create-dp-koa 1.1.2 → 1.1.3

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 (84) hide show
  1. package/package.json +1 -1
  2. package/template/scripts/sync-template.mjs +20 -0
  3. package/template/src/app.ts +1 -2
  4. package/template/src/{framework/plugins → plugins}/registry.ts +2 -2
  5. package/template/src/plugins/weboffice/http/routes.ts +1 -1
  6. package/template/src/plugins/weboffice/index.ts +3 -3
  7. package/template/src/plugins/weboffice/services/webofficeCallback.service.ts +3 -4
  8. package/template/src/utils/testDataInitializer.ts +1 -1
  9. package/template/tsconfig.json +6 -0
  10. package/template/src/annotations/decorators/ConfigManagement.ts +0 -9
  11. package/template/src/annotations/decorators/DistributedTracing.ts +0 -9
  12. package/template/src/annotations/decorators/EnterprisePerformance.ts +0 -9
  13. package/template/src/annotations/decorators/PerformanceMonitor.ts +0 -32
  14. package/template/src/annotations/decorators/SecurityAudit.ts +0 -9
  15. package/template/src/annotations/index.ts +0 -50
  16. package/template/src/annotations/processors/ConfigManagementProcessor.ts +0 -369
  17. package/template/src/annotations/processors/DistributedTracingProcessor.ts +0 -288
  18. package/template/src/annotations/processors/EnterprisePerformanceProcessor.ts +0 -189
  19. package/template/src/annotations/processors/PerformanceMonitorProcessor.ts +0 -101
  20. package/template/src/annotations/processors/SecurityAuditProcessor.ts +0 -345
  21. package/template/src/annotations/processors/SwaggerProcessor.ts +0 -612
  22. package/template/src/annotations/processors/index.ts +0 -10
  23. package/template/src/examples/InterceptorExampleRunner.ts +0 -284
  24. package/template/src/examples/ServiceInterceptorExample.ts +0 -214
  25. package/template/src/examples/cacheExamples.ts +0 -155
  26. package/template/src/framework/decorator/controller.ts +0 -311
  27. package/template/src/framework/decorator/processor/AnnotationDecorators.ts +0 -100
  28. package/template/src/framework/decorator/processor/AnnotationProcessor.ts +0 -160
  29. package/template/src/framework/decorator/processor/AnnotationProcessorConfig.ts +0 -45
  30. package/template/src/framework/decorator/processor/AnnotationRegistry.ts +0 -117
  31. package/template/src/framework/decorator/processor/AnnotationSystemInitializer.ts +0 -95
  32. package/template/src/framework/decorator/processor/ProcessorManager.ts +0 -76
  33. package/template/src/framework/decorator/processor/processors/CustomProcessors.ts +0 -126
  34. package/template/src/framework/decorator/processor/processors/DefaultProcessors.ts +0 -207
  35. package/template/src/framework/decorator/refactored/DecoratorFactory.ts +0 -99
  36. package/template/src/framework/decorator/refactored/DecoratorMetadataManager.ts +0 -125
  37. package/template/src/framework/decorator/refactored/DecoratorValidator.ts +0 -128
  38. package/template/src/framework/decorator/refactored/TypeSafeDecorators.ts +0 -139
  39. package/template/src/framework/decorator/refactored/index.ts +0 -98
  40. package/template/src/framework/decorator/swagger.ts +0 -150
  41. package/template/src/framework/interceptors/AdvancedServiceCallInterceptor.ts +0 -375
  42. package/template/src/framework/interceptors/ServiceCallInterceptor.ts +0 -348
  43. package/template/src/framework/interceptors/index.ts +0 -19
  44. package/template/src/framework/plugins/types.ts +0 -15
  45. package/template/src/framework/types/ServiceResult.ts +0 -151
  46. package/template/src/framework/types/index.ts +0 -16
  47. package/template/src/framework/utils/CacheManager.ts +0 -430
  48. package/template/src/framework/utils/CacheService.ts +0 -248
  49. package/template/src/framework/utils/DtoValidator.ts +0 -164
  50. package/template/src/framework/utils/MigrationHelper.ts +0 -179
  51. package/template/src/framework/utils/MigrationManager.ts +0 -256
  52. package/template/src/framework/utils/NewRouter.ts +0 -207
  53. package/template/src/framework/utils/TransactionManager.ts +0 -172
  54. package/template/src/framework/utils/bootstrap.ts +0 -445
  55. package/template/src/framework/utils/cache.ts +0 -269
  56. package/template/src/framework/utils/databaseConfig.ts +0 -148
  57. package/template/src/framework/utils/db.ts +0 -39
  58. package/template/src/framework/utils/dbMonitor.ts +0 -106
  59. package/template/src/framework/utils/function.ts +0 -61
  60. package/template/src/framework/utils/gracefulShutdown.ts +0 -131
  61. package/template/src/framework/utils/logger.ts +0 -388
  62. package/template/src/framework/utils/metrics.ts +0 -182
  63. package/template/src/framework/utils/router.ts +0 -417
  64. package/template/src/framework/utils/swagger.ts +0 -184
  65. package/template/src/framework/utils/testDb.ts +0 -19
  66. package/template/src/framework/utils/token.ts +0 -23
  67. package/template/src/framework/utils/transform.ts +0 -17
  68. package/template/src/libs/aokEmailSender.ts +0 -42
  69. package/template/src/libs/captcha.ts +0 -37
  70. package/template/src/libs/cos.ts +0 -45
  71. package/template/src/libs/mCache.ts +0 -7
  72. package/template/src/libs/serviceValidate.ts +0 -3
  73. package/template/src/libs/tecentSms.ts +0 -51
  74. package/template/src/middlewares/a.middleware.ts +0 -6
  75. package/template/src/middlewares/error.middleware.ts +0 -14
  76. package/template/src/middlewares/logging.middleware.ts +0 -187
  77. package/template/src/middlewares/static.middleware.ts +0 -79
  78. package/template/src/middlewares/swagger.middleware.ts +0 -70
  79. package/template/src/middlewares/token.middleware.ts +0 -32
  80. package/template/src/migrations/1700000000000-InitialDatabaseStructure.ts +0 -172
  81. package/template/src/migrations/index.ts +0 -6
  82. package/template/src/repository/base/BaseRepository.ts +0 -124
  83. package/template/src/repository/interfaces/IBaseRepository.ts +0 -67
  84. package/template/src/service/base.service.ts +0 -116
