@nest-omni/core 4.1.3-1 → 4.1.3-11

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 (249) hide show
  1. package/audit/audit.module.d.ts +10 -0
  2. package/audit/audit.module.js +39 -1
  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 +9 -1
  6. package/audit/decorators/audit-controller.decorator.js +11 -2
  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 +76 -1
  10. package/audit/decorators/entity-audit.decorator.js +135 -3
  11. package/audit/decorators/index.d.ts +1 -0
  12. package/audit/decorators/index.js +1 -0
  13. package/audit/dto/audit-log-query.dto.d.ts +3 -0
  14. package/audit/dto/audit-log-query.dto.js +3 -0
  15. package/audit/dto/begin-transaction.dto.d.ts +3 -0
  16. package/audit/dto/begin-transaction.dto.js +3 -0
  17. package/audit/dto/compare-entities.dto.d.ts +3 -0
  18. package/audit/dto/compare-entities.dto.js +3 -0
  19. package/audit/dto/pre-check-restore.dto.d.ts +3 -0
  20. package/audit/dto/pre-check-restore.dto.js +3 -0
  21. package/audit/dto/restore-entity.dto.d.ts +3 -0
  22. package/audit/dto/restore-entity.dto.js +3 -0
  23. package/audit/entities/entity-audit-log.entity.d.ts +8 -0
  24. package/audit/entities/entity-audit-log.entity.js +33 -1
  25. package/audit/entities/entity-transaction.entity.d.ts +10 -0
  26. package/audit/entities/entity-transaction.entity.js +33 -1
  27. package/audit/entities/index.d.ts +2 -0
  28. package/audit/entities/index.js +2 -0
  29. package/audit/entities/manual-operation-log.entity.d.ts +4 -0
  30. package/audit/entities/manual-operation-log.entity.js +4 -0
  31. package/audit/entities/operation-template.entity.d.ts +4 -0
  32. package/audit/entities/operation-template.entity.js +4 -0
  33. package/audit/enums/audit.enums.d.ts +45 -5
  34. package/audit/enums/audit.enums.js +47 -4
  35. package/audit/index.d.ts +3 -1
  36. package/audit/index.js +30 -1
  37. package/audit/interceptors/audit.interceptor.d.ts +15 -0
  38. package/audit/interceptors/audit.interceptor.js +23 -1
  39. package/audit/interfaces/audit.interfaces.d.ts +182 -2
  40. package/audit/services/audit-context.service.d.ts +15 -0
  41. package/audit/services/audit-context.service.js +15 -0
  42. package/audit/services/audit-strategy.service.d.ts +6 -0
  43. package/audit/services/audit-strategy.service.js +13 -0
  44. package/audit/services/entity-audit.service.d.ts +129 -3
  45. package/audit/services/entity-audit.service.js +301 -6
  46. package/audit/services/index.d.ts +2 -0
  47. package/audit/services/index.js +2 -0
  48. package/audit/services/manual-audit-log.service.d.ts +124 -0
  49. package/audit/services/manual-audit-log.service.js +138 -0
  50. package/audit/services/multi-database.service.d.ts +12 -0
  51. package/audit/services/multi-database.service.js +12 -0
  52. package/audit/services/operation-description.service.d.ts +59 -0
  53. package/audit/services/operation-description.service.js +76 -2
  54. package/audit/services/transaction-audit.service.d.ts +30 -0
  55. package/audit/services/transaction-audit.service.js +47 -0
  56. package/audit/subscribers/entity-audit.subscriber.d.ts +15 -0
  57. package/audit/subscribers/entity-audit.subscriber.js +29 -1
  58. package/cache/cache-metrics.service.d.ts +67 -0
  59. package/cache/cache-metrics.service.js +68 -4
  60. package/cache/cache-serialization.service.d.ts +31 -0
  61. package/cache/cache-serialization.service.js +25 -0
  62. package/cache/cache.constants.d.ts +9 -0
  63. package/cache/cache.constants.js +9 -0
  64. package/cache/cache.health.d.ts +26 -0
  65. package/cache/cache.health.js +30 -0
  66. package/cache/cache.module.d.ts +86 -0
  67. package/cache/cache.module.js +71 -0
  68. package/cache/cache.service.d.ts +140 -0
  69. package/cache/cache.service.js +157 -0
  70. package/cache/cache.warmup.service.d.ts +39 -0
  71. package/cache/cache.warmup.service.js +32 -0
  72. package/cache/decorators/cache-evict.decorator.d.ts +47 -0
  73. package/cache/decorators/cache-evict.decorator.js +56 -0
  74. package/cache/decorators/cache-put.decorator.d.ts +34 -0
  75. package/cache/decorators/cache-put.decorator.js +39 -0
  76. package/cache/decorators/cacheable.decorator.d.ts +40 -0
  77. package/cache/decorators/cacheable.decorator.js +55 -0
  78. package/cache/dependencies/callback.dependency.d.ts +33 -0
  79. package/cache/dependencies/callback.dependency.js +39 -1
  80. package/cache/dependencies/chain.dependency.d.ts +28 -0
  81. package/cache/dependencies/chain.dependency.js +34 -0
  82. package/cache/dependencies/db.dependency.d.ts +45 -0
  83. package/cache/dependencies/db.dependency.js +48 -1
  84. package/cache/dependencies/file.dependency.d.ts +32 -0
  85. package/cache/dependencies/file.dependency.js +34 -0
  86. package/cache/dependencies/tag.dependency.d.ts +36 -0
  87. package/cache/dependencies/tag.dependency.js +36 -0
  88. package/cache/dependencies/time.dependency.d.ts +43 -0
  89. package/cache/dependencies/time.dependency.js +43 -0
  90. package/cache/examples/basic-usage.d.ts +15 -0
  91. package/cache/examples/basic-usage.js +62 -8
  92. package/cache/index.js +9 -0
  93. package/cache/interfaces/cache-dependency.interface.d.ts +53 -0
  94. package/cache/interfaces/cache-options.interface.d.ts +81 -0
  95. package/cache/interfaces/cache-options.interface.js +6 -0
  96. package/cache/interfaces/cache-provider.interface.d.ts +78 -0
  97. package/cache/providers/base-cache.provider.d.ts +14 -0
  98. package/cache/providers/base-cache.provider.js +16 -0
  99. package/cache/providers/cls-cache.provider.d.ts +20 -0
  100. package/cache/providers/cls-cache.provider.js +28 -0
  101. package/cache/providers/memory-cache.provider.d.ts +23 -0
  102. package/cache/providers/memory-cache.provider.js +26 -0
  103. package/cache/providers/redis-cache.provider.d.ts +26 -0
  104. package/cache/providers/redis-cache.provider.js +29 -0
  105. package/cache/utils/dependency-manager.util.d.ts +52 -0
  106. package/cache/utils/dependency-manager.util.js +59 -0
  107. package/cache/utils/key-generator.util.d.ts +42 -0
  108. package/cache/utils/key-generator.util.js +53 -1
  109. package/common/abstract.entity.d.ts +14 -0
  110. package/common/abstract.entity.js +14 -0
  111. package/common/boilerplate.polyfill.d.ts +142 -4
  112. package/common/boilerplate.polyfill.js +24 -100
  113. package/common/dto/dto-container.d.ts +16 -0
  114. package/common/dto/dto-container.js +20 -0
  115. package/common/dto/dto-decorators.d.ts +18 -0
  116. package/common/dto/dto-decorators.js +14 -0
  117. package/common/dto/dto-extensions.d.ts +11 -0
  118. package/common/dto/dto-extensions.js +9 -0
  119. package/common/dto/dto-service-accessor.d.ts +17 -0
  120. package/common/dto/dto-service-accessor.js +18 -0
  121. package/common/dto/dto-transformer.d.ts +12 -0
  122. package/common/dto/dto-transformer.js +9 -0
  123. package/common/dto/index.js +2 -0
  124. package/common/examples/paginate-and-map.example.d.ts +6 -0
  125. package/common/examples/paginate-and-map.example.js +26 -0
  126. package/common/utils.d.ts +15 -0
  127. package/common/utils.js +15 -0
  128. package/constants/language-code.js +1 -0
  129. package/decorators/field.decorators.js +8 -1
  130. package/decorators/property.decorators.js +1 -0
  131. package/decorators/public-route.decorator.js +1 -0
  132. package/decorators/transform.decorators.d.ts +27 -0
  133. package/decorators/transform.decorators.js +29 -0
  134. package/decorators/translate.decorator.js +1 -0
  135. package/decorators/user.decorator.js +1 -0
  136. package/decorators/validator.decorators.d.ts +8 -18
  137. package/decorators/validator.decorators.js +22 -190
  138. package/filters/constraint-errors.js +1 -0
  139. package/helpers/common.helper.d.ts +13 -0
  140. package/helpers/common.helper.js +13 -0
  141. package/http-client/config/http-client.config.d.ts +15 -0
  142. package/http-client/config/http-client.config.js +25 -9
  143. package/http-client/decorators/http-client.decorators.d.ts +63 -0
  144. package/http-client/decorators/http-client.decorators.js +71 -3
  145. package/http-client/entities/http-log.entity.d.ts +229 -0
  146. package/http-client/entities/http-log.entity.js +6 -1
  147. package/http-client/errors/http-client.errors.d.ts +57 -0
  148. package/http-client/errors/http-client.errors.js +58 -0
  149. package/http-client/examples/advanced-usage.example.d.ts +41 -0
  150. package/http-client/examples/advanced-usage.example.js +68 -24
  151. package/http-client/examples/auth-with-waiting-lock.example.d.ts +31 -0
  152. package/http-client/examples/auth-with-waiting-lock.example.js +52 -5
  153. package/http-client/examples/basic-usage.example.d.ts +60 -0
  154. package/http-client/examples/basic-usage.example.js +60 -0
  155. package/http-client/examples/multi-api-configuration.example.d.ts +60 -0
  156. package/http-client/examples/multi-api-configuration.example.js +76 -5
  157. package/http-client/http-client.module.d.ts +13 -0
  158. package/http-client/http-client.module.js +20 -5
  159. package/http-client/index.js +8 -0
  160. package/http-client/interfaces/api-client-config.interface.d.ts +125 -0
  161. package/http-client/interfaces/api-client-config.interface.js +3 -0
  162. package/http-client/interfaces/http-client-config.interface.d.ts +60 -0
  163. package/http-client/services/api-client-registry.service.d.ts +57 -0
  164. package/http-client/services/api-client-registry.service.js +84 -1
  165. package/http-client/services/cache.service.d.ts +52 -0
  166. package/http-client/services/cache.service.js +72 -3
  167. package/http-client/services/circuit-breaker.service.d.ts +46 -0
  168. package/http-client/services/circuit-breaker.service.js +52 -0
  169. package/http-client/services/http-client.service.d.ts +67 -0
  170. package/http-client/services/http-client.service.js +105 -4
  171. package/http-client/services/http-log-query.service.d.ts +83 -0
  172. package/http-client/services/http-log-query.service.js +122 -1
  173. package/http-client/services/http-replay.service.d.ts +101 -0
  174. package/http-client/services/http-replay.service.js +86 -0
  175. package/http-client/services/log-cleanup.service.d.ts +63 -0
  176. package/http-client/services/log-cleanup.service.js +54 -2
  177. package/http-client/services/logging.service.d.ts +40 -0
  178. package/http-client/services/logging.service.js +53 -0
  179. package/http-client/utils/call-stack-extractor.util.d.ts +37 -0
  180. package/http-client/utils/call-stack-extractor.util.js +48 -0
  181. package/http-client/utils/context-extractor.util.d.ts +49 -0
  182. package/http-client/utils/context-extractor.util.js +52 -0
  183. package/http-client/utils/curl-generator.util.d.ts +21 -0
  184. package/http-client/utils/curl-generator.util.js +44 -3
  185. package/http-client/utils/request-id.util.d.ts +18 -0
  186. package/http-client/utils/request-id.util.js +20 -0
  187. package/http-client/utils/retry-recorder.util.d.ts +42 -0
  188. package/http-client/utils/retry-recorder.util.js +44 -0
  189. package/i18n/en_US/validation.json +2 -1
  190. package/i18n/zh_CN/validation.json +2 -1
  191. package/index.js +8 -0
  192. package/interceptors/translation-interceptor.service.js +5 -0
  193. package/package.json +1 -1
  194. package/providers/context.provider.js +2 -0
  195. package/providers/generator.provider.d.ts +4 -0
  196. package/providers/generator.provider.js +4 -0
  197. package/redis-lock/comprehensive-lock-cleanup.service.d.ts +94 -0
  198. package/redis-lock/comprehensive-lock-cleanup.service.js +253 -0
  199. package/redis-lock/examples/lock-strategy.examples.d.ts +89 -0
  200. package/redis-lock/examples/lock-strategy.examples.js +130 -15
  201. package/redis-lock/index.d.ts +2 -0
  202. package/redis-lock/index.js +8 -1
  203. package/redis-lock/lock-heartbeat.service.d.ts +78 -0
  204. package/redis-lock/lock-heartbeat.service.js +222 -0
  205. package/redis-lock/redis-lock.decorator.d.ts +101 -0
  206. package/redis-lock/redis-lock.decorator.js +120 -0
  207. package/redis-lock/redis-lock.module.d.ts +66 -0
  208. package/redis-lock/redis-lock.module.js +175 -70
  209. package/redis-lock/redis-lock.service.d.ts +278 -0
  210. package/redis-lock/redis-lock.service.js +282 -12
  211. package/setup/bootstrap.setup.js +20 -0
  212. package/setup/mode.setup.d.ts +44 -0
  213. package/setup/mode.setup.js +44 -0
  214. package/setup/schedule.decorator.d.ts +227 -0
  215. package/setup/schedule.decorator.js +235 -12
  216. package/setup/worker.decorator.d.ts +86 -0
  217. package/setup/worker.decorator.js +88 -0
  218. package/shared/serviceRegistryModule.js +27 -14
  219. package/shared/services/api-config.service.d.ts +3 -0
  220. package/shared/services/api-config.service.js +20 -9
  221. package/validator-json/decorators.d.ts +17 -0
  222. package/validator-json/decorators.js +17 -2
  223. package/validator-json/default.d.ts +6 -0
  224. package/validator-json/default.js +30 -2
  225. package/validator-json/defaultConverters.js +1 -0
  226. package/validator-json/options.d.ts +23 -0
  227. package/validators/common-validators.d.ts +143 -0
  228. package/validators/common-validators.js +249 -0
  229. package/validators/custom-validate.examples.d.ts +96 -0
  230. package/validators/custom-validate.examples.js +400 -0
  231. package/validators/custom-validate.validator.d.ts +134 -0
  232. package/validators/custom-validate.validator.js +214 -0
  233. package/validators/index.d.ts +2 -0
  234. package/validators/index.js +2 -0
  235. package/validators/is-exists.validator.d.ts +18 -4
  236. package/validators/is-exists.validator.js +67 -6
  237. package/validators/is-unique.validator.d.ts +32 -5
  238. package/validators/is-unique.validator.js +99 -17
  239. package/validators/skip-empty.validator.d.ts +5 -0
  240. package/validators/skip-empty.validator.js +5 -0
  241. package/vault/interfaces/vault-options.interface.d.ts +9 -0
  242. package/vault/vault-config.loader.d.ts +30 -0
  243. package/vault/vault-config.loader.js +48 -1
  244. package/vault/vault-config.service.d.ts +53 -0
  245. package/vault/vault-config.service.js +57 -0
  246. package/vault/vault.module.d.ts +4 -0
  247. package/vault/vault.module.js +4 -0
  248. package/decorators/examples/validation-decorators.example.d.ts +0 -69
  249. package/decorators/examples/validation-decorators.example.js +0 -331
