@nest-omni/core 4.1.3-1 → 4.1.3-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 (237) hide show
  1. package/audit/audit.module.d.ts +10 -0
  2. package/audit/audit.module.js +15 -0
  3. package/audit/controllers/audit.controller.d.ts +24 -0
  4. package/audit/controllers/audit.controller.js +24 -0
  5. package/audit/decorators/audit-controller.decorator.d.ts +8 -0
  6. package/audit/decorators/audit-controller.decorator.js +9 -0
  7. package/audit/decorators/audit-operation.decorator.d.ts +45 -0
  8. package/audit/decorators/audit-operation.decorator.js +49 -0
  9. package/audit/decorators/entity-audit.decorator.d.ts +8 -0
  10. package/audit/decorators/entity-audit.decorator.js +9 -0
  11. package/audit/dto/audit-log-query.dto.d.ts +3 -0
  12. package/audit/dto/audit-log-query.dto.js +3 -0
  13. package/audit/dto/begin-transaction.dto.d.ts +3 -0
  14. package/audit/dto/begin-transaction.dto.js +3 -0
  15. package/audit/dto/compare-entities.dto.d.ts +3 -0
  16. package/audit/dto/compare-entities.dto.js +3 -0
  17. package/audit/dto/pre-check-restore.dto.d.ts +3 -0
  18. package/audit/dto/pre-check-restore.dto.js +3 -0
  19. package/audit/dto/restore-entity.dto.d.ts +3 -0
  20. package/audit/dto/restore-entity.dto.js +3 -0
  21. package/audit/entities/entity-audit-log.entity.d.ts +3 -0
  22. package/audit/entities/entity-audit-log.entity.js +3 -0
  23. package/audit/entities/entity-transaction.entity.d.ts +3 -0
  24. package/audit/entities/entity-transaction.entity.js +3 -0
  25. package/audit/entities/manual-operation-log.entity.d.ts +4 -0
  26. package/audit/entities/manual-operation-log.entity.js +4 -0
  27. package/audit/entities/operation-template.entity.d.ts +4 -0
  28. package/audit/entities/operation-template.entity.js +4 -0
  29. package/audit/enums/audit.enums.d.ts +17 -2
  30. package/audit/enums/audit.enums.js +15 -0
  31. package/audit/index.js +10 -0
  32. package/audit/interceptors/audit.interceptor.d.ts +15 -0
  33. package/audit/interceptors/audit.interceptor.js +23 -1
  34. package/audit/interfaces/audit.interfaces.d.ts +42 -0
  35. package/audit/services/audit-context.service.d.ts +15 -0
  36. package/audit/services/audit-context.service.js +15 -0
  37. package/audit/services/audit-strategy.service.d.ts +6 -0
  38. package/audit/services/audit-strategy.service.js +13 -0
  39. package/audit/services/entity-audit.service.d.ts +57 -0
  40. package/audit/services/entity-audit.service.js +91 -0
  41. package/audit/services/manual-audit-log.service.d.ts +124 -0
  42. package/audit/services/manual-audit-log.service.js +138 -0
  43. package/audit/services/multi-database.service.d.ts +12 -0
  44. package/audit/services/multi-database.service.js +12 -0
  45. package/audit/services/operation-description.service.d.ts +59 -0
  46. package/audit/services/operation-description.service.js +76 -2
  47. package/audit/services/transaction-audit.service.d.ts +30 -0
  48. package/audit/services/transaction-audit.service.js +47 -0
  49. package/audit/subscribers/entity-audit.subscriber.d.ts +15 -0
  50. package/audit/subscribers/entity-audit.subscriber.js +29 -1
  51. package/cache/cache-metrics.service.d.ts +67 -0
  52. package/cache/cache-metrics.service.js +68 -4
  53. package/cache/cache-serialization.service.d.ts +31 -0
  54. package/cache/cache-serialization.service.js +25 -0
  55. package/cache/cache.constants.d.ts +9 -0
  56. package/cache/cache.constants.js +9 -0
  57. package/cache/cache.health.d.ts +26 -0
  58. package/cache/cache.health.js +30 -0
  59. package/cache/cache.module.d.ts +86 -0
  60. package/cache/cache.module.js +71 -0
  61. package/cache/cache.service.d.ts +140 -0
  62. package/cache/cache.service.js +157 -0
  63. package/cache/cache.warmup.service.d.ts +39 -0
  64. package/cache/cache.warmup.service.js +32 -0
  65. package/cache/decorators/cache-evict.decorator.d.ts +47 -0
  66. package/cache/decorators/cache-evict.decorator.js +56 -0
  67. package/cache/decorators/cache-put.decorator.d.ts +34 -0
  68. package/cache/decorators/cache-put.decorator.js +39 -0
  69. package/cache/decorators/cacheable.decorator.d.ts +40 -0
  70. package/cache/decorators/cacheable.decorator.js +55 -0
  71. package/cache/dependencies/callback.dependency.d.ts +33 -0
  72. package/cache/dependencies/callback.dependency.js +39 -1
  73. package/cache/dependencies/chain.dependency.d.ts +28 -0
  74. package/cache/dependencies/chain.dependency.js +34 -0
  75. package/cache/dependencies/db.dependency.d.ts +45 -0
  76. package/cache/dependencies/db.dependency.js +48 -1
  77. package/cache/dependencies/file.dependency.d.ts +32 -0
  78. package/cache/dependencies/file.dependency.js +34 -0
  79. package/cache/dependencies/tag.dependency.d.ts +36 -0
  80. package/cache/dependencies/tag.dependency.js +36 -0
  81. package/cache/dependencies/time.dependency.d.ts +43 -0
  82. package/cache/dependencies/time.dependency.js +43 -0
  83. package/cache/examples/basic-usage.d.ts +15 -0
  84. package/cache/examples/basic-usage.js +62 -8
  85. package/cache/index.js +9 -0
  86. package/cache/interfaces/cache-dependency.interface.d.ts +53 -0
  87. package/cache/interfaces/cache-options.interface.d.ts +81 -0
  88. package/cache/interfaces/cache-options.interface.js +6 -0
  89. package/cache/interfaces/cache-provider.interface.d.ts +78 -0
  90. package/cache/providers/base-cache.provider.d.ts +14 -0
  91. package/cache/providers/base-cache.provider.js +16 -0
  92. package/cache/providers/cls-cache.provider.d.ts +20 -0
  93. package/cache/providers/cls-cache.provider.js +28 -0
  94. package/cache/providers/memory-cache.provider.d.ts +23 -0
  95. package/cache/providers/memory-cache.provider.js +26 -0
  96. package/cache/providers/redis-cache.provider.d.ts +26 -0
  97. package/cache/providers/redis-cache.provider.js +29 -0
  98. package/cache/utils/dependency-manager.util.d.ts +52 -0
  99. package/cache/utils/dependency-manager.util.js +59 -0
  100. package/cache/utils/key-generator.util.d.ts +42 -0
  101. package/cache/utils/key-generator.util.js +53 -1
  102. package/common/abstract.entity.d.ts +14 -0
  103. package/common/abstract.entity.js +14 -0
  104. package/common/boilerplate.polyfill.d.ts +142 -4
  105. package/common/boilerplate.polyfill.js +24 -100
  106. package/common/dto/dto-container.d.ts +16 -0
  107. package/common/dto/dto-container.js +20 -0
  108. package/common/dto/dto-decorators.d.ts +18 -0
  109. package/common/dto/dto-decorators.js +14 -0
  110. package/common/dto/dto-extensions.d.ts +11 -0
  111. package/common/dto/dto-extensions.js +9 -0
  112. package/common/dto/dto-service-accessor.d.ts +17 -0
  113. package/common/dto/dto-service-accessor.js +18 -0
  114. package/common/dto/dto-transformer.d.ts +12 -0
  115. package/common/dto/dto-transformer.js +9 -0
  116. package/common/dto/index.js +2 -0
  117. package/common/examples/paginate-and-map.example.d.ts +6 -0
  118. package/common/examples/paginate-and-map.example.js +26 -0
  119. package/common/utils.d.ts +15 -0
  120. package/common/utils.js +15 -0
  121. package/constants/language-code.js +1 -0
  122. package/decorators/field.decorators.js +8 -1
  123. package/decorators/property.decorators.js +1 -0
  124. package/decorators/public-route.decorator.js +1 -0
  125. package/decorators/transform.decorators.d.ts +27 -0
  126. package/decorators/transform.decorators.js +29 -0
  127. package/decorators/translate.decorator.js +1 -0
  128. package/decorators/user.decorator.js +1 -0
  129. package/decorators/validator.decorators.d.ts +8 -18
  130. package/decorators/validator.decorators.js +22 -190
  131. package/filters/constraint-errors.js +1 -0
  132. package/helpers/common.helper.d.ts +13 -0
  133. package/helpers/common.helper.js +13 -0
  134. package/http-client/config/http-client.config.d.ts +15 -0
  135. package/http-client/config/http-client.config.js +25 -9
  136. package/http-client/decorators/http-client.decorators.d.ts +63 -0
  137. package/http-client/decorators/http-client.decorators.js +71 -3
  138. package/http-client/entities/http-log.entity.d.ts +229 -0
  139. package/http-client/entities/http-log.entity.js +6 -1
  140. package/http-client/errors/http-client.errors.d.ts +57 -0
  141. package/http-client/errors/http-client.errors.js +58 -0
  142. package/http-client/examples/advanced-usage.example.d.ts +41 -0
  143. package/http-client/examples/advanced-usage.example.js +68 -24
  144. package/http-client/examples/auth-with-waiting-lock.example.d.ts +31 -0
  145. package/http-client/examples/auth-with-waiting-lock.example.js +52 -5
  146. package/http-client/examples/basic-usage.example.d.ts +60 -0
  147. package/http-client/examples/basic-usage.example.js +60 -0
  148. package/http-client/examples/multi-api-configuration.example.d.ts +60 -0
  149. package/http-client/examples/multi-api-configuration.example.js +76 -5
  150. package/http-client/http-client.module.d.ts +13 -0
  151. package/http-client/http-client.module.js +19 -0
  152. package/http-client/index.js +8 -0
  153. package/http-client/interfaces/api-client-config.interface.d.ts +125 -0
  154. package/http-client/interfaces/api-client-config.interface.js +3 -0
  155. package/http-client/interfaces/http-client-config.interface.d.ts +60 -0
  156. package/http-client/services/api-client-registry.service.d.ts +57 -0
  157. package/http-client/services/api-client-registry.service.js +84 -1
  158. package/http-client/services/cache.service.d.ts +52 -0
  159. package/http-client/services/cache.service.js +72 -3
  160. package/http-client/services/circuit-breaker.service.d.ts +46 -0
  161. package/http-client/services/circuit-breaker.service.js +52 -0
  162. package/http-client/services/http-client.service.d.ts +67 -0
  163. package/http-client/services/http-client.service.js +105 -4
  164. package/http-client/services/http-log-query.service.d.ts +83 -0
  165. package/http-client/services/http-log-query.service.js +122 -1
  166. package/http-client/services/http-replay.service.d.ts +101 -0
  167. package/http-client/services/http-replay.service.js +86 -0
  168. package/http-client/services/log-cleanup.service.d.ts +63 -0
  169. package/http-client/services/log-cleanup.service.js +54 -2
  170. package/http-client/services/logging.service.d.ts +40 -0
  171. package/http-client/services/logging.service.js +53 -0
  172. package/http-client/utils/call-stack-extractor.util.d.ts +37 -0
  173. package/http-client/utils/call-stack-extractor.util.js +48 -0
  174. package/http-client/utils/context-extractor.util.d.ts +49 -0
  175. package/http-client/utils/context-extractor.util.js +52 -0
  176. package/http-client/utils/curl-generator.util.d.ts +21 -0
  177. package/http-client/utils/curl-generator.util.js +44 -3
  178. package/http-client/utils/request-id.util.d.ts +18 -0
  179. package/http-client/utils/request-id.util.js +20 -0
  180. package/http-client/utils/retry-recorder.util.d.ts +42 -0
  181. package/http-client/utils/retry-recorder.util.js +44 -0
  182. package/i18n/en_US/validation.json +2 -1
  183. package/i18n/zh_CN/validation.json +2 -1
  184. package/index.js +8 -0
  185. package/interceptors/translation-interceptor.service.js +5 -0
  186. package/package.json +1 -1
  187. package/providers/context.provider.js +2 -0
  188. package/providers/generator.provider.d.ts +4 -0
  189. package/providers/generator.provider.js +4 -0
  190. package/redis-lock/examples/lock-strategy.examples.d.ts +89 -0
  191. package/redis-lock/examples/lock-strategy.examples.js +130 -15
  192. package/redis-lock/index.js +3 -0
  193. package/redis-lock/redis-lock.decorator.d.ts +101 -0
  194. package/redis-lock/redis-lock.decorator.js +120 -0
  195. package/redis-lock/redis-lock.module.d.ts +60 -0
  196. package/redis-lock/redis-lock.module.js +46 -0
  197. package/redis-lock/redis-lock.service.d.ts +251 -0
  198. package/redis-lock/redis-lock.service.js +219 -3
  199. package/setup/bootstrap.setup.js +20 -0
  200. package/setup/mode.setup.d.ts +44 -0
  201. package/setup/mode.setup.js +44 -0
  202. package/setup/schedule.decorator.d.ts +226 -0
  203. package/setup/schedule.decorator.js +214 -1
  204. package/setup/worker.decorator.d.ts +86 -0
  205. package/setup/worker.decorator.js +88 -0
  206. package/shared/serviceRegistryModule.js +9 -1
  207. package/shared/services/api-config.service.d.ts +3 -0
  208. package/shared/services/api-config.service.js +20 -9
  209. package/validator-json/decorators.d.ts +17 -0
  210. package/validator-json/decorators.js +17 -2
  211. package/validator-json/default.d.ts +6 -0
  212. package/validator-json/default.js +30 -2
  213. package/validator-json/defaultConverters.js +1 -0
  214. package/validator-json/options.d.ts +23 -0
  215. package/validators/common-validators.d.ts +143 -0
  216. package/validators/common-validators.js +249 -0
  217. package/validators/custom-validate.examples.d.ts +96 -0
  218. package/validators/custom-validate.examples.js +400 -0
  219. package/validators/custom-validate.validator.d.ts +133 -0
  220. package/validators/custom-validate.validator.js +213 -0
  221. package/validators/index.d.ts +2 -0
  222. package/validators/index.js +2 -0
  223. package/validators/is-exists.validator.d.ts +18 -4
  224. package/validators/is-exists.validator.js +67 -6
  225. package/validators/is-unique.validator.d.ts +19 -4
  226. package/validators/is-unique.validator.js +67 -11
  227. package/validators/skip-empty.validator.d.ts +5 -0
  228. package/validators/skip-empty.validator.js +5 -0
  229. package/vault/interfaces/vault-options.interface.d.ts +9 -0
  230. package/vault/vault-config.loader.d.ts +30 -0
  231. package/vault/vault-config.loader.js +48 -1
  232. package/vault/vault-config.service.d.ts +53 -0
  233. package/vault/vault-config.service.js +57 -0
  234. package/vault/vault.module.d.ts +4 -0
  235. package/vault/vault.module.js +4 -0
  236. package/decorators/examples/validation-decorators.example.d.ts +0 -69
  237. package/decorators/examples/validation-decorators.example.js +0 -331