@@ -1,117 +0,0 @@
1
- import { AnnotationProcessor } from '@src/framework/decorator/processor/AnnotationProcessor';
2
- import { logger } from '@src/framework/utils/logger';
3
-
4
- /**
5
- * 注解注册中心
6
- * 统一管理所有注解的定义、注册和使用
7
- */
8
- export class AnnotationRegistry {
9
- private static instance: AnnotationRegistry;
10
- private processors: Map<string, AnnotationProcessor> = new Map();
11
- private processorList: AnnotationProcessor[] = [];
12
-
13
- private constructor() {}
14
-
15
- static getInstance(): AnnotationRegistry {
16
- if (!AnnotationRegistry.instance) {
17
- AnnotationRegistry.instance = new AnnotationRegistry();
18
- }
19
- return AnnotationRegistry.instance;
20
- }
21
-
22
- /**
23
- * 注册注解处理器
24
- * @param processor 注解处理器实例
25
- */
26
- registerProcessor(processor: AnnotationProcessor): void {
27
- if (this.processors.has(processor.name)) {
28
- logger.warn(`注解处理器 ${processor.name} 已存在,将被覆盖`);
29
- }
30
-
31
- this.processors.set(processor.name, processor);
32
- this.processorList.push(processor);
33
-
34
- // 按优先级排序
35
- this.processorList.sort((a, b) => a.priority - b.priority);
36
-
37
- logger.info(`注解处理器 ${processor.name} 已注册,优先级: ${processor.priority}`);
38
- }
39
-
40
- /**
41
- * 获取注解处理器
42
- * @param name 处理器名称
43
- */
44
- getProcessor(name: string): AnnotationProcessor | undefined {
45
- return this.processors.get(name);
46
- }
47
-
48
- /**
49
- * 获取所有处理器(按优先级排序)
50
- */
51
- getAllProcessors(): AnnotationProcessor[] {
52
- return [...this.processorList];
53
- }
54
-
55
- /**
56
- * 移除注解处理器
57
- * @param name 处理器名称
58
- */
59
- unregisterProcessor(name: string): boolean {
60
- const processor = this.processors.get(name);
61
- if (processor) {
62
- this.processors.delete(name);
63
- const index = this.processorList.indexOf(processor);
64
- if (index > -1) {
65
- this.processorList.splice(index, 1);
66
- }
67
- logger.info(`注解处理器 ${name} 已移除`);
68
- return true;
69
- }
70
- return false;
71
- }
72
-
73
- /**
74
- * 清空所有处理器
75
- */
76
- clear(): void {
77
- this.processors.clear();
78
- this.processorList = [];
79
- logger.info('所有注解处理器已清空');
80
- }
81
-
82
- /**
83
- * 清理所有处理器的资源
84
- * 在应用关闭时调用
85
- */
86
- cleanup(): void {
87
- this.processorList.forEach(processor => {
88
- // 检查处理器是否有 cleanup 方法
89
- if (typeof (processor as any).cleanup === 'function') {
90
- try {
91
- (processor as any).cleanup();
92
- } catch (error) {
93
- logger.error(`清理处理器 ${processor.name} 时发生错误:`, error as Error);
94
- }
95
- }
96
- });
97
- logger.info('所有注解处理器资源已清理');
98
- }
99
-
100
- /**
101
- * 获取注册的处理器列表
102
- */
103
- getRegisteredProcessors(): string[] {
104
- return Array.from(this.processors.keys());
105
- }
106
-
107
- /**
108
- * 检查处理器是否已注册
109
- * @param name 处理器名称
110
- */
111
- hasProcessor(name: string): boolean {
112
- return this.processors.has(name);
113
- }
114
- }
115
-
116
- // 导出单例实例
117
- export const annotationRegistry = AnnotationRegistry.getInstance();
@@ -1,95 +0,0 @@
1
- import { annotationRegistry } from '@src/framework/decorator/processor/AnnotationRegistry';
2
- import { logger } from '@src/framework/utils/logger';
3
- import { getAllAnnotationProcessors } from '@src/framework/decorator/processor/AnnotationProcessorConfig';
4
-
5
- /**
6
- * 注解系统初始化器
7
- * 负责在应用启动时初始化所有注解处理器
8
- */
9
- export class AnnotationSystemInitializer {
10
- private static initialized = false;
11
-
12
- /**
13
- * 初始化注解系统
14
- * 注册所有内置和自定义注解处理器
15
- */
16
- static initialize(): void {
17
- if (this.initialized) {
18
- logger.warn('注解系统已经初始化,跳过重复初始化');
19
- return;
20
- }
21
-
22
- try {
23
- // 注册内置注解处理器
24
- this.registerBuiltinProcessors();
25
-
26
- // 注册自定义注解处理器
27
- this.registerCustomProcessors();
28
-
29
- this.initialized = true;
30
- logger.info('注解系统初始化完成');
31
- logger.info(`已注册的注解处理器: ${annotationRegistry.getRegisteredProcessors().join(', ')}`);
32
-
33
- } catch (error) {
34
- logger.error('注解系统初始化失败:', error as Error);
35
- throw error;
36
- }
37
- }
38
-
39
- /**
40
- * 注册内置注解处理器
41
- */
42
- private static registerBuiltinProcessors(): void {
43
- // 动态导入内置处理器,避免循环依赖
44
- import('./processors/DefaultProcessors').then(({
45
- ParameterValidationProcessor,
46
- ResponseValidationProcessor,
47
- CacheProcessor,
48
- ResponseCodeProcessor,
49
- ResponseHeaderProcessor
50
- }) => {
51
- annotationRegistry.registerProcessor(new ParameterValidationProcessor());
52
- annotationRegistry.registerProcessor(new ResponseValidationProcessor());
53
- annotationRegistry.registerProcessor(new CacheProcessor());
54
- annotationRegistry.registerProcessor(new ResponseCodeProcessor());
55
- annotationRegistry.registerProcessor(new ResponseHeaderProcessor());
56
-
57
- logger.info('内置注解处理器注册完成');
58
- }).catch(error => {
59
- logger.error('内置注解处理器注册失败:', error);
60
- });
61
- }
62
-
63
- /**
64
- * 注册自定义注解处理器
65
- */
66
- private static registerCustomProcessors(): void {
67
- try {
68
- // 使用配置文件注册所有注解处理器
69
- const allProcessors = getAllAnnotationProcessors();
70
- allProcessors.forEach(processor => {
71
- annotationRegistry.registerProcessor(processor);
72
- });
73
-
74
- logger.info(`自定义注解处理器注册完成,共注册 ${allProcessors.length} 个处理器`);
75
- } catch (error) {
76
- logger.error('自定义注解处理器注册失败:', error as Error);
77
- }
78
- }
79
-
80
- /**
81
- * 检查是否已初始化
82
- */
83
- static isInitialized(): boolean {
84
- return this.initialized;
85
- }
86
-
87
- /**
88
- * 重置初始化状态(主要用于测试)
89
- */
90
- static reset(): void {
91
- this.initialized = false;
92
- annotationRegistry.clear();
93
- logger.info('注解系统已重置');
94
- }
95
- }
@@ -1,76 +0,0 @@
1
- import { annotationRegistry } from '@src/framework/decorator/processor/AnnotationRegistry';
2
- import {
3
- ParameterValidationProcessor,
4
- ResponseValidationProcessor,
5
- CacheProcessor,
6
- ResponseCodeProcessor,
7
- ResponseHeaderProcessor
8
- } from './processors/DefaultProcessors';
9
-
10
- /**
11
- * 注解处理器管理器
12
- * @deprecated 请使用 AnnotationRegistry 和 AnnotationSystemInitializer
13
- */
14
- export class ProcessorManager {
15
- private static initialized = false;
16
-
17
- /**
18
- * 初始化默认处理器
19
- */
20
- static initialize(): void {
21
- if (this.initialized) {
22
- return;
23
- }
24
-
25
- // 注册默认处理器
26
- this.registerDefaultProcessors();
27
- this.initialized = true;
28
- }
29
-
30
- /**
31
- * 注册默认处理器
32
- */
33
- private static registerDefaultProcessors(): void {
34
- annotationRegistry.registerProcessor(new ParameterValidationProcessor());
35
- annotationRegistry.registerProcessor(new ResponseValidationProcessor());
36
- annotationRegistry.registerProcessor(new CacheProcessor());
37
- annotationRegistry.registerProcessor(new ResponseCodeProcessor());
38
- annotationRegistry.registerProcessor(new ResponseHeaderProcessor());
39
- }
40
-
41
- /**
42
- * 注册自定义处理器
43
- */
44
- static registerProcessor(processor: any): void {
45
- annotationRegistry.registerProcessor(processor);
46
- }
47
-
48
- /**
49
- * 获取所有处理器
50
- */
51
- static getAllProcessors() {
52
- return annotationRegistry.getAllProcessors();
53
- }
54
-
55
- /**
56
- * 获取处理器
57
- */
58
- static getProcessor(name: string) {
59
- return annotationRegistry.getProcessor(name);
60
- }
61
-
62
- /**
63
- * 移除处理器
64
- */
65
- static removeProcessor(name: string): boolean {
66
- return annotationRegistry.unregisterProcessor(name);
67
- }
68
-
69
- /**
70
- * 清空所有处理器
71
- */
72
- static clear(): void {
73
- annotationRegistry.clear();
74
- this.initialized = false;
75
- }
76
- }
@@ -1,126 +0,0 @@
1
- import { Context } from 'koa';
2
- import { AnnotationProcessor } from '@src/framework/decorator/processor/AnnotationProcessor';
3
- import { logger } from '@src/framework/utils/logger';
4
-
5
- /**
6
- * 日志注解处理器示例
7
- * 演示如何创建自定义注解处理器
8
- */
9
- export class LoggingProcessor implements AnnotationProcessor {
10
- readonly name = 'Logging';
11
- readonly priority = 10; // 高优先级,在其他处理器之前执行
12
-
13
- async process(
14
- ctx: Context,
15
- controller: any,
16
- methodName: string,
17
- annotationData: any,
18
- callParams: any[]
19
- ): Promise<boolean> {
20
- const startTime = Date.now();
21
-
22
- // 只在调试模式下输出详细日志
23
- logger.debug(`[${this.name}] 开始处理请求: ${controller.constructor.name}.${methodName}`);
24
- logger.debug(`[${this.name}] 请求参数:`, callParams);
25
- logger.debug(`[${this.name}] 注解数据:`, annotationData);
26
-
27
- // 将开始时间存储到上下文中,供后续使用
28
- ctx.state.loggingStartTime = startTime;
29
-
30
- return true;
31
- }
32
-
33
- /**
34
- * 记录响应日志
35
- */
36
- async logResponse(ctx: Context, controller: any, methodName: string, response: any): Promise<void> {
37
- const startTime = ctx.state.loggingStartTime;
38
- const duration = startTime ? Date.now() - startTime : 0;
39
-
40
- // 只在调试模式下输出详细日志
41
- logger.debug(`[Logging] 完成处理请求: ${controller.constructor.name}.${methodName}`);
42
- logger.debug(`[Logging] 响应数据:`, response);
43
- logger.debug(`[Logging] 处理耗时: ${duration}ms`);
44
- }
45
- }
46
-
47
- /**
48
- * 权限检查注解处理器示例
49
- */
50
- export class PermissionProcessor implements AnnotationProcessor {
51
- readonly name = 'Permission';
52
- readonly priority = 5; // 最高优先级
53
-
54
- async process(
55
- ctx: Context,
56
- controller: any,
57
- methodName: string,
58
- annotationData: any,
59
- callParams: any[]
60
- ): Promise<boolean> {
61
- // 检查用户权限
62
- const user = ctx.state.user;
63
- if (!user) {
64
- ctx.status = 401;
65
- ctx.body = { error: '未授权访问' };
66
- return false;
67
- }
68
-
69
- // 检查特定权限
70
- if (annotationData && annotationData.requiredPermission) {
71
- if (!user.permissions || !user.permissions.includes(annotationData.requiredPermission)) {
72
- ctx.status = 403;
73
- ctx.body = { error: '权限不足' };
74
- return false;
75
- }
76
- }
77
-
78
- return true;
79
- }
80
- }
81
-
82
- /**
83
- * 限流注解处理器示例
84
- */
85
- export class RateLimitProcessor implements AnnotationProcessor {
86
- readonly name = 'RateLimit';
87
- readonly priority = 15;
88
-
89
- private static requestCounts: Map<string, { count: number; resetTime: number }> = new Map();
90
-
91
- async process(
92
- ctx: Context,
93
- controller: any,
94
- methodName: string,
95
- annotationData: any,
96
- callParams: any[]
97
- ): Promise<boolean> {
98
- if (!annotationData) {
99
- return true;
100
- }
101
-
102
- const { maxRequests = 100, windowMs = 60000 } = annotationData;
103
- const clientId = ctx.ip || 'unknown';
104
- const key = `${clientId}:${controller.constructor.name}:${methodName}`;
105
-
106
- const now = Date.now();
107
- const current = RateLimitProcessor.requestCounts.get(key);
108
-
109
- if (!current || now > current.resetTime) {
110
- // 重置计数器
111
- RateLimitProcessor.requestCounts.set(key, {
112
- count: 1,
113
- resetTime: now + windowMs
114
- });
115
- } else {
116
- current.count++;
117
- if (current.count > maxRequests) {
118
- ctx.status = 429;
119
- ctx.body = { error: '请求过于频繁,请稍后再试' };
120
- return false;
121
- }
122
- }
123
-
124
- return true;
125
- }
126
- }
@@ -1,207 +0,0 @@
1
- import { Context } from 'koa';
2
- import { AnnotationProcessor } from '@src/framework/decorator/processor/AnnotationProcessor';
3
- import { validate } from 'class-validator';
4
- import { isPromise } from '@src/framework/utils/function';
5
-
6
- /**
7
- * 参数验证处理器
8
- */
9
- export class ParameterValidationProcessor implements AnnotationProcessor {
10
- readonly name = 'ParameterValidation';
11
- readonly priority = 100;
12
-
13
- async process(
14
- ctx: Context,
15
- controller: any,
16
- methodName: string,
17
- annotationData: any,
18
- callParams: any[]
19
- ): Promise<boolean> {
20
- if (!controller.$_MethdosParamInfo) {
21
- return true;
22
- }
23
-
24
- const paramsInfo = controller.$_MethdosParamInfo.get(methodName);
25
- if (!paramsInfo || paramsInfo.length === 0) {
26
- return true;
27
- }
28
-
29
- for (let i = 0; i < paramsInfo.length; i++) {
30
- const paramInfo = paramsInfo[i];
31
- const data = callParams[i];
32
-
33
- if (paramInfo.validate && typeof paramInfo.validate === 'function' && data) {
34
- const waitToValidateObject = new paramInfo.validate();
35
-
36
- // 处理数据转换
37
- for (let key in data) {
38
- if (waitToValidateObject.$_Transform && waitToValidateObject.$_Transform.get(key)) {
39
- const func = waitToValidateObject.$_Transform.get(key);
40
- const result = func(data[key]);
41
- if (isPromise(result)) {
42
- waitToValidateObject[key] = await result;
43
- } else {
44
- waitToValidateObject[key] = result;
45
- }
46
- } else {
47
- waitToValidateObject[key] = data[key];
48
- }
49
- }
50
-
51
- const validateErrors = await validate(waitToValidateObject);
52
- if (validateErrors.length > 0) {
53
- ctx.status = 400;
54
- ctx.body = validateErrors;
55
- return false;
56
- }
57
- }
58
- }
59
-
60
- return true;
61
- }
62
- }
63
-
64
- /**
65
- * 响应验证处理器
66
- */
67
- export class ResponseValidationProcessor implements AnnotationProcessor {
68
- readonly name = 'ResponseValidation';
69
- readonly priority = 200;
70
-
71
- async process(
72
- ctx: Context,
73
- controller: any,
74
- methodName: string,
75
- annotationData: any,
76
- callParams: any[]
77
- ): Promise<boolean> {
78
- // 这个方法会在响应处理时被调用
79
- // 这里先返回true,具体的响应验证逻辑会在响应处理阶段实现
80
- return true;
81
- }
82
-
83
- /**
84
- * 验证响应数据
85
- */
86
- async validateResponse(
87
- controller: any,
88
- methodName: string,
89
- response: any
90
- ): Promise<any[]> {
91
- if (controller.$_ResponseValidateIf && controller.$_ResponseValidateIf.get(methodName)) {
92
- const { fn, clas } = controller.$_ResponseValidateIf.get(methodName);
93
- let callResult = fn(response);
94
- if (isPromise(callResult)) {
95
- callResult = await callResult;
96
- }
97
- if (callResult && (callResult instanceof Object)) {
98
- const dto = new clas();
99
- Object.assign(dto, callResult);
100
- return await validate(dto, {
101
- skipMissingProperties: false,
102
- forbidNonWhitelisted: true,
103
- whitelist: true,
104
- });
105
- }
106
- } else if (controller.$_ResponseValidator && controller.$_ResponseValidator.get(methodName)) {
107
- const { clas, objectKey } = controller.$_ResponseValidator.get(methodName);
108
- if (response instanceof Object) {
109
- const dto = new clas();
110
- let dataObject = response;
111
- if (objectKey && response[objectKey] && (response[objectKey] instanceof Object)) {
112
- dataObject = response[objectKey];
113
- }
114
- Object.assign(dto, dataObject);
115
- return await validate(dto, {
116
- skipMissingProperties: false,
117
- forbidNonWhitelisted: true,
118
- whitelist: true,
119
- });
120
- }
121
- }
122
- return [];
123
- }
124
- }
125
-
126
- /**
127
- * 缓存处理器
128
- */
129
- export class CacheProcessor implements AnnotationProcessor {
130
- readonly name = 'Cache';
131
- readonly priority = 50;
132
-
133
- async process(
134
- ctx: Context,
135
- controller: any,
136
- methodName: string,
137
- annotationData: any,
138
- callParams: any[]
139
- ): Promise<boolean> {
140
- if (!controller.$_ControllerCache || !controller.$_ControllerCache.get(methodName)) {
141
- return true;
142
- }
143
-
144
- const { cacheyFn, options } = controller.$_ControllerCache.get(methodName);
145
- if (!options || (options.enable !== undefined && !options.enable)) {
146
- return true;
147
- }
148
-
149
- const cacheKey = cacheyFn(...callParams);
150
- if (cacheKey) {
151
- // 这里需要访问缓存存储,暂时跳过缓存逻辑
152
- // 实际的缓存逻辑会在响应处理时实现
153
- }
154
-
155
- return true;
156
- }
157
- }
158
-
159
- /**
160
- * 响应码处理器
161
- */
162
- export class ResponseCodeProcessor implements AnnotationProcessor {
163
- readonly name = 'ResponseCode';
164
- readonly priority = 300;
165
-
166
- async process(
167
- ctx: Context,
168
- controller: any,
169
- methodName: string,
170
- annotationData: any,
171
- callParams: any[]
172
- ): Promise<boolean> {
173
- if (controller.$_ResponseCode) {
174
- const code = controller.$_ResponseCode.get(methodName) ?? 200;
175
- ctx.status = code;
176
- }
177
- return true;
178
- }
179
- }
180
-
181
- /**
182
- * 响应头处理器
183
- */
184
- export class ResponseHeaderProcessor implements AnnotationProcessor {
185
- readonly name = 'ResponseHeader';
186
- readonly priority = 400;
187
-
188
- async process(
189
- ctx: Context,
190
- controller: any,
191
- methodName: string,
192
- annotationData: any,
193
- callParams: any[]
194
- ): Promise<boolean> {
195
- if (controller.$_ResponseHeader) {
196
- const responseHeaders = controller.$_ResponseHeader.get(methodName);
197
- if (responseHeaders) {
198
- responseHeaders.forEach((value: any, key: string) => {
199
- if (value) {
200
- ctx.set(key, value);
201
- }
202
- });
203
- }
204
- }
205
- return true;
206
- }
207
- }