@@ -24,6 +24,10 @@ const common_1 = require("@nestjs/common");
24
24
  const http_client_service_1 = require("../services/http-client.service");
25
25
  const http_log_query_service_1 = require("../services/http-log-query.service");
26
26
  const http_replay_service_1 = require("../services/http-replay.service");
27
+ /**
28
+ * 使用等待锁的认证示例
29
+ * 演示如何在原有的HTTP客户端中使用等待锁机制
30
+ */
27
31
  let AuthWithWaitingLockExample = AuthWithWaitingLockExample_1 = class AuthWithWaitingLockExample {
28
32
  constructor(httpClient, logQueryService, replayService) {
29
33
  this.httpClient = httpClient;
@@ -31,6 +35,10 @@ let AuthWithWaitingLockExample = AuthWithWaitingLockExample_1 = class AuthWithWa
31
35
  this.replayService = replayService;
32
36
  this.logger = new common_1.Logger(AuthWithWaitingLockExample_1.name);
33
37
  }
38
+ /**
39
+ * 示例1: 基本的带等待锁的认证请求
40
+ * 演示如何使用authRequest方法确保只有一个进程获取token
41
+ */
34
42
  basicAuthWithLock() {
35
43
  return __awaiter(this, void 0, void 0, function* () {
36
44
  this.logger.log('=== 示例1: 基本带等待锁的认证请求 ===');
@@ -41,18 +49,21 @@ let AuthWithWaitingLockExample = AuthWithWaitingLockExample_1 = class AuthWithWa
41
49
  Accept: 'application/vnd.github.v3+json',
42
50
  },
43
51
  };
52
+ // Token提供函数
44
53
  const tokenProvider = () => __awaiter(this, void 0, void 0, function* () {
45
54
  this.logger.log('开始获取GitHub访问令牌...');
55
+ // 模拟token获取过程
46
56
  yield new Promise((resolve) => setTimeout(resolve, 1000));
47
57
  const token = `ghp_${Math.random().toString(36).substring(2, 15)}${Date.now()}`;
48
58
  this.logger.log(`成功获取令牌: ${token.substring(0, 20)}...`);
49
59
  return token;
50
60
  });
51
61
  try {
62
+ // 使用等待锁执行认证请求
52
63
  const response = yield this.httpClient.authRequest(requestConfig, tokenProvider, {
53
64
  lockKey: 'github-token-refresh',
54
- lockTimeout: 30000,
55
- waitTimeout: 60000,
65
+ lockTimeout: 30000, // 30秒锁超时
66
+ waitTimeout: 60000, // 60秒等待超时
56
67
  enableRetry: true,
57
68
  });
58
69
  this.logger.log('认证请求成功完成');
@@ -64,6 +75,10 @@ let AuthWithWaitingLockExample = AuthWithWaitingLockExample_1 = class AuthWithWa
64
75
  }
65
76
  });