@@ -24,6 +24,9 @@ const common_1 = require("@nestjs/common");
24
24
  const typeorm_1 = require("typeorm");
25
25
  const http_log_entity_1 = require("../entities/http-log.entity");
26
26
  const curl_generator_util_1 = require("../utils/curl-generator.util");
27
+ /**
28
+ * HTTP日志查询服务
29
+ */
27
30
  let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
28
31
  constructor(dataSource) {
29
32
  this.dataSource = dataSource;
@@ -31,6 +34,9 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
31
34
  this.logRepository = null;
32
35
  this.initializeRepository();
33
36
  }
37
+ /**
38
+ * 查询HTTP日志
39
+ */
34
40
  findLogs() {
35
41
  return __awaiter(this, arguments, void 0, function* (options = {}) {
36
42
  if (!this.logRepository) {
@@ -38,9 +44,12 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
38
44
  }
39
45
  const { page = 1, limit = 50, sortBy = 'createdAt', sortOrder = 'DESC', includeDetails = false, } = options;
40
46
  const queryBuilder = this.buildQuery(options, includeDetails);
47
+ // 分页
41
48
  const offset = (page - 1) * limit;
42
49
  queryBuilder.skip(offset).take(limit);
50
+ // 排序
43
51
  queryBuilder.orderBy(`log.${sortBy}`, sortOrder);
52
+ // 执行查询
44
53
  const [logs, total] = yield queryBuilder.getManyAndCount();
45
54
  return {
46
55
  logs,
@@ -51,6 +60,9 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
51
60
  };
52
61
  });
53
62
  }
