@nest-omni/core 4.1.3-2 → 4.1.3-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/audit/audit.module.d.ts +10 -0
- package/audit/audit.module.js +15 -0
- package/audit/controllers/audit.controller.d.ts +24 -0
- package/audit/controllers/audit.controller.js +24 -0
- package/audit/decorators/audit-controller.decorator.d.ts +8 -0
- package/audit/decorators/audit-controller.decorator.js +9 -0
- package/audit/decorators/audit-operation.decorator.d.ts +45 -0
- package/audit/decorators/audit-operation.decorator.js +49 -0
- package/audit/decorators/entity-audit.decorator.d.ts +8 -0
- package/audit/decorators/entity-audit.decorator.js +9 -0
- package/audit/dto/audit-log-query.dto.d.ts +3 -0
- package/audit/dto/audit-log-query.dto.js +3 -0
- package/audit/dto/begin-transaction.dto.d.ts +3 -0
- package/audit/dto/begin-transaction.dto.js +3 -0
- package/audit/dto/compare-entities.dto.d.ts +3 -0
- package/audit/dto/compare-entities.dto.js +3 -0
- package/audit/dto/pre-check-restore.dto.d.ts +3 -0
- package/audit/dto/pre-check-restore.dto.js +3 -0
- package/audit/dto/restore-entity.dto.d.ts +3 -0
- package/audit/dto/restore-entity.dto.js +3 -0
- package/audit/entities/entity-audit-log.entity.d.ts +3 -0
- package/audit/entities/entity-audit-log.entity.js +3 -0
- package/audit/entities/entity-transaction.entity.d.ts +3 -0
- package/audit/entities/entity-transaction.entity.js +3 -0
- package/audit/entities/manual-operation-log.entity.d.ts +4 -0
- package/audit/entities/manual-operation-log.entity.js +4 -0
- package/audit/entities/operation-template.entity.d.ts +4 -0
- package/audit/entities/operation-template.entity.js +4 -0
- package/audit/enums/audit.enums.d.ts +17 -2
- package/audit/enums/audit.enums.js +15 -0
- package/audit/index.js +10 -0
- package/audit/interceptors/audit.interceptor.d.ts +15 -0
- package/audit/interceptors/audit.interceptor.js +23 -1
- package/audit/interfaces/audit.interfaces.d.ts +42 -0
- package/audit/services/audit-context.service.d.ts +15 -0
- package/audit/services/audit-context.service.js +15 -0
- package/audit/services/audit-strategy.service.d.ts +6 -0
- package/audit/services/audit-strategy.service.js +13 -0
- package/audit/services/entity-audit.service.d.ts +57 -0
- package/audit/services/entity-audit.service.js +91 -0
- package/audit/services/manual-audit-log.service.d.ts +124 -0
- package/audit/services/manual-audit-log.service.js +138 -0
- package/audit/services/multi-database.service.d.ts +12 -0
- package/audit/services/multi-database.service.js +12 -0
- package/audit/services/operation-description.service.d.ts +59 -0
- package/audit/services/operation-description.service.js +76 -2
- package/audit/services/transaction-audit.service.d.ts +30 -0
- package/audit/services/transaction-audit.service.js +47 -0
- package/audit/subscribers/entity-audit.subscriber.d.ts +15 -0
- package/audit/subscribers/entity-audit.subscriber.js +29 -1
- package/cache/cache-metrics.service.d.ts +67 -0
- package/cache/cache-metrics.service.js +68 -4
- package/cache/cache-serialization.service.d.ts +31 -0
- package/cache/cache-serialization.service.js +25 -0
- package/cache/cache.constants.d.ts +9 -0
- package/cache/cache.constants.js +9 -0
- package/cache/cache.health.d.ts +26 -0
- package/cache/cache.health.js +30 -0
- package/cache/cache.module.d.ts +86 -0
- package/cache/cache.module.js +71 -0
- package/cache/cache.service.d.ts +140 -0
- package/cache/cache.service.js +157 -0
- package/cache/cache.warmup.service.d.ts +39 -0
- package/cache/cache.warmup.service.js +32 -0
- package/cache/decorators/cache-evict.decorator.d.ts +47 -0
- package/cache/decorators/cache-evict.decorator.js +56 -0
- package/cache/decorators/cache-put.decorator.d.ts +34 -0
- package/cache/decorators/cache-put.decorator.js +39 -0
- package/cache/decorators/cacheable.decorator.d.ts +40 -0
- package/cache/decorators/cacheable.decorator.js +55 -0
- package/cache/dependencies/callback.dependency.d.ts +33 -0
- package/cache/dependencies/callback.dependency.js +39 -1
- package/cache/dependencies/chain.dependency.d.ts +28 -0
- package/cache/dependencies/chain.dependency.js +34 -0
- package/cache/dependencies/db.dependency.d.ts +45 -0
- package/cache/dependencies/db.dependency.js +48 -1
- package/cache/dependencies/file.dependency.d.ts +32 -0
- package/cache/dependencies/file.dependency.js +34 -0
- package/cache/dependencies/tag.dependency.d.ts +36 -0
- package/cache/dependencies/tag.dependency.js +36 -0
- package/cache/dependencies/time.dependency.d.ts +43 -0
- package/cache/dependencies/time.dependency.js +43 -0
- package/cache/examples/basic-usage.d.ts +15 -0
- package/cache/examples/basic-usage.js +62 -8
- package/cache/index.js +9 -0
- package/cache/interfaces/cache-dependency.interface.d.ts +53 -0
- package/cache/interfaces/cache-options.interface.d.ts +81 -0
- package/cache/interfaces/cache-options.interface.js +6 -0
- package/cache/interfaces/cache-provider.interface.d.ts +78 -0
- package/cache/providers/base-cache.provider.d.ts +14 -0
- package/cache/providers/base-cache.provider.js +16 -0
- package/cache/providers/cls-cache.provider.d.ts +20 -0
- package/cache/providers/cls-cache.provider.js +28 -0
- package/cache/providers/memory-cache.provider.d.ts +23 -0
- package/cache/providers/memory-cache.provider.js +26 -0
- package/cache/providers/redis-cache.provider.d.ts +26 -0
- package/cache/providers/redis-cache.provider.js +29 -0
- package/cache/utils/dependency-manager.util.d.ts +52 -0
- package/cache/utils/dependency-manager.util.js +59 -0
- package/cache/utils/key-generator.util.d.ts +42 -0
- package/cache/utils/key-generator.util.js +53 -1
- package/common/abstract.entity.d.ts +14 -0
- package/common/abstract.entity.js +14 -0
- package/common/boilerplate.polyfill.d.ts +142 -0
- package/common/boilerplate.polyfill.js +17 -0
- package/common/dto/dto-container.d.ts +16 -0
- package/common/dto/dto-container.js +20 -0
- package/common/dto/dto-decorators.d.ts +18 -0
- package/common/dto/dto-decorators.js +14 -0
- package/common/dto/dto-extensions.d.ts +11 -0
- package/common/dto/dto-extensions.js +9 -0
- package/common/dto/dto-service-accessor.d.ts +17 -0
- package/common/dto/dto-service-accessor.js +18 -0
- package/common/dto/dto-transformer.d.ts +12 -0
- package/common/dto/dto-transformer.js +9 -0
- package/common/dto/index.js +2 -0
- package/common/examples/paginate-and-map.example.d.ts +6 -0
- package/common/examples/paginate-and-map.example.js +26 -0
- package/common/utils.d.ts +15 -0
- package/common/utils.js +15 -0
- package/constants/language-code.js +1 -0
- package/decorators/field.decorators.js +8 -1
- package/decorators/property.decorators.js +1 -0
- package/decorators/public-route.decorator.js +1 -0
- package/decorators/transform.decorators.d.ts +27 -0
- package/decorators/transform.decorators.js +29 -0
- package/decorators/translate.decorator.js +1 -0
- package/decorators/user.decorator.js +1 -0
- package/decorators/validator.decorators.d.ts +8 -18
- package/decorators/validator.decorators.js +22 -190
- package/filters/constraint-errors.js +1 -0
- package/helpers/common.helper.d.ts +13 -0
- package/helpers/common.helper.js +13 -0
- package/http-client/config/http-client.config.d.ts +15 -0
- package/http-client/config/http-client.config.js +25 -9
- package/http-client/decorators/http-client.decorators.d.ts +63 -0
- package/http-client/decorators/http-client.decorators.js +71 -3
- package/http-client/entities/http-log.entity.d.ts +229 -0
- package/http-client/entities/http-log.entity.js +6 -1
- package/http-client/errors/http-client.errors.d.ts +57 -0
- package/http-client/errors/http-client.errors.js +58 -0
- package/http-client/examples/advanced-usage.example.d.ts +41 -0
- package/http-client/examples/advanced-usage.example.js +68 -24
- package/http-client/examples/auth-with-waiting-lock.example.d.ts +31 -0
- package/http-client/examples/auth-with-waiting-lock.example.js +52 -5
- package/http-client/examples/basic-usage.example.d.ts +60 -0
- package/http-client/examples/basic-usage.example.js +60 -0
- package/http-client/examples/multi-api-configuration.example.d.ts +60 -0
- package/http-client/examples/multi-api-configuration.example.js +76 -5
- package/http-client/http-client.module.d.ts +13 -0
- package/http-client/http-client.module.js +19 -0
- package/http-client/index.js +8 -0
- package/http-client/interfaces/api-client-config.interface.d.ts +125 -0
- package/http-client/interfaces/api-client-config.interface.js +3 -0
- package/http-client/interfaces/http-client-config.interface.d.ts +60 -0
- package/http-client/services/api-client-registry.service.d.ts +57 -0
- package/http-client/services/api-client-registry.service.js +84 -1
- package/http-client/services/cache.service.d.ts +52 -0
- package/http-client/services/cache.service.js +72 -3
- package/http-client/services/circuit-breaker.service.d.ts +46 -0
- package/http-client/services/circuit-breaker.service.js +52 -0
- package/http-client/services/http-client.service.d.ts +67 -0
- package/http-client/services/http-client.service.js +105 -4
- package/http-client/services/http-log-query.service.d.ts +83 -0
- package/http-client/services/http-log-query.service.js +122 -1
- package/http-client/services/http-replay.service.d.ts +101 -0
- package/http-client/services/http-replay.service.js +86 -0
- package/http-client/services/log-cleanup.service.d.ts +63 -0
- package/http-client/services/log-cleanup.service.js +54 -2
- package/http-client/services/logging.service.d.ts +40 -0
- package/http-client/services/logging.service.js +53 -0
- package/http-client/utils/call-stack-extractor.util.d.ts +37 -0
- package/http-client/utils/call-stack-extractor.util.js +48 -0
- package/http-client/utils/context-extractor.util.d.ts +49 -0
- package/http-client/utils/context-extractor.util.js +52 -0
- package/http-client/utils/curl-generator.util.d.ts +21 -0
- package/http-client/utils/curl-generator.util.js +44 -3
- package/http-client/utils/request-id.util.d.ts +18 -0
- package/http-client/utils/request-id.util.js +20 -0
- package/http-client/utils/retry-recorder.util.d.ts +42 -0
- package/http-client/utils/retry-recorder.util.js +44 -0
- package/index.js +8 -0
- package/interceptors/translation-interceptor.service.js +5 -0
- package/package.json +1 -1
- package/providers/context.provider.js +2 -0
- package/providers/generator.provider.d.ts +4 -0
- package/providers/generator.provider.js +4 -0
- package/redis-lock/examples/lock-strategy.examples.d.ts +89 -0
- package/redis-lock/examples/lock-strategy.examples.js +130 -15
- package/redis-lock/index.js +3 -0
- package/redis-lock/redis-lock.decorator.d.ts +101 -0
- package/redis-lock/redis-lock.decorator.js +120 -0
- package/redis-lock/redis-lock.module.d.ts +60 -0
- package/redis-lock/redis-lock.module.js +46 -0
- package/redis-lock/redis-lock.service.d.ts +251 -0
- package/redis-lock/redis-lock.service.js +219 -3
- package/setup/bootstrap.setup.js +20 -0
- package/setup/mode.setup.d.ts +44 -0
- package/setup/mode.setup.js +44 -0
- package/setup/schedule.decorator.d.ts +226 -0
- package/setup/schedule.decorator.js +214 -1
- package/setup/worker.decorator.d.ts +86 -0
- package/setup/worker.decorator.js +88 -0
- package/shared/serviceRegistryModule.js +5 -1
- package/shared/services/api-config.service.d.ts +3 -0
- package/shared/services/api-config.service.js +20 -9
- package/validator-json/decorators.d.ts +17 -0
- package/validator-json/decorators.js +17 -2
- package/validator-json/default.d.ts +6 -0
- package/validator-json/default.js +30 -2
- package/validator-json/defaultConverters.js +1 -0
- package/validator-json/options.d.ts +23 -0
- package/validators/common-validators.d.ts +143 -0
- package/validators/common-validators.js +249 -0
- package/validators/custom-validate.examples.d.ts +23 -0
- package/validators/custom-validate.examples.js +78 -6
- package/validators/custom-validate.validator.d.ts +107 -0
- package/validators/custom-validate.validator.js +84 -0
- package/validators/index.d.ts +1 -0
- package/validators/index.js +1 -0
- package/validators/is-exists.validator.d.ts +11 -0
- package/validators/is-exists.validator.js +22 -0
- package/validators/is-unique.validator.d.ts +11 -0
- package/validators/is-unique.validator.js +31 -3
- package/validators/skip-empty.validator.d.ts +5 -0
- package/validators/skip-empty.validator.js +5 -0
- package/vault/interfaces/vault-options.interface.d.ts +9 -0
- package/vault/vault-config.loader.d.ts +30 -0
- package/vault/vault-config.loader.js +48 -1
- package/vault/vault-config.service.d.ts +53 -0
- package/vault/vault-config.service.js +57 -0
- package/vault/vault.module.d.ts +4 -0
- package/vault/vault.module.js +4 -0
- package/decorators/examples/validation-decorators.example.d.ts +0 -69
- package/decorators/examples/validation-decorators.example.js +0 -331
|
@@ -5,6 +5,7 @@ require("reflect-metadata");
|
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
const cache_options_interface_1 = require("../../cache/interfaces/cache-options.interface");
|
|
7
7
|
const call_stack_extractor_util_1 = require("../utils/call-stack-extractor.util");
|
|
8
|
+
// 装饰器元数据键
|
|
8
9
|
exports.HTTP_CLIENT_OPTIONS_KEY = 'http_client_options';
|
|
9
10
|
exports.RETRY_OPTIONS_KEY = 'http_retry_options';
|
|
10
11
|
exports.CIRCUIT_BREAKER_OPTIONS_KEY = 'http_circuit_breaker_options';
|
|
@@ -13,12 +14,20 @@ exports.LOGGING_OPTIONS_KEY = 'http_logging_options';
|
|
|
13
14
|
exports.TIMEOUT_OPTIONS_KEY = 'http_timeout_options';
|
|
14
15
|
exports.PROXY_OPTIONS_KEY = 'http_proxy_options';
|
|
15
16
|
exports.CALL_INFO_KEY = 'http_call_info';
|
|
17
|
+
/**
|
|
18
|
+
* HTTP客户端装饰器
|
|
19
|
+
* 类似Spring Boot的@RestClient注解
|
|
20
|
+
*/
|
|
16
21
|
const HttpClient = (options = {}) => {
|
|
17
22
|
return (target) => {
|
|
18
23
|
(0, common_1.SetMetadata)(exports.HTTP_CLIENT_OPTIONS_KEY, options)(target);
|
|
19
24
|
};
|
|
20
25
|
};
|
|
21
26
|
exports.HttpClient = HttpClient;
|
|
27
|
+
/**
|
|
28
|
+
* 重试装饰器
|
|
29
|
+
* 基于axios-retry库
|
|
30
|
+
*/
|
|
22
31
|
const HttpRetry = (options = {}) => {
|
|
23
32
|
return (target, propertyKey, descriptor) => {
|
|
24
33
|
const retryOptions = {
|
|
@@ -27,10 +36,11 @@ const HttpRetry = (options = {}) => {
|
|
|
27
36
|
retryDelay: options.retryDelay || ((retryCount) => Math.pow(2, retryCount) * 1000),
|
|
28
37
|
retryCondition: options.retryCondition ||
|
|
29
38
|
((error) => {
|
|
39
|
+
// 默认重试条件:网络错误、超时、5xx错误、429错误
|
|
30
40
|
if (!error.response)
|
|
31
|
-
return true;
|
|
41
|
+
return true; // 网络错误
|
|
32
42
|
const status = error.response.status;
|
|
33
|
-
return status >= 500 || status === 429;
|
|
43
|
+
return status >= 500 || status === 429; // 5xx错误或429限流
|
|
34
44
|
}),
|
|
35
45
|
shouldResetTimeout: options.shouldResetTimeout !== false,
|
|
36
46
|
onRetry: options.onRetry,
|
|
@@ -40,6 +50,10 @@ const HttpRetry = (options = {}) => {
|
|
|
40
50
|
};
|
|
41
51
|
};
|
|
42
52
|
exports.HttpRetry = HttpRetry;
|
|
53
|
+
/**
|
|
54
|
+
* 熔断器装饰器
|
|
55
|
+
* 类似Spring Cloud CircuitBreaker的@CircuitBreaker注解
|
|
56
|
+
*/
|
|
43
57
|
const HttpCircuitBreaker = (options = {}) => {
|
|
44
58
|
return (target, propertyKey, descriptor) => {
|
|
45
59
|
const circuitBreakerOptions = {
|
|
@@ -55,12 +69,16 @@ const HttpCircuitBreaker = (options = {}) => {
|
|
|
55
69
|
};
|
|
56
70
|
};
|
|
57
71
|
exports.HttpCircuitBreaker = HttpCircuitBreaker;
|
|
72
|
+
/**
|
|
73
|
+
* HTTP缓存装饰器
|
|
74
|
+
* 集成现有的三层缓存架构
|
|
75
|
+
*/
|
|
58
76
|
const HttpCacheable = (options = {}) => {
|
|
59
77
|
return (target, propertyKey, descriptor) => {
|
|
60
78
|
var _a;
|
|
61
79
|
const cacheOptions = {
|
|
62
80
|
enabled: true,
|
|
63
|
-
defaultTtl: options.ttl || 300000,
|
|
81
|
+
defaultTtl: options.ttl || 300000, // 5分钟默认
|
|
64
82
|
keyGenerator: typeof options.key === 'function'
|
|
65
83
|
? (config) => options.key(config.url, config.method, config.data, config.params)
|
|
66
84
|
: options.key
|
|
@@ -85,20 +103,24 @@ const HttpCacheable = (options = {}) => {
|
|
|
85
103
|
cacheableMethods: ['get'],
|
|
86
104
|
cacheableStatusCodes: [200, 201, 202, 204, 301, 302, 304],
|
|
87
105
|
};
|
|
106
|
+
// 处理unless条件
|
|
88
107
|
if (options.unless) {
|
|
89
108
|
const originalMethod = descriptor.value;
|
|
90
109
|
descriptor.value = function (...args) {
|
|
91
110
|
const result = originalMethod.apply(this, args);
|
|
92
111
|
if (typeof options.unless === 'string') {
|
|
112
|
+
// 如果是字符串,作为表达式求值
|
|
93
113
|
if (evalInContext(options.unless, { result, args })) {
|
|
94
114
|
return result;
|
|
95
115
|
}
|
|
96
116
|
}
|
|
97
117
|
else if (typeof options.unless === 'function') {
|
|
118
|
+
// 如果是函数,直接调用
|
|
98
119
|
if (options.unless(result, args)) {
|
|
99
120
|
return result;
|
|
100
121
|
}
|
|
101
122
|
}
|
|
123
|
+
// 正常缓存
|
|
102
124
|
(0, common_1.SetMetadata)(`${exports.CACHE_OPTIONS_KEY}_${propertyKey}`, cacheOptions)(originalMethod);
|
|
103
125
|
return result;
|
|
104
126
|
};
|
|
@@ -110,6 +132,10 @@ const HttpCacheable = (options = {}) => {
|
|
|
110
132
|
};
|
|
111
133
|
};
|
|
112
134
|
exports.HttpCacheable = HttpCacheable;
|
|
135
|
+
/**
|
|
136
|
+
* 请求日志装饰器
|
|
137
|
+
* 类似Spring Boot的@LogRequest注解
|
|
138
|
+
*/
|
|
113
139
|
const HttpLogRequest = (options = {}) => {
|
|
114
140
|
return (target, propertyKey, descriptor) => {
|
|
115
141
|
var _a, _b, _c;
|
|
@@ -128,6 +154,7 @@ const HttpLogRequest = (options = {}) => {
|
|
|
128
154
|
databaseLog: (_c = options.databaseLog) !== null && _c !== void 0 ? _c : false,
|
|
129
155
|
logLevel: options.logLevel || 'info',
|
|
130
156
|
};
|
|
157
|
+
// 提取调用信息
|
|
131
158
|
const decoratorInfo = call_stack_extractor_util_1.CallStackExtractor.extractFromDecorator(target, propertyKey);
|
|
132
159
|
const callInfo = {
|
|
133
160
|
serviceClass: options.serviceClass || decoratorInfo.serviceClass,
|
|
@@ -140,6 +167,10 @@ const HttpLogRequest = (options = {}) => {
|
|
|
140
167
|
};
|
|
141
168
|
};
|
|
142
169
|
exports.HttpLogRequest = HttpLogRequest;
|
|
170
|
+
/**
|
|
171
|
+
* 超时装饰器
|
|
172
|
+
* 类似Spring的@Timeout注解
|
|
173
|
+
*/
|
|
143
174
|
const HttpTimeout = (timeoutMs) => {
|
|
144
175
|
return (target, propertyKey, descriptor) => {
|
|
145
176
|
(0, common_1.SetMetadata)(`${exports.TIMEOUT_OPTIONS_KEY}_${propertyKey}`, timeoutMs)(descriptor.value);
|
|
@@ -147,6 +178,9 @@ const HttpTimeout = (timeoutMs) => {
|
|
|
147
178
|
};
|
|
148
179
|
};
|
|
149
180
|
exports.HttpTimeout = HttpTimeout;
|
|
181
|
+
/**
|
|
182
|
+
* 代理装饰器
|
|
183
|
+
*/
|
|
150
184
|
const HttpUseProxy = (options) => {
|
|
151
185
|
return (target, propertyKey, descriptor) => {
|
|
152
186
|
(0, common_1.SetMetadata)(`${exports.PROXY_OPTIONS_KEY}_${propertyKey}`, options)(descriptor.value);
|
|
@@ -154,31 +188,61 @@ const HttpUseProxy = (options) => {
|
|
|
154
188
|
};
|
|
155
189
|
};
|
|
156
190
|
exports.HttpUseProxy = HttpUseProxy;
|
|
191
|
+
/**
|
|
192
|
+
* 装饰器工具函数
|
|
193
|
+
*/
|
|
157
194
|
class HttpDecoratorUtils {
|
|
195
|
+
/**
|
|
196
|
+
* 获取方法上的重试配置
|
|
197
|
+
*/
|
|
158
198
|
static getRetryOptions(target, propertyKey) {
|
|
159
199
|
return Reflect.getMetadata(`${exports.RETRY_OPTIONS_KEY}_${propertyKey}`, target[propertyKey]);
|
|
160
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* 获取方法上的熔断器配置
|
|
203
|
+
*/
|
|
161
204
|
static getCircuitBreakerOptions(target, propertyKey) {
|
|
162
205
|
return Reflect.getMetadata(`${exports.CIRCUIT_BREAKER_OPTIONS_KEY}_${propertyKey}`, target[propertyKey]);
|
|
163
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* 获取方法上的缓存配置
|
|
209
|
+
*/
|
|
164
210
|
static getCacheOptions(target, propertyKey) {
|
|
165
211
|
return Reflect.getMetadata(`${exports.CACHE_OPTIONS_KEY}_${propertyKey}`, target[propertyKey]);
|
|
166
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* 获取方法上的日志配置
|
|
215
|
+
*/
|
|
167
216
|
static getLoggingOptions(target, propertyKey) {
|
|
168
217
|
return Reflect.getMetadata(`${exports.LOGGING_OPTIONS_KEY}_${propertyKey}`, target[propertyKey]);
|
|
169
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* 获取方法上的超时配置
|
|
221
|
+
*/
|
|
170
222
|
static getTimeoutOptions(target, propertyKey) {
|
|
171
223
|
return Reflect.getMetadata(`${exports.TIMEOUT_OPTIONS_KEY}_${propertyKey}`, target[propertyKey]);
|
|
172
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* 获取方法上的代理配置
|
|
227
|
+
*/
|
|
173
228
|
static getProxyOptions(target, propertyKey) {
|
|
174
229
|
return Reflect.getMetadata(`${exports.PROXY_OPTIONS_KEY}_${propertyKey}`, target[propertyKey]);
|
|
175
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* 获取类上的HTTP客户端配置
|
|
233
|
+
*/
|
|
176
234
|
static getHttpClientOptions(target) {
|
|
177
235
|
return Reflect.getMetadata(exports.HTTP_CLIENT_OPTIONS_KEY, target) || {};
|
|
178
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* 获取方法上的调用信息配置
|
|
239
|
+
*/
|
|
179
240
|
static getCallInfoOptions(target, propertyKey) {
|
|
180
241
|
return Reflect.getMetadata(`${exports.CALL_INFO_KEY}_${propertyKey}`, target[propertyKey]);
|
|
181
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* 获取所有装饰器配置
|
|
245
|
+
*/
|
|
182
246
|
static getAllDecoratorConfigs(target, propertyKey) {
|
|
183
247
|
return {
|
|
184
248
|
retry: this.getRetryOptions(target, propertyKey),
|
|
@@ -193,8 +257,12 @@ class HttpDecoratorUtils {
|
|
|
193
257
|
}
|
|
194
258
|
}
|
|
195
259
|
exports.HttpDecoratorUtils = HttpDecoratorUtils;
|
|
260
|
+
/**
|
|
261
|
+
* 在上下文中执行表达式
|
|
262
|
+
*/
|
|
196
263
|
function evalInContext(expression, context) {
|
|
197
264
|
try {
|
|
265
|
+
// 创建一个安全的执行环境
|
|
198
266
|
const func = new Function(...Object.keys(context), `return ${expression}`);
|
|
199
267
|
return func(...Object.values(context));
|
|
200
268
|
}
|
|
@@ -1,95 +1,324 @@
|
|
|
1
1
|
import { AbstractUuidPrimaryEntity } from '../../common';
|
|
2
|
+
/**
|
|
3
|
+
* HTTP请求日志实体
|
|
4
|
+
* 用于TypeORM数据库记录
|
|
5
|
+
*/
|
|
2
6
|
export declare class HttpLogEntity extends AbstractUuidPrimaryEntity {
|
|
7
|
+
/**
|
|
8
|
+
* 请求ID(从ContextProvider获取)
|
|
9
|
+
*/
|
|
3
10
|
requestId?: string;
|
|
11
|
+
/**
|
|
12
|
+
* 用户ID(从ContextProvider获取)
|
|
13
|
+
*/
|
|
4
14
|
userId?: string;
|
|
15
|
+
/**
|
|
16
|
+
* HTTP方法
|
|
17
|
+
*/
|
|
5
18
|
method: string;
|
|
19
|
+
/**
|
|
20
|
+
* 请求URL
|
|
21
|
+
*/
|
|
6
22
|
url: string;
|
|
23
|
+
/**
|
|
24
|
+
* 请求头信息(JSON格式)
|
|
25
|
+
*/
|
|
7
26
|
headers?: Record<string, string>;
|
|
27
|
+
/**
|
|
28
|
+
* 请求体内容
|
|
29
|
+
*/
|
|
8
30
|
body?: string;
|
|
31
|
+
/**
|
|
32
|
+
* 查询参数(JSON格式)
|
|
33
|
+
*/
|
|
9
34
|
params?: Record<string, any>;
|
|
35
|
+
/**
|
|
36
|
+
* HTTP状态码
|
|
37
|
+
*/
|
|
10
38
|
statusCode?: number;
|
|
39
|
+
/**
|
|
40
|
+
* 响应时间(毫秒)
|
|
41
|
+
*/
|
|
11
42
|
responseTime: number;
|
|
43
|
+
/**
|
|
44
|
+
* 尝试次数
|
|
45
|
+
*/
|
|
12
46
|
attemptCount: number;
|
|
47
|
+
/**
|
|
48
|
+
* 是否成功
|
|
49
|
+
*/
|
|
13
50
|
success: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* 错误信息
|
|
53
|
+
*/
|
|
14
54
|
errorMessage?: string;
|
|
55
|
+
/**
|
|
56
|
+
* 错误堆栈
|
|
57
|
+
*/
|
|
15
58
|
errorStack?: string;
|
|
59
|
+
/**
|
|
60
|
+
* 错误代码
|
|
61
|
+
*/
|
|
16
62
|
errorCode?: string;
|
|
63
|
+
/**
|
|
64
|
+
* 响应头信息(JSON格式)
|
|
65
|
+
*/
|
|
17
66
|
responseHeaders?: Record<string, string>;
|
|
67
|
+
/**
|
|
68
|
+
* 响应体内容
|
|
69
|
+
*/
|
|
18
70
|
responseBody?: string;
|
|
71
|
+
/**
|
|
72
|
+
* 响应大小(字节)
|
|
73
|
+
*/
|
|
19
74
|
responseSize?: number;
|
|
75
|
+
/**
|
|
76
|
+
* 请求大小(字节)
|
|
77
|
+
*/
|
|
20
78
|
requestSize?: number;
|
|
79
|
+
/**
|
|
80
|
+
* 服务名称(用于微服务环境)
|
|
81
|
+
*/
|
|
21
82
|
serviceName?: string;
|
|
83
|
+
/**
|
|
84
|
+
* 自定义操作名称(用于业务标识)
|
|
85
|
+
*/
|
|
22
86
|
operationName?: string;
|
|
87
|
+
/**
|
|
88
|
+
* 客户端IP地址
|
|
89
|
+
*/
|
|
23
90
|
clientIp?: string;
|
|
91
|
+
/**
|
|
92
|
+
* 请求来源
|
|
93
|
+
*/
|
|
24
94
|
source?: string;
|
|
95
|
+
/**
|
|
96
|
+
* 请求标签(用于分类)
|
|
97
|
+
*/
|
|
25
98
|
tags?: string[];
|
|
99
|
+
/**
|
|
100
|
+
* 请求元数据(JSON格式)
|
|
101
|
+
*/
|
|
26
102
|
metadata?: Record<string, any>;
|
|
103
|
+
/**
|
|
104
|
+
* 重试记录(JSON格式)
|
|
105
|
+
*/
|
|
27
106
|
retryRecords?: RetryRecord[];
|
|
107
|
+
/**
|
|
108
|
+
* 缓存命中状态
|
|
109
|
+
*/
|
|
28
110
|
cacheHit?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* 熔断器状态
|
|
113
|
+
*/
|
|
29
114
|
circuitBreakerState?: string;
|
|
30
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* 重试记录接口
|
|
118
|
+
*/
|
|
31
119
|
export interface RetryRecord {
|
|
120
|
+
/**
|
|
121
|
+
* 重试次数
|
|
122
|
+
*/
|
|
32
123
|
attempt: number;
|
|
124
|
+
/**
|
|
125
|
+
* 重试时间
|
|
126
|
+
*/
|
|
33
127
|
timestamp: Date;
|
|
128
|
+
/**
|
|
129
|
+
* 重试原因
|
|
130
|
+
*/
|
|
34
131
|
reason: string;
|
|
132
|
+
/**
|
|
133
|
+
* 重试延迟(毫秒)
|
|
134
|
+
*/
|
|
35
135
|
delay: number;
|
|
136
|
+
/**
|
|
137
|
+
* 错误信息
|
|
138
|
+
*/
|
|
36
139
|
error?: {
|
|
37
140
|
message: string;
|
|
38
141
|
code?: string;
|
|
39
142
|
statusCode?: number;
|
|
40
143
|
};
|
|
144
|
+
/**
|
|
145
|
+
* 请求配置(简化版)
|
|
146
|
+
*/
|
|
41
147
|
requestConfig?: {
|
|
42
148
|
method: string;
|
|
43
149
|
url: string;
|
|
44
150
|
headers: Record<string, string>;
|
|
45
151
|
};
|
|
46
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* HTTP日志查询选项
|
|
155
|
+
*/
|
|
47
156
|
export interface HttpLogQueryOptions {
|
|
157
|
+
/**
|
|
158
|
+
* 请求ID
|
|
159
|
+
*/
|
|
48
160
|
requestId?: string;
|
|
161
|
+
/**
|
|
162
|
+
* 用户ID
|
|
163
|
+
*/
|
|
49
164
|
userId?: string;
|
|
165
|
+
/**
|
|
166
|
+
* HTTP方法
|
|
167
|
+
*/
|
|
50
168
|
method?: string | string[];
|
|
169
|
+
/**
|
|
170
|
+
* URL(支持模糊搜索)
|
|
171
|
+
*/
|
|
51
172
|
url?: string;
|
|
173
|
+
/**
|
|
174
|
+
* 状态码
|
|
175
|
+
*/
|
|
52
176
|
statusCode?: number | number[];
|
|
177
|
+
/**
|
|
178
|
+
* 是否成功
|
|
179
|
+
*/
|
|
53
180
|
success?: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* 服务名称
|
|
183
|
+
*/
|
|
54
184
|
serviceName?: string;
|
|
185
|
+
/**
|
|
186
|
+
* 操作名称
|
|
187
|
+
*/
|
|
55
188
|
operationName?: string;
|
|
189
|
+
/**
|
|
190
|
+
* 客户端IP
|
|
191
|
+
*/
|
|
56
192
|
clientIp?: string;
|
|
193
|
+
/**
|
|
194
|
+
* 请求来源
|
|
195
|
+
*/
|
|
57
196
|
source?: string;
|
|
197
|
+
/**
|
|
198
|
+
* 标签
|
|
199
|
+
*/
|
|
58
200
|
tags?: string[];
|
|
201
|
+
/**
|
|
202
|
+
* 错误代码
|
|
203
|
+
*/
|
|
59
204
|
errorCode?: string;
|
|
205
|
+
/**
|
|
206
|
+
* 最小响应时间
|
|
207
|
+
*/
|
|
60
208
|
minResponseTime?: number;
|
|
209
|
+
/**
|
|
210
|
+
* 最大响应时间
|
|
211
|
+
*/
|
|
61
212
|
maxResponseTime?: number;
|
|
213
|
+
/**
|
|
214
|
+
* 开始时间
|
|
215
|
+
*/
|
|
62
216
|
startDate?: Date;
|
|
217
|
+
/**
|
|
218
|
+
* 结束时间
|
|
219
|
+
*/
|
|
63
220
|
endDate?: Date;
|
|
221
|
+
/**
|
|
222
|
+
* 搜索关键词
|
|
223
|
+
*/
|
|
64
224
|
keyword?: string;
|
|
225
|
+
/**
|
|
226
|
+
* 分页参数
|
|
227
|
+
*/
|
|
65
228
|
page?: number;
|
|
229
|
+
/**
|
|
230
|
+
* 每页数量
|
|
231
|
+
*/
|
|
66
232
|
limit?: number;
|
|
233
|
+
/**
|
|
234
|
+
* 排序字段
|
|
235
|
+
*/
|
|
67
236
|
sortBy?: 'createdAt' | 'responseTime' | 'statusCode' | 'url';
|
|
237
|
+
/**
|
|
238
|
+
* 排序方向
|
|
239
|
+
*/
|
|
68
240
|
sortOrder?: 'ASC' | 'DESC';
|
|
241
|
+
/**
|
|
242
|
+
* 是否包含详细数据
|
|
243
|
+
*/
|
|
69
244
|
includeDetails?: boolean;
|
|
70
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* HTTP日志统计结果
|
|
248
|
+
*/
|
|
71
249
|
export interface HttpLogStats {
|
|
250
|
+
/**
|
|
251
|
+
* 总请求数
|
|
252
|
+
*/
|
|
72
253
|
totalRequests: number;
|
|
254
|
+
/**
|
|
255
|
+
* 成功请求数
|
|
256
|
+
*/
|
|
73
257
|
successfulRequests: number;
|
|
258
|
+
/**
|
|
259
|
+
* 失败请求数
|
|
260
|
+
*/
|
|
74
261
|
failedRequests: number;
|
|
262
|
+
/**
|
|
263
|
+
* 成功率
|
|
264
|
+
*/
|
|
75
265
|
successRate: number;
|
|
266
|
+
/**
|
|
267
|
+
* 平均响应时间
|
|
268
|
+
*/
|
|
76
269
|
averageResponseTime: number;
|
|
270
|
+
/**
|
|
271
|
+
* 最小响应时间
|
|
272
|
+
*/
|
|
77
273
|
minResponseTime: number;
|
|
274
|
+
/**
|
|
275
|
+
* 最大响应时间
|
|
276
|
+
*/
|
|
78
277
|
maxResponseTime: number;
|
|
278
|
+
/**
|
|
279
|
+
* P50响应时间
|
|
280
|
+
*/
|
|
79
281
|
p50ResponseTime: number;
|
|
282
|
+
/**
|
|
283
|
+
* P95响应时间
|
|
284
|
+
*/
|
|
80
285
|
p95ResponseTime: number;
|
|
286
|
+
/**
|
|
287
|
+
* P99响应时间
|
|
288
|
+
*/
|
|
81
289
|
p99ResponseTime: number;
|
|
290
|
+
/**
|
|
291
|
+
* 按方法统计
|
|
292
|
+
*/
|
|
82
293
|
requestsByMethod: Record<string, number>;
|
|
294
|
+
/**
|
|
295
|
+
* 按状态码统计
|
|
296
|
+
*/
|
|
83
297
|
requestsByStatus: Record<string, number>;
|
|
298
|
+
/**
|
|
299
|
+
* 按服务统计
|
|
300
|
+
*/
|
|
84
301
|
requestsByService: Record<string, number>;
|
|
302
|
+
/**
|
|
303
|
+
* 按来源统计
|
|
304
|
+
*/
|
|
85
305
|
requestsBySource: Record<string, number>;
|
|
306
|
+
/**
|
|
307
|
+
* 错误统计
|
|
308
|
+
*/
|
|
86
309
|
errorsByCode: Record<string, number>;
|
|
310
|
+
/**
|
|
311
|
+
* 重试统计
|
|
312
|
+
*/
|
|
87
313
|
retryStats: {
|
|
88
314
|
totalRetries: number;
|
|
89
315
|
averageRetries: number;
|
|
90
316
|
maxRetries: number;
|
|
91
317
|
retryRate: number;
|
|
92
318
|
};
|
|
319
|
+
/**
|
|
320
|
+
* 缓存统计
|
|
321
|
+
*/
|
|
93
322
|
cacheStats: {
|
|
94
323
|
cacheHits: number;
|
|
95
324
|
cacheMisses: number;
|
|
@@ -12,6 +12,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.HttpLogEntity = void 0;
|
|
13
13
|
const typeorm_1 = require("typeorm");
|
|
14
14
|
const common_1 = require("../../common");
|
|
15
|
+
/**
|
|
16
|
+
* HTTP请求日志实体
|
|
17
|
+
* 用于TypeORM数据库记录
|
|
18
|
+
*/
|
|
15
19
|
let HttpLogEntity = class HttpLogEntity extends common_1.AbstractUuidPrimaryEntity {
|
|
16
20
|
};
|
|
17
21
|
exports.HttpLogEntity = HttpLogEntity;
|
|
@@ -103,7 +107,8 @@ __decorate([
|
|
|
103
107
|
__metadata("design:type", String)
|
|
104
108
|
], HttpLogEntity.prototype, "operationName", void 0);
|
|
105
109
|
__decorate([
|
|
106
|
-
(0, typeorm_1.Column)({ type: 'varchar', length: 45, nullable: true })
|
|
110
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 45, nullable: true }) // 支持IPv6
|
|
111
|
+
,
|
|
107
112
|
__metadata("design:type", String)
|
|
108
113
|
], HttpLogEntity.prototype, "clientIp", void 0);
|
|
109
114
|
__decorate([
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP客户端基础错误类
|
|
3
|
+
*/
|
|
1
4
|
export declare class HttpClientError extends Error {
|
|
2
5
|
readonly code: string;
|
|
3
6
|
readonly statusCode?: number;
|
|
@@ -5,52 +8,106 @@ export declare class HttpClientError extends Error {
|
|
|
5
8
|
readonly config?: any;
|
|
6
9
|
constructor(message: string, code?: string, statusCode?: number, response?: any, config?: any);
|
|
7
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* 网络错误
|
|
13
|
+
*/
|
|
8
14
|
export declare class NetworkError extends HttpClientError {
|
|
9
15
|
constructor(message: string, config?: any);
|
|
10
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* 超时错误
|
|
19
|
+
*/
|
|
11
20
|
export declare class TimeoutError extends HttpClientError {
|
|
12
21
|
constructor(message: string, config?: any);
|
|
13
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* 重试失败错误
|
|
25
|
+
*/
|
|
14
26
|
export declare class RetryExhaustedError extends HttpClientError {
|
|
15
27
|
readonly attempts: number;
|
|
16
28
|
readonly lastError: any;
|
|
17
29
|
constructor(message: string, attempts: number, lastError: any, config?: any);
|
|
18
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* 熔断器开启错误
|
|
33
|
+
*/
|
|
19
34
|
export declare class CircuitBreakerOpenError extends HttpClientError {
|
|
20
35
|
readonly circuitName: string;
|
|
21
36
|
readonly failureCount: number;
|
|
22
37
|
constructor(message: string, circuitName: string, failureCount: number, config?: any);
|
|
23
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* API认证错误
|
|
41
|
+
*/
|
|
24
42
|
export declare class AuthenticationError extends HttpClientError {
|
|
25
43
|
constructor(message: string, statusCode?: number, response?: any, config?: any);
|
|
26
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* API授权错误
|
|
47
|
+
*/
|
|
27
48
|
export declare class AuthorizationError extends HttpClientError {
|
|
28
49
|
constructor(message: string, statusCode?: number, response?: any, config?: any);
|
|
29
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* 限流错误
|
|
53
|
+
*/
|
|
30
54
|
export declare class RateLimitError extends HttpClientError {
|
|
31
55
|
readonly retryAfter?: number;
|
|
32
56
|
readonly limit?: number;
|
|
33
57
|
readonly remaining?: number;
|
|
34
58
|
constructor(message: string, statusCode?: number, response?: any, config?: any, retryAfter?: number, limit?: number, remaining?: number);
|
|
35
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* 服务器错误
|
|
62
|
+
*/
|
|
36
63
|
export declare class ServerError extends HttpClientError {
|
|
37
64
|
constructor(message: string, statusCode?: number, response?: any, config?: any);
|
|
38
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* 响应格式错误
|
|
68
|
+
*/
|
|
39
69
|
export declare class ResponseFormatError extends HttpClientError {
|
|
40
70
|
readonly responseData: any;
|
|
41
71
|
constructor(message: string, responseData: any, config?: any);
|
|
42
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* API客户端配置错误
|
|
75
|
+
*/
|
|
43
76
|
export declare class ApiClientConfigError extends HttpClientError {
|
|
44
77
|
constructor(message: string, config?: any);
|
|
45
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* 缓存错误
|
|
81
|
+
*/
|
|
46
82
|
export declare class CacheError extends HttpClientError {
|
|
47
83
|
constructor(message: string, config?: any);
|
|
48
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* 错误工厂函数
|
|
87
|
+
*/
|
|
49
88
|
export declare class ErrorFactory {
|
|
89
|
+
/**
|
|
90
|
+
* 根据axios错误创建对应的HTTP客户端错误
|
|
91
|
+
*/
|
|
50
92
|
static fromAxiosError(error: any): HttpClientError;
|
|
93
|
+
/**
|
|
94
|
+
* 创建重试失败错误
|
|
95
|
+
*/
|
|
51
96
|
static createRetryExhaustedError(attempts: number, lastError: any, config?: any): RetryExhaustedError;
|
|
97
|
+
/**
|
|
98
|
+
* 创建熔断器开启错误
|
|
99
|
+
*/
|
|
52
100
|
static createCircuitBreakerOpenError(circuitName: string, failureCount: number, config?: any): CircuitBreakerOpenError;
|
|
101
|
+
/**
|
|
102
|
+
* 创建响应格式错误
|
|
103
|
+
*/
|
|
53
104
|
static createResponseFormatError(message: string, responseData: any, config?: any): ResponseFormatError;
|
|
105
|
+
/**
|
|
106
|
+
* 创建API客户端配置错误
|
|
107
|
+
*/
|
|
54
108
|
static createApiClientConfigError(message: string, config?: any): ApiClientConfigError;
|
|
109
|
+
/**
|
|
110
|
+
* 创建缓存错误
|
|
111
|
+
*/
|
|
55
112
|
static createCacheError(message: string, config?: any): CacheError;
|
|
56
113
|
}
|