66
77
  }
78
+ /**
79
+ * 示例2: 批量带等待锁的认证请求
80
+ * 演示如何在批量操作中共享token,避免重复认证
81
+ */
67
82
  batchAuthWithLock() {
68
83
  return __awaiter(this, void 0, void 0, function* () {
69
84
  this.logger.log('=== 示例2: 批量带等待锁的认证请求 ===');
@@ -90,6 +105,7 @@ let AuthWithWaitingLockExample = AuthWithWaitingLockExample_1 = class AuthWithWa
90
105
  key: 'user-followers',
91
106
  },
92
107
  ];
108
+ // Token提供函数
93
109
  const tokenProvider = () => __awaiter(this, void 0, void 0, function* () {
94
110
  this.logger.log('开始获取批量操作的GitHub访问令牌...');
95
111
  yield new Promise((resolve) => setTimeout(resolve, 1500));
@@ -99,11 +115,12 @@ let AuthWithWaitingLockExample = AuthWithWaitingLockExample_1 = class AuthWithWa
99
115
  });
100
116
  try {
101
117
  const startTime = Date.now();
118
+ // 使用批量认证请求,所有请求共享同一个token
102
119
  const results = yield this.httpClient.authBatchRequest(requests, tokenProvider, {
103
120
  lockKey: 'github-batch-token-refresh',
104
- lockTimeout: 60000,
105
- waitTimeout: 120000,
106
- maxConcurrency: 3,
121
+ lockTimeout: 60000, // 60秒锁超时
122
+ waitTimeout: 120000, // 2分钟等待超时
123
+ maxConcurrency: 3, // 最大并发数
107
124
  });
108
125
  const endTime = Date.now();
109
126
  const duration = endTime - startTime;
@@ -125,10 +142,15 @@ let AuthWithWaitingLockExample = AuthWithWaitingLockExample_1 = class AuthWithWa
125
142
  }
126
143
  });