63
+ /**
64
+ * 根据ID查询单条日志
65
+ */
54
66
  findLogById(id_1) {
55
67
  return __awaiter(this, arguments, void 0, function* (id, includeDetails = false) {
56
68
  if (!this.logRepository) {
@@ -63,6 +75,9 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
63
75
  return queryBuilder.where('log.id = :id', { id }).getOne();
64
76
  });
65
77
  }
78
+ /**
79
+ * 根据请求ID查询日志
80
+ */
66
81
  findLogByRequestId(requestId) {
67
82
  return __awaiter(this, void 0, void 0, function* () {
68
83
  if (!this.logRepository) {
@@ -74,12 +89,18 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
74
89
  });
75
90
  });
76
91
  }
92
+ /**
93
+ * 查询错误日志
94
+ */
77
95
  findErrorLogs() {
78
96
  return __awaiter(this, arguments, void 0, function* (options = {}) {
79
97
  const queryOptions = Object.assign(Object.assign({}, options), { success: false });
80
98
  return this.findLogs(queryOptions);
81
99
  });
82
100
  }
101
+ /**
102
+ * 查询慢请求日志
103
+ */
83
104
  findSlowRequests() {
84
105
  return __awaiter(this, arguments, void 0, function* (minResponseTime = 5000, options = {}) {
85
106
  if (!this.logRepository) {
@@ -97,6 +118,9 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
97
118
  return { logs, total };
98
119
  });
99
120
  }
121
+ /**
122
+ * 查询重试日志
123
+ */
100
124
  findRetryLogs() {
101
125
  return __awaiter(this, arguments, void 0, function* (options = {}) {
102
126
  if (!this.logRepository) {
@@ -115,12 +139,16 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
115
139
  return { logs, total };
116
140
  });
117
141
  }
142
+ /**
143
+ * 获取统计信息
144
+ */
118
145
  getStats() {
119
146
  return __awaiter(this, arguments, void 0, function* (options = {}) {
120
147
  if (!this.logRepository) {
121
148
  throw new Error('HTTP log repository not available');
122
149
  }
123
150
  const { startDate, endDate, userId, serviceName } = options;
151
+ // 基础查询构建器
124
152
  const baseQuery = this.logRepository.createQueryBuilder('log');
125
153
  if (startDate) {
126
154
  baseQuery.andWhere('log.createdAt >= :startDate', { startDate });
@@ -134,6 +162,7 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
134
162
  if (serviceName) {
135
163
  baseQuery.andWhere('log.serviceName = :serviceName', { serviceName });
136
164
  }
165
+ // 总体统计
137
166
  const [total, successful, failed] = yield Promise.all([
138
167
  baseQuery.getCount(),
139
168
  baseQuery
@@ -145,36 +174,43 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
145
174
  .andWhere('log.success = :success', { success: false })
146
175
  .getCount(),
147
176
  ]);
177
+ // 响应时间统计
148
178
  const responseTimeStats = yield baseQuery
149
179
  .select('AVG(log.responseTime)', 'avg')
150
180
  .addSelect('MIN(log.responseTime)', 'min')
151
181
  .addSelect('MAX(log.responseTime)', 'max')
152
182
  .getRawOne();
183
+ // 按HTTP方法统计
153
184
  const httpMethodStats = yield baseQuery
154
185
  .select('log.method', 'method')
155
186
  .addSelect('COUNT(*)', 'count')
156
187
  .groupBy('log.method')
157
188
  .getRawMany();
189
+ // 按状态码统计
158
190
  const statusStats = yield baseQuery
159
191
  .select('log.statusCode', 'statusCode')
160
192
  .addSelect('COUNT(*)', 'count')
161
193
  .groupBy('log.statusCode')
162
194
  .getRawMany();
195
+ // 按服务统计
163
196
  const serviceStats = yield baseQuery
164
197
  .select('log.serviceName', 'serviceName')
165
198
  .addSelect('COUNT(*)', 'count')
166
199
  .groupBy('log.serviceName')
167
200
  .getRawMany();
201
+ // 按操作统计
168
202
  const operationStats = yield baseQuery
169
203
  .select('log.operationName', 'operationName')
170
204
  .addSelect('COUNT(*)', 'count')
171
205
  .groupBy('log.operationName')
172
206
  .getRawMany();
207
+ // 按来源统计
173
208
  const sourceStats = yield baseQuery
174
209
  .select('log.source', 'source')
175
210
  .addSelect('COUNT(*)', 'count')
176
211
  .groupBy('log.source')
177
212
  .getRawMany();
213
+ // 错误统计
178
214
  const errorStats = yield baseQuery
179
215
  .clone()
180
216
  .where('log.success = :success', { success: false })
@@ -182,17 +218,20 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
182
218
  .addSelect('COUNT(*)', 'count')
183
219
  .groupBy('log.errorCode')
184
220
  .getRawMany();
221
+ // 重试统计
185
222
  const retryStats = yield baseQuery
186
223
  .select('AVG(log.attemptCount)', 'avgAttempts')
187
224
  .addSelect('MAX(log.attemptCount)', 'maxAttempts')
188
225
  .addSelect('SUM(log.attemptCount - 1)', 'totalRetries')
189
226
  .addSelect('COUNT(*)', 'totalRequests')
190
227
  .getRawOne();
228
+ // 缓存统计
191
229
  const cacheStats = yield baseQuery
192
230
  .select('SUM(CASE WHEN log.cacheHit = true THEN 1 ELSE 0 END)', 'cacheHits')
193
231
  .addSelect('SUM(CASE WHEN log.cacheHit = false OR log.cacheHit IS NULL THEN 1 ELSE 0 END)', 'cacheMisses')
194
232
  .addSelect('COUNT(*)', 'total')
195
233
  .getRawOne();
234
+ // 百分位数计算(简化版)
196
235
  const percentiles = yield this.calculatePercentiles(baseQuery);
197
236
  return {
198
237
  totalRequests: total,
@@ -230,6 +269,9 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
230
269
  };
231
270
  });
232
271
  }
272
+ /**
273
+ * 删除旧日志
274
+ */
233
275
  deleteOldLogs() {
234
276
  return __awaiter(this, arguments, void 0, function* (daysToKeep = 30) {
235
277
  if (!this.logRepository) {
@@ -246,6 +288,9 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
246
288
  return result.affected || 0;
247
289
  });
248
290
  }
291
+ /**
292
+ * 清空所有日志
293
+ */
249
294
  clearAllLogs() {
250
295
  return __awaiter(this, void 0, void 0, function* () {
251
296
  if (!this.logRepository) {
@@ -253,9 +298,14 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
253
298
  }
254
299
  yield this.logRepository.clear();
255
300
  this.logger.warn('Cleared all HTTP logs');
256
- return 0;
301
+ return 0; // Cannot get affected count from clear()
257
302
  });
258
303
  }
304
+ /**
305
+ * 根据日志ID生成curl命令
306
+ * @param logId 日志ID
307
+ * @returns curl命令字符串
308
+ */
259
309
  generateCurlFromLog(logId) {
260
310
  return __awaiter(this, void 0, void 0, function* () {
261
311
  if (!this.logRepository) {
@@ -269,7 +319,9 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
269
319
  return null;
270
320
  }
271
321
  try {
322
+ // 清理敏感信息
272
323
  const sanitizedHeaders = this.sanitizeHeadersForCurl(log.headers || {});
324
+ // 构建请求配置
273
325
  const requestConfig = {
274
326
  method: log.method,
275
327
  url: log.url,
@@ -277,6 +329,7 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
277
329
  data: log.body,
278
330
  params: log.params,
279
331
  };
332
+ // 使用CurlGenerator生成curl命令
280
333
  const curlCommand = curl_generator_util_1.CurlGenerator.generateCurlCommand(requestConfig);
281
334
  this.logger.log(`Generated curl command for log ${logId}`);
282
335
  return curlCommand;
@@ -287,6 +340,11 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
287
340
  }
288
341
  });
289
342
  }
343
+ /**
344
+ * 根据请求ID生成curl命令
345
+ * @param requestId 请求ID
346
+ * @returns curl命令字符串
347
+ */
290
348
  generateCurlFromRequestId(requestId) {
291
349
  return __awaiter(this, void 0, void 0, function* () {
292
350
  if (!this.logRepository) {
@@ -303,6 +361,11 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
303
361
  return this.generateCurlFromLog(log.id);
304
362
  });
305
363
  }
364
+ /**
365
+ * 根据日志生成可重放的请求配置
366
+ * @param logId 日志ID
367
+ * @returns 请求配置对象
368
+ */
306
369
  generateReplayConfigFromLog(logId) {
307
370
  return __awaiter(this, void 0, void 0, function* () {
308
371
  if (!this.logRepository) {
@@ -316,6 +379,7 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
316
379
  return null;
317
380
  }
318
381
  try {
382
+ // 构建重放配置
319
383
  const replayConfig = {
320
384
  method: log.method,
321
385
  url: log.url,
@@ -326,6 +390,7 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
326
390
  : log.body
327
391
  : undefined,
328
392
  params: log.params || {},
393
+ // 添加重放标记
329
394
  metadata: {
330
395
  originalLogId: log.id,
331
396
  originalRequestId: log.requestId,
@@ -342,6 +407,11 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
342
407
  }
343
408
  });
344
409
  }
410
+ /**
411
+ * 根据请求ID生成可重放的请求配置
412
+ * @param requestId 请求ID
413
+ * @returns 请求配置对象
414
+ */
345
415
  generateReplayConfigFromRequestId(requestId) {
346
416
  return __awaiter(this, void 0, void 0, function* () {
347
417
  if (!this.logRepository) {
@@ -358,11 +428,17 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
358
428
  return this.generateReplayConfigFromLog(log.id);
359
429
  });
360
430
  }
431
+ /**
432
+ * 批量生成curl命令
433
+ * @param options 查询选项
434
+ * @returns curl命令数组
435
+ */
361
436
  generateBatchCurlCommands() {
362
437
  return __awaiter(this, arguments, void 0, function* (options = {}) {
363
438
  if (!this.logRepository) {
364
439
  throw new Error('HTTP log repository not available');
365
440
  }
441
+ // 限制返回数量以避免过大的响应
366
442
  const limitedOptions = Object.assign(Object.assign({}, options), { limit: Math.min(options.limit || 10, 50) });
367
443
  const result = yield this.findLogs(limitedOptions);
368
444
  const curlCommands = [];
@@ -385,6 +461,11 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
385
461
  return curlCommands;
386
462
  });
387
463
  }
464
+ /**
465
+ * 获取日志的完整重放信息
466
+ * @param logId 日志ID
467
+ * @returns 包含curl命令和重放配置的对象
468
+ */
388
469
  getLogReplayInfo(logId) {
389
470
  return __awaiter(this, void 0, void 0, function* () {
390
471
  if (!this.logRepository) {
@@ -405,6 +486,11 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
405
486
  };
406
487
  });
407
488
  }
489
+ /**
490
+ * 根据请求ID获取日志的完整重放信息
491
+ * @param requestId 请求ID
492
+ * @returns 包含curl命令和重放配置的对象
493
+ */
408
494
  getLogReplayInfoByRequestId(requestId) {
409
495
  return __awaiter(this, void 0, void 0, function* () {
410
496
  const log = yield this.findLogByRequestId(requestId);
@@ -414,6 +500,9 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
414
500
  return this.getLogReplayInfo(log.id);
415
501
  });
416
502
  }
503
+ /**
504
+ * 初始化仓库
505
+ */
417
506
  initializeRepository() {
418
507
  if (this.dataSource) {
419
508
  try {
@@ -425,9 +514,13 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
425
514
  }
426
515
  }
427
516
  }
517
+ /**
518
+ * 计算响应时间百分位数
519
+ */
428
520
  calculatePercentiles(queryBuilder) {
429
521
  return __awaiter(this, void 0, void 0, function* () {
430
522
  try {
523
+ // 获取所有响应时间
431
524
  const results = yield queryBuilder
432
525
  .select('log.responseTime', 'responseTime')
433
526
  .where('log.responseTime IS NOT NULL')
@@ -456,6 +549,9 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
456
549
  }
457
550
  });
458
551
  }
552
+ /**
553
+ * 格式化统计结果
554
+ */
459
555
  formatStats(stats, keyField, valueField) {
460
556
  return stats.reduce((acc, item) => {
461
557
  const key = item[keyField] || 'unknown';
@@ -464,14 +560,19 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
464
560
  return acc;
465
561
  }, {});
466
562
  }
563
+ /**
564
+ * 构建查询
565
+ */
467
566
  buildQuery(options, includeDetails = false) {
468
567
  if (!this.logRepository) {
469
568
  throw new Error('HTTP log repository not available');
470
569
  }
471
570
  const queryBuilder = this.logRepository.createQueryBuilder('log');
571
+ // 关联查询重试记录
472
572
  if (includeDetails) {
473
573
  queryBuilder.leftJoinAndSelect('log.retryRecords', 'retryRecords');
474
574
  }
575
+ // 基础条件
475
576
  if (options.requestId) {
476
577
  queryBuilder.andWhere('log.requestId = :requestId', {
477
578
  requestId: options.requestId,
@@ -480,6 +581,7 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
480
581
  if (options.userId) {
481
582
  queryBuilder.andWhere('log.userId = :userId', { userId: options.userId });
482
583
  }
584
+ // 方法过滤
483
585
  if (options.method) {
484
586
  if (Array.isArray(options.method)) {
485
587
  queryBuilder.andWhere('log.method IN (:...methods)', {
@@ -492,9 +594,11 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
492
594
  });
493
595
  }
494
596
  }
597
+ // URL过滤
495
598
  if (options.url) {
496
599
  queryBuilder.andWhere('log.url LIKE :url', { url: `%${options.url}%` });
497
600
  }
601
+ // 状态码过滤
498
602
  if (options.statusCode) {
499
603
  if (Array.isArray(options.statusCode)) {
500
604
  queryBuilder.andWhere('log.statusCode IN (:...statusCodes)', {
@@ -507,39 +611,47 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
507
611
  });
508
612
  }
509
613
  }
614
+ // 成功状态过滤
510
615
  if (options.success !== undefined) {
511
616
  queryBuilder.andWhere('log.success = :success', {
512
617
  success: options.success,
513
618
  });
514
619
  }
620
+ // 服务名称过滤
515
621
  if (options.serviceName) {
516
622
  queryBuilder.andWhere('log.serviceName = :serviceName', {
517
623
  serviceName: options.serviceName,
518
624
  });
519
625
  }
626
+ // 操作名称过滤
520
627
  if (options.operationName) {
521
628
  queryBuilder.andWhere('log.operationName = :operationName', {
522
629
  operationName: options.operationName,
523
630
  });
524
631
  }
632
+ // 客户端IP过滤
525
633
  if (options.clientIp) {
526
634
  queryBuilder.andWhere('log.clientIp = :clientIp', {
527
635
  clientIp: options.clientIp,
528
636
  });
529
637
  }
638
+ // 来源过滤
530
639
  if (options.source) {
531
640
  queryBuilder.andWhere('log.source = :source', { source: options.source });
532
641
  }
642
+ // 标签过滤
533
643
  if (options.tags && options.tags.length > 0) {
534
644
  queryBuilder.andWhere('JSON_CONTAINS(log.tags, :tags)', {
535
645
  tags: JSON.stringify(options.tags),
536
646
  });
537
647
  }
648
+ // 错误代码过滤
538
649
  if (options.errorCode) {
539
650
  queryBuilder.andWhere('log.errorCode = :errorCode', {
540
651
  errorCode: options.errorCode,
541
652
  });
542
653
  }
654
+ // 响应时间范围过滤
543
655
  if (options.minResponseTime) {
544
656
  queryBuilder.andWhere('log.responseTime >= :minResponseTime', {
545
657
  minResponseTime: options.minResponseTime,
@@ -550,6 +662,7 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
550
662
  maxResponseTime: options.maxResponseTime,
551
663
  });
552
664
  }
665
+ // 时间范围过滤
553
666
  if (options.startDate) {
554
667
  queryBuilder.andWhere('log.createdAt >= :startDate', {
555
668
  startDate: options.startDate,
@@ -560,11 +673,18 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
560
673
  endDate: options.endDate,
561
674
  });
562
675
  }
676
+ // 关键词搜索
563
677
  if (options.keyword) {
564
678
  queryBuilder.andWhere('(log.url LIKE :keyword OR log.errorMessage LIKE :keyword OR log.body LIKE :keyword)', { keyword: `%${options.keyword}%` });
565
679
  }
566
680
  return queryBuilder;
567
681
  }
682
+ /**
683
+ * 清理敏感信息用于生成curl命令
684
+ * 移除或替换敏感的请求头和认证信息
685
+ * @param headers 原始请求头
686
+ * @returns 清理后的请求头
687
+ */
568
688
  sanitizeHeadersForCurl(headers) {
569
689
  const sensitiveHeaders = [
570
690
  'authorization',
@@ -577,6 +697,7 @@ let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
577
697
  const sanitized = Object.assign({}, headers);
578
698
  for (const header of sensitiveHeaders) {
579
699
  if (sanitized[header]) {
700
+ // 保留头部但替换值为占位符
580
701
  sanitized[header] = '***REDACTED***';
581
702
  }
582
703
  }
@@ -2,43 +2,110 @@ import { AxiosRequestConfig } from 'axios';
2
2
  import { HttpClientService } from './http-client.service';
3
3
  import { HttpLogQueryService } from './http-log-query.service';
4
4
  import { HttpLogEntity } from '../entities/http-log.entity';
5
+ /**
6
+ * 请求重放选项
7
+ */
5
8
  export interface HttpReplayOptions {
9
+ /** 是否覆盖原始请求头 */
6
10
  overrideHeaders?: boolean;
11
+ /** 是否覆盖原始请求体 */
7
12
  overrideBody?: boolean;
13
+ /** 是否覆盖原始参数 */
8
14
  overrideParams?: boolean;
15
+ /** 重放时的额外请求头 */
9
16
  additionalHeaders?: Record<string, string>;
17
+ /** 重放时的额外元数据 */
10
18
  metadata?: Record<string, any>;
19
+ /** 是否记录重放日志 */
11
20
  logReplay?: boolean;
21
+ /** 重放超时时间(毫秒) */
12
22
  timeout?: number;
13
23
  }
24
+ /**
25
+ * 请求重放结果
26
+ */
14
27
  export interface HttpReplayResult {
28
+ /** 重放的日志信息 */
15
29
  originalLog: HttpLogEntity;
30
+ /** 重放的请求配置 */
16
31
  requestConfig: AxiosRequestConfig;
32
+ /** 重放的响应结果 */
17
33
  response: any;
34
+ /** 重放耗时(毫秒) */
18
35
  responseTime: number;
36
+ /** 重放是否成功 */
19
37
  success: boolean;
38
+ /** 错误信息(如果失败) */
20
39
  error?: string;
40
+ /** 重放时间戳 */
21
41
  replayTimestamp: string;
42
+ /** 重放ID */
22
43
  replayId: string;
23
44
  }
45
+ /**
46
+ * 批量重放结果
47
+ */
24
48
  export interface BatchReplayResult {
49
+ /** 总请求数 */
25
50
  totalRequests: number;
51
+ /** 成功请求数 */
26
52
  successfulRequests: number;
53
+ /** 失败请求数 */
27
54
  failedRequests: number;
55
+ /** 成功率 */
28
56
  successRate: number;
57
+ /** 总耗时(毫秒) */
29
58
  totalResponseTime: number;
59
+ /** 平均响应时间(毫秒) */
30
60
  averageResponseTime: number;
61
+ /** 单个重放结果 */
31
62
  results: HttpReplayResult[];
32
63
  }
64
+ /**
65
+ * HTTP请求重放服务
66
+ * 提供基于HTTP日志的请求重放功能,支持单个请求和批量请求重放
67
+ */
33
68
  export declare class HttpReplayService {
34
69
  private readonly httpClient;
35
70
  private readonly logQueryService;
36
71
  private readonly logger;
37
72
  constructor(httpClient: HttpClientService, logQueryService: HttpLogQueryService);
73
+ /**
74
+ * 根据日志ID重放请求
75
+ * @param logId 日志ID
76
+ * @param options 重放选项
77
+ * @returns 重放结果
78
+ */
38
79
  replayByLogId(logId: string, options?: HttpReplayOptions): Promise<HttpReplayResult>;
80
+ /**
81
+ * 根据请求ID重放请求
82
+ * @param requestId 请求ID
83
+ * @param options 重放选项
84
+ * @returns 重放结果
85
+ */
39
86
  replayByRequestId(requestId: string, options?: HttpReplayOptions): Promise<HttpReplayResult>;
87
+ /**
88
+ * 批量重放请求
89
+ * @param logIds 日志ID数组
90
+ * @param options 重放选项
91
+ * @param concurrency 并发数
92
+ * @returns 批量重放结果
93
+ */
40
94
  batchReplay(logIds: string[], options?: HttpReplayOptions, concurrency?: number): Promise<BatchReplayResult>;
95
+ /**
96
+ * 根据查询条件批量重放请求
97
+ * @param queryOptions 查询选项
98
+ * @param replayOptions 重放选项
99
+ * @param concurrency 并发数
100
+ * @returns 批量重放结果
101
+ */
41
102
  batchReplayByQuery(queryOptions?: any, replayOptions?: HttpReplayOptions, concurrency?: number): Promise<BatchReplayResult>;
103
+ /**
104
+ * 重放请求并比较结果
105
+ * @param logId 日志ID
106
+ * @param options 重放选项
107
+ * @returns 包含原始和重放结果的比较
108
+ */
42
109
  replayAndCompare(logId: string, options?: HttpReplayOptions): Promise<{
43
110
  original: HttpLogEntity;
44
111
  replay: HttpReplayResult;
@@ -49,10 +116,44 @@ export declare class HttpReplayService {
49
116
  bodyMatch: boolean;
50
117
  };
51
118
  }>;
119
+ /**
120
+ * 构建重放配置
121
+ * @param log 原始日志
122
+ * @param options 重放选项
123
+ * @returns 请求配置
124
+ */
52
125
  private buildReplayConfig;
126
+ /**
127
+ * 执行重放请求
128
+ * @param config 请求配置
129
+ * @param options 重放选项
130
+ * @returns 响应结果
131
+ */
53
132
  private executeReplayRequest;
133
+ /**
134
+ * 生成重放ID
135
+ * @returns 重放ID
136
+ */
54
137
  private generateReplayId;
138
+ /**
139
+ * 数组分块
140
+ * @param array 原始数组
141
+ * @param size 块大小
142
+ * @returns 分块后的数组
143
+ */
55
144
  private chunkArray;
145
+ /**
146
+ * 比较响应头
147
+ * @param original 原始响应头
148
+ * @param replay 重放响应头
149
+ * @returns 是否匹配
150
+ */
56
151
  private compareHeaders;
152
+ /**
153
+ * 比较响应体
154
+ * @param original 原始响应体
155
+ * @param replay 重放响应体
156
+ * @returns 是否匹配
157
+ */
57
158
  private compareBodies;
58
159
  }