127
144
  }
145
+ /**
146
+ * 示例3: 从HTTP日志生成curl命令
147
+ * 演示如何从已有的HTTP日志生成可执行的curl命令
148
+ */
128
149
  generateCurlFromLogs() {
129
150
  return __awaiter(this, void 0, void 0, function* () {
130
151
  this.logger.log('=== 示例3: 从HTTP日志生成curl命令 ===');
131
152
  try {
153
+ // 查询最近的日志
132
154
  const recentLogs = yield this.logQueryService.findLogs({
133
155
  limit: 5,
134
156
  sortBy: 'createdAt',
@@ -139,6 +161,7 @@ let AuthWithWaitingLockExample = AuthWithWaitingLockExample_1 = class AuthWithWa
139
161
  return;
140
162
  }
141
163
  this.logger.log(`找到 ${recentLogs.logs.length} 条最近的HTTP日志`);
164
+ // 为每条日志生成curl命令
142
165
  for (const log of recentLogs.logs) {
143
166
  const curlCommand = yield this.logQueryService.generateCurlFromLog(log.id);
144
167
  if (curlCommand) {
@@ -148,6 +171,7 @@ ${curlCommand}
148
171
  `);
149
172
  }
150
173
  }
174
+ // 批量生成curl命令
151
175
  const batchCurlCommands = yield this.logQueryService.generateBatchCurlCommands({
152
176
  limit: 3,
153
177
  method: 'GET',
@@ -159,11 +183,16 @@ ${curlCommand}
159
183
  }
160
184
  });
161
185
  }
186
+ /**
187
+ * 示例4: 请求重放功能
188
+ * 演示如何重放已有的HTTP请求
189
+ */
162
190
  demonstrateRequestReplay() {
163
191
  return __awaiter(this, void 0, void 0, function* () {
164
192
  var _a, _b, _c;
165
193
  this.logger.log('=== 示例4: 请求重放功能 ===');
166
194
  try {
195
+ // 查询一个成功的请求进行重放
167
196
  const successfulLogs = yield this.logQueryService.findLogs({
168
197
  limit: 1,
169
198
  success: true,
@@ -177,6 +206,7 @@ ${curlCommand}
177
206
  }
178
207
  const logToReplay = successfulLogs.logs[0];
179
208
  this.logger.log(`准备重放请求: ${logToReplay.method} ${logToReplay.url}`);
209
+ // 重放请求
180
210
  const replayResult = yield this.replayService.replayByLogId(logToReplay.id, {
181
211
  overrideHeaders: false,
182
212
  additionalHeaders: {
@@ -206,11 +236,16 @@ ${curlCommand}
206
236
  }
207
237
  });
208
238
  }
239
+ /**
240
+ * 示例5: 批量重放和比较
241
+ * 演示如何批量重放请求并比较结果
242
+ */
209
243
  batchReplayAndCompare() {
210
244
  return __awaiter(this, void 0, void 0, function* () {
211
245
  var _a, _b, _c;
212
246
  this.logger.log('=== 示例5: 批量重放和比较 ===');
213
247
  try {
248
+ // 查询最近的3个GET请求进行批量重放
214
249
  const batchReplayResult = yield this.replayService.batchReplayByQuery({
215
250
  method: 'GET',
216
251
  limit: 3,
@@ -234,6 +269,7 @@ ${curlCommand}
234
269
  │ 平均响应时间 │ ${batchReplayResult.averageResponseTime.toFixed(1).toString().padStart(7)}ms │
235
270
  └─────────────────┴──────────┘
236
271
  `);
272
+ // 详细比较每个重放结果
237
273
  for (let i = 0; i < Math.min(batchReplayResult.results.length, 3); i++) {
238
274
  const result = batchReplayResult.results[i];
239
275
  if (result.originalLog.id) {
@@ -262,12 +298,18 @@ ${curlCommand}
262
298
  }
263
299
  });
264
300
  }
301
+ /**
302
+ * 示例6: 综合演示 - 等待锁 + curl生成 + 请求重放
303
+ * 演示完整的工作流程
304
+ */
265
305
  comprehensiveDemo() {
266
306
  return __awaiter(this, void 0, void 0, function* () {
267
307
  this.logger.log('=== 示例6: 综合演示 ===');
268
308
  try {
309
+ // 1. 执行带等待锁的认证请求
269
310
  this.logger.log('步骤1: 执行带等待锁的认证请求');
270
311
  const authResponse = yield this.basicAuthWithLock();
312
+ // 2. 查询刚才的请求日志
271
313
  this.logger.log('\n步骤2: 查询请求日志');
272
314
  const recentLogs = yield this.logQueryService.findLogs({
273
315
  limit: 1,
@@ -276,12 +318,14 @@ ${curlCommand}
276
318
  });
277
319
  if (recentLogs.logs.length > 0) {
278
320
  const log = recentLogs.logs[0];
321
+ // 3. 生成curl命令
279
322
  this.logger.log('\n步骤3: 生成curl命令');
280
323
  const curlCommand = yield this.logQueryService.generateCurlFromLog(log.id);
281
324
  if (curlCommand) {
282
325
  this.logger.log('生成的curl命令:');
283
326
  this.logger.log(curlCommand);
284
327
  }
328
+ // 4. 重放请求
285
329
  this.logger.log('\n步骤4: 重放请求');
286
330
  const replayResult = yield this.replayService.replayByLogId(log.id, {
287
331
  additionalHeaders: {
@@ -304,6 +348,9 @@ ${curlCommand}
304
348
  }
305
349
  });
306
350
  }
351
+ /**
352
+ * 运行所有示例
353
+ */
307
354
  runAllExamples() {
308
355
  return __awaiter(this, void 0, void 0, function* () {
309
356
  this.logger.log('开始运行HTTP客户端等待锁和请求重放示例...\n');
@@ -1,19 +1,55 @@
1
1
  import { HttpClientService, HttpLogQueryService } from '../services';
2
2
  import { HttpLogQueryOptions } from '../entities';
3
+ /**
4
+ * 基本使用示例
5
+ */
3
6
  export declare class BasicHttpExample {
4
7
  private readonly httpClient;
5
8
  private readonly logQueryService;
6
9
  constructor(httpClient: HttpClientService, logQueryService: HttpLogQueryService);
10
+ /**
11
+ * 简单GET请求
12
+ */
7
13
  getUser(id: string): Promise<any>;
14
+ /**
15
+ * 带参数的GET请求
16
+ */
8
17
  searchUsers(query: string, page?: number, limit?: number): Promise<any>;
18
+ /**
19
+ * POST请求
20
+ */
9
21
  createUser(userData: any): Promise<any>;
22
+ /**
23
+ * PUT请求
24
+ */
10
25
  updateUser(id: string, userData: any): Promise<any>;
26
+ /**
27
+ * DELETE请求
28
+ */
11
29
  deleteUser(id: string): Promise<any>;
30
+ /**
31
+ * 文件上传
32
+ */
12
33
  uploadFile(file: Buffer, filename: string): Promise<any>;
34
+ /**
35
+ * 自定义请求配置
36
+ */
13
37
  customRequest(): Promise<any>;
38
+ /**
39
+ * 获取统计信息
40
+ */
14
41
  getStatistics(): any;
42
+ /**
43
+ * 重置统计信息
44
+ */
15
45
  resetStatistics(): void;
46
+ /**
47
+ * 生成curl命令
48
+ */
16
49
  generateCurlForRequest(url: string, method?: string, data?: any): string;
50
+ /**
51
+ * 查询HTTP日志
52
+ */
17
53
  queryHttpLogs(options?: HttpLogQueryOptions): Promise<{
18
54
  logs: import("../entities").HttpLogEntity[];
19
55
  total: number;
@@ -21,18 +57,30 @@ export declare class BasicHttpExample {
21
57
  limit: number;
22
58
  totalPages: number;
23
59
  }>;
60
+ /**
61
+ * 查询错误日志
62
+ */
24
63
  findErrorLogs(limit?: number): Promise<{
25
64
  logs: import("../entities").HttpLogEntity[];
26
65
  total: number;
27
66
  }>;
67
+ /**
68
+ * 查询慢请求
69
+ */
28
70
  findSlowRequests(minResponseTime?: number): Promise<{
29
71
  logs: import("../entities").HttpLogEntity[];
30
72
  total: number;
31
73
  }>;
74
+ /**
75
+ * 查询重试日志
76
+ */
32
77
  findRetryLogs(minRetries?: number): Promise<{
33
78
  logs: import("../entities").HttpLogEntity[];
34
79
  total: number;
35
80
  }>;
81
+ /**
82
+ * 根据服务名称查询日志
83
+ */
36
84
  findLogsByServiceName(serviceName: string, limit?: number): Promise<{
37
85
  logs: import("../entities").HttpLogEntity[];
38
86
  total: number;
@@ -40,6 +88,9 @@ export declare class BasicHttpExample {
40
88
  limit: number;
41
89
  totalPages: number;
42
90
  }>;
91
+ /**
92
+ * 根据操作名称查询日志
93
+ */
43
94
  findLogsByOperationName(operationName: string, limit?: number): Promise<{
44
95
  logs: import("../entities").HttpLogEntity[];
45
96
  total: number;
@@ -47,7 +98,16 @@ export declare class BasicHttpExample {
47
98
  limit: number;
48
99
  totalPages: number;
49
100
  }>;
101
+ /**
102
+ * 获取HTTP统计信息
103
+ */
50
104
  getHttpStats(startDate?: Date, endDate?: Date): Promise<import("../entities").HttpLogStats>;
105
+ /**
106
+ * 根据请求ID查询日志
107
+ */
51
108
  findLogByRequestId(requestId: string): Promise<import("../entities").HttpLogEntity>;
109
+ /**
110
+ * 清理旧日志
111
+ */
52
112
  cleanupOldLogs(daysToKeep?: number): Promise<number>;
53
113
  }
@@ -21,16 +21,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.BasicHttpExample = void 0;
22
22
  const common_1 = require("@nestjs/common");
23
23
  const services_1 = require("../services");
24
+ /**
25
+ * 基本使用示例
26
+ */
24
27
  let BasicHttpExample = class BasicHttpExample {
25
28
  constructor(httpClient, logQueryService) {
26
29
  this.httpClient = httpClient;
27
30
  this.logQueryService = logQueryService;
28
31
  }
32
+ /**
33
+ * 简单GET请求
34
+ */
29
35
  getUser(id) {
30
36
  return __awaiter(this, void 0, void 0, function* () {
31
37
  return this.httpClient.get(`/users/${id}`);
32
38
  });
33
39
  }
40
+ /**
41
+ * 带参数的GET请求
42
+ */
34
43
  searchUsers(query_1) {
35
44
  return __awaiter(this, arguments, void 0, function* (query, page = 1, limit = 10) {
36
45
  return this.httpClient.get('/users', {
@@ -42,6 +51,9 @@ let BasicHttpExample = class BasicHttpExample {
42
51
  });
43
52
  });
44
53
  }
54
+ /**
55
+ * POST请求
56
+ */
45
57
  createUser(userData) {
46
58
  return __awaiter(this, void 0, void 0, function* () {
47
59
  return this.httpClient.post('/users', userData, {
@@ -51,16 +63,25 @@ let BasicHttpExample = class BasicHttpExample {
51
63
  });
52
64
  });
53
65
  }
66
+ /**
67
+ * PUT请求
68
+ */
54
69
  updateUser(id, userData) {
55
70
  return __awaiter(this, void 0, void 0, function* () {
56
71
  return this.httpClient.put(`/users/${id}`, userData);
57
72
  });
58
73
  }
74
+ /**
75
+ * DELETE请求
76
+ */
59
77
  deleteUser(id) {
60
78
  return __awaiter(this, void 0, void 0, function* () {
61
79
  return this.httpClient.delete(`/users/${id}`);
62
80
  });
63
81
  }
82
+ /**
83
+ * 文件上传
84
+ */
64
85
  uploadFile(file, filename) {
65
86
  return __awaiter(this, void 0, void 0, function* () {
66
87
  const formData = new FormData();
@@ -72,6 +93,9 @@ let BasicHttpExample = class BasicHttpExample {
72
93
  });
73
94
  });
74
95
  }
96
+ /**
97
+ * 自定义请求配置
98
+ */
75
99
  customRequest() {
76
100
  return __awaiter(this, void 0, void 0, function* () {
77
101
  return this.httpClient.request({
@@ -89,12 +113,21 @@ let BasicHttpExample = class BasicHttpExample {
89
113
  });
90
114
  });
91
115
  }
116
+ /**
117
+ * 获取统计信息
118
+ */
92
119
  getStatistics() {
93
120
  return this.httpClient.getStats();
94
121
  }
122
+ /**
123
+ * 重置统计信息
124
+ */
95
125
  resetStatistics() {
96
126
  this.httpClient.resetStats();
97
127
  }
128
+ /**
129
+ * 生成curl命令
130
+ */
98
131
  generateCurlForRequest(url, method = 'GET', data) {
99
132
  const config = {
100
133
  url,
@@ -107,46 +140,73 @@ let BasicHttpExample = class BasicHttpExample {
107
140
  };
108
141
  return this.httpClient.generateCurlCommand(config);
109
142
  }
143
+ /**
144
+ * 查询HTTP日志
145
+ */
110
146
  queryHttpLogs() {
111
147
  return __awaiter(this, arguments, void 0, function* (options = {}) {
112
148
  return this.logQueryService.findLogs(options);
113
149
  });
114
150
  }
151
+ /**
152
+ * 查询错误日志
153
+ */
115
154
  findErrorLogs() {
116
155
  return __awaiter(this, arguments, void 0, function* (limit = 10) {
117
156
  return this.logQueryService.findErrorLogs({ limit });
118
157
  });
119
158
  }
159
+ /**
160
+ * 查询慢请求
161
+ */
120
162
  findSlowRequests() {
121
163
  return __awaiter(this, arguments, void 0, function* (minResponseTime = 5000) {
122
164
  return this.logQueryService.findSlowRequests(minResponseTime);
123
165
  });
124
166
  }
167
+ /**
168
+ * 查询重试日志
169
+ */
125
170
  findRetryLogs() {
126
171
  return __awaiter(this, arguments, void 0, function* (minRetries = 2) {
127
172
  return this.logQueryService.findRetryLogs({ minRetries });
128
173
  });
129
174
  }
175
+ /**
176
+ * 根据服务名称查询日志
177
+ */
130
178
  findLogsByServiceName(serviceName_1) {
131
179
  return __awaiter(this, arguments, void 0, function* (serviceName, limit = 20) {
132
180
  return this.logQueryService.findLogs({ serviceName, limit });
133
181
  });
134
182
  }
183
+ /**
184
+ * 根据操作名称查询日志
185
+ */
135
186
  findLogsByOperationName(operationName_1) {
136
187
  return __awaiter(this, arguments, void 0, function* (operationName, limit = 20) {
137
188
  return this.logQueryService.findLogs({ operationName, limit });
138
189
  });
139
190
  }
191
+ /**
192
+ * 获取HTTP统计信息
193
+ */
140
194
  getHttpStats(startDate, endDate) {
141
195
  return __awaiter(this, void 0, void 0, function* () {
142
196
  return this.logQueryService.getStats({ startDate, endDate });
143
197
  });
144
198
  }
199
+ /**
200
+ * 根据请求ID查询日志
201
+ */
145
202
  findLogByRequestId(requestId) {
146
203
  return __awaiter(this, void 0, void 0, function* () {
147
204
  return this.logQueryService.findLogByRequestId(requestId);
148
205
  });
149
206
  }
207
+ /**
208
+ * 清理旧日志
209
+ */
150
210
  cleanupOldLogs() {
151
211
  return __awaiter(this, arguments, void 0, function* (daysToKeep = 30) {
152
212
  return this.logQueryService.deleteOldLogs(daysToKeep);
@@ -1,10 +1,19 @@
1
1
  import { ApiClientInstanceConfig, ApiClientRegistryService } from '../services/api-client-registry.service';
2
+ /**
3
+ * GitHub API 客户端示例
4
+ */
2
5
  export declare class GitHubApiService {
3
6
  private readonly apiRegistry;
4
7
  constructor(apiRegistry: ApiClientRegistryService);
8
+ /**
9
+ * 获取GitHub客户端
10
+ */
5
11
  get github(): GitHubApiClient;
6
12
  private initializeClients;
7
13
  }
14
+ /**
15
+ * GitHub API 类型定义
16
+ */
8
17
  export interface GitHubApiClient {
9
18
  get<T = any>(url: string, config?: any): Promise<T>;
10
19
  post<T = any>(url: string, data?: any, config?: any): Promise<T>;
@@ -14,6 +23,9 @@ export interface GitHubApiClient {
14
23
  getStats(): any;
15
24
  resetStats(): void;
16
25
  }
26
+ /**
27
+ * Stripe API 客户端示例
28
+ */
17
29
  export declare class StripeApiService {
18
30
  private readonly apiRegistry;
19
31
  constructor(apiRegistry: ApiClientRegistryService);
@@ -27,6 +39,9 @@ export interface StripeApiClient {
27
39
  getStats(): any;
28
40
  resetStats(): void;
29
41
  }
42
+ /**
43
+ * 微信API客户端示例
44
+ */
30
45
  export declare class WeChatApiService {
31
46
  private readonly apiRegistry;
32
47
  constructor(apiRegistry: ApiClientRegistryService);
@@ -40,6 +55,9 @@ export interface WeChatApiClient {
40
55
  getStats(): any;
41
56
  resetStats(): void;
42
57
  }
58
+ /**
59
+ * 自定义API客户端示例(复杂响应格式)
60
+ */
43
61
  export declare class CustomApiService {
44
62
  private readonly apiRegistry;
45
63
  constructor(apiRegistry: ApiClientRegistryService);
@@ -59,12 +77,27 @@ export interface CustomApiClient {
59
77
  getStats(): any;
60
78
  resetStats(): void;
61
79
  }
80
+ /**
81
+ * API管理服务示例
82
+ */
62
83
  export declare class ApiManagementService {
63
84
  private readonly apiRegistry;
64
85
  constructor(apiRegistry: ApiClientRegistryService);
86
+ /**
87
+ * 动态创建API客户端
88
+ */
65
89
  createDynamicClient(name: string, config: Partial<ApiClientInstanceConfig>): any;
90
+ /**
91
+ * 获取所有客户端统计信息
92
+ */
66
93
  getAllStats(): Record<string, any>;
94
+ /**
95
+ * 重置所有统计信息
96
+ */
67
97
  resetAllStats(): void;
98
+ /**
99
+ * 健康检查
100
+ */
68
101
  healthCheck(): Promise<{
69
102
  status: "healthy" | "unhealthy";
70
103
  clients: Record<string, {
@@ -72,9 +105,18 @@ export declare class ApiManagementService {
72
105
  error?: string;
73
106
  }>;
74
107
  }>;
108
+ /**
109
+ * 批量创建客户端
110
+ */
75
111
  createMultipleClients(configs: ApiClientInstanceConfig[]): void;
112
+ /**
113
+ * 获取客户端列表
114
+ */
76
115
  listClients(): string[];
77
116
  }
117
+ /**
118
+ * 使用示例控制器
119
+ */
78
120
  export declare class ExampleController {
79
121
  private readonly githubApi;
80
122
  private readonly stripeApi;
@@ -82,11 +124,29 @@ export declare class ExampleController {
82
124
  private readonly customApi;
83
125
  private readonly apiManagement;
84
126
  constructor(githubApi: GitHubApiService, stripeApi: StripeApiService, wechatApi: WeChatApiService, customApi: CustomApiService, apiManagement: ApiManagementService);
127
+ /**
128
+ * GitHub API 示例
129
+ */
85
130
  getGitHubUser(username: string): Promise<any>;
131
+ /**
132
+ * Stripe API 示例
133
+ */
86
134
  createStripePayment(amount: number, currency: string): Promise<any>;
135
+ /**
136
+ * 微信 API 示例
137
+ */
87
138
  sendWeChatMessage(openid: string, content: string): Promise<any>;
139
+ /**
140
+ * 自定义API 示例
141
+ */
88
142
  getCustomData(id: string): Promise<any>;
143
+ /**
144
+ * 动态API示例
145
+ */
89
146
  callDynamicApi(url: string): Promise<any>;
147
+ /**
148
+ * API管理示例
149
+ */
90
150
  getApiHealth(): Promise<{
91
151
  status: "healthy" | "unhealthy";
92
152
  clients: Record<string, {