@nest-omni/core 4.1.3-1 → 4.1.3-10
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 -4
- package/common/boilerplate.polyfill.js +24 -100
- 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/i18n/en_US/validation.json +2 -1
- package/i18n/zh_CN/validation.json +2 -1
- 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/comprehensive-lock-cleanup.service.d.ts +94 -0
- package/redis-lock/comprehensive-lock-cleanup.service.js +253 -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.d.ts +2 -0
- package/redis-lock/index.js +8 -1
- package/redis-lock/lock-heartbeat.service.d.ts +78 -0
- package/redis-lock/lock-heartbeat.service.js +222 -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 +66 -0
- package/redis-lock/redis-lock.module.js +175 -70
- package/redis-lock/redis-lock.service.d.ts +260 -0
- package/redis-lock/redis-lock.service.js +244 -4
- 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 +227 -0
- package/setup/schedule.decorator.js +219 -6
- package/setup/worker.decorator.d.ts +86 -0
- package/setup/worker.decorator.js +88 -0
- package/shared/serviceRegistryModule.js +9 -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 +96 -0
- package/validators/custom-validate.examples.js +400 -0
- package/validators/custom-validate.validator.d.ts +134 -0
- package/validators/custom-validate.validator.js +214 -0
- package/validators/index.d.ts +2 -0
- package/validators/index.js +2 -0
- package/validators/is-exists.validator.d.ts +18 -4
- package/validators/is-exists.validator.js +67 -6
- package/validators/is-unique.validator.d.ts +32 -5
- package/validators/is-unique.validator.js +99 -17
- 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
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ErrorFactory = exports.CacheError = exports.ApiClientConfigError = exports.ResponseFormatError = exports.ServerError = exports.RateLimitError = exports.AuthorizationError = exports.AuthenticationError = exports.CircuitBreakerOpenError = exports.RetryExhaustedError = exports.TimeoutError = exports.NetworkError = exports.HttpClientError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* HTTP客户端基础错误类
|
|
6
|
+
*/
|
|
4
7
|
class HttpClientError extends Error {
|
|
5
8
|
constructor(message, code = 'HTTP_CLIENT_ERROR', statusCode, response, config) {
|
|
6
9
|
super(message);
|
|
@@ -13,6 +16,9 @@ class HttpClientError extends Error {
|
|
|
13
16
|
}
|
|
14
17
|
}
|
|
15
18
|
exports.HttpClientError = HttpClientError;
|
|
19
|
+
/**
|
|
20
|
+
* 网络错误
|
|
21
|
+
*/
|
|
16
22
|
class NetworkError extends HttpClientError {
|
|
17
23
|
constructor(message, config) {
|
|
18
24
|
super(message, 'NETWORK_ERROR', undefined, undefined, config);
|
|
@@ -20,6 +26,9 @@ class NetworkError extends HttpClientError {
|
|
|
20
26
|
}
|
|
21
27
|
}
|
|
22
28
|
exports.NetworkError = NetworkError;
|
|
29
|
+
/**
|
|
30
|
+
* 超时错误
|
|
31
|
+
*/
|
|
23
32
|
class TimeoutError extends HttpClientError {
|
|
24
33
|
constructor(message, config) {
|
|
25
34
|
super(message, 'TIMEOUT_ERROR', undefined, undefined, config);
|
|
@@ -27,6 +36,9 @@ class TimeoutError extends HttpClientError {
|
|
|
27
36
|
}
|
|
28
37
|
}
|
|
29
38
|
exports.TimeoutError = TimeoutError;
|
|
39
|
+
/**
|
|
40
|
+
* 重试失败错误
|
|
41
|
+
*/
|
|
30
42
|
class RetryExhaustedError extends HttpClientError {
|
|
31
43
|
constructor(message, attempts, lastError, config) {
|
|
32
44
|
super(message, 'RETRY_EXHAUSTED', undefined, undefined, config);
|
|
@@ -36,6 +48,9 @@ class RetryExhaustedError extends HttpClientError {
|
|
|
36
48
|
}
|
|
37
49
|
}
|
|
38
50
|
exports.RetryExhaustedError = RetryExhaustedError;
|
|
51
|
+
/**
|
|
52
|
+
* 熔断器开启错误
|
|
53
|
+
*/
|
|
39
54
|
class CircuitBreakerOpenError extends HttpClientError {
|
|
40
55
|
constructor(message, circuitName, failureCount, config) {
|
|
41
56
|
super(message, 'CIRCUIT_BREAKER_OPEN', 503, undefined, config);
|
|
@@ -45,6 +60,9 @@ class CircuitBreakerOpenError extends HttpClientError {
|
|
|
45
60
|
}
|
|
46
61
|
}
|
|
47
62
|
exports.CircuitBreakerOpenError = CircuitBreakerOpenError;
|
|
63
|
+
/**
|
|
64
|
+
* API认证错误
|
|
65
|
+
*/
|
|
48
66
|
class AuthenticationError extends HttpClientError {
|
|
49
67
|
constructor(message, statusCode = 401, response, config) {
|
|
50
68
|
super(message, 'AUTHENTICATION_ERROR', statusCode, response, config);
|
|
@@ -52,6 +70,9 @@ class AuthenticationError extends HttpClientError {
|
|
|
52
70
|
}
|
|
53
71
|
}
|
|
54
72
|
exports.AuthenticationError = AuthenticationError;
|
|
73
|
+
/**
|
|
74
|
+
* API授权错误
|
|
75
|
+
*/
|
|
55
76
|
class AuthorizationError extends HttpClientError {
|
|
56
77
|
constructor(message, statusCode = 403, response, config) {
|
|
57
78
|
super(message, 'AUTHORIZATION_ERROR', statusCode, response, config);
|
|
@@ -59,6 +80,9 @@ class AuthorizationError extends HttpClientError {
|
|
|
59
80
|
}
|
|
60
81
|
}
|
|
61
82
|
exports.AuthorizationError = AuthorizationError;
|
|
83
|
+
/**
|
|
84
|
+
* 限流错误
|
|
85
|
+
*/
|
|
62
86
|
class RateLimitError extends HttpClientError {
|
|
63
87
|
constructor(message, statusCode = 429, response, config, retryAfter, limit, remaining) {
|
|
64
88
|
super(message, 'RATE_LIMIT_ERROR', statusCode, response, config);
|
|
@@ -69,6 +93,9 @@ class RateLimitError extends HttpClientError {
|
|
|
69
93
|
}
|
|
70
94
|
}
|
|
71
95
|
exports.RateLimitError = RateLimitError;
|
|
96
|
+
/**
|
|
97
|
+
* 服务器错误
|
|
98
|
+
*/
|
|
72
99
|
class ServerError extends HttpClientError {
|
|
73
100
|
constructor(message, statusCode = 500, response, config) {
|
|
74
101
|
super(message, 'SERVER_ERROR', statusCode, response, config);
|
|
@@ -76,6 +103,9 @@ class ServerError extends HttpClientError {
|
|
|
76
103
|
}
|
|
77
104
|
}
|
|
78
105
|
exports.ServerError = ServerError;
|
|
106
|
+
/**
|
|
107
|
+
* 响应格式错误
|
|
108
|
+
*/
|
|
79
109
|
class ResponseFormatError extends HttpClientError {
|
|
80
110
|
constructor(message, responseData, config) {
|
|
81
111
|
super(message, 'RESPONSE_FORMAT_ERROR', undefined, undefined, config);
|
|
@@ -84,6 +114,9 @@ class ResponseFormatError extends HttpClientError {
|
|
|
84
114
|
}
|
|
85
115
|
}
|
|
86
116
|
exports.ResponseFormatError = ResponseFormatError;
|
|
117
|
+
/**
|
|
118
|
+
* API客户端配置错误
|
|
119
|
+
*/
|
|
87
120
|
class ApiClientConfigError extends HttpClientError {
|
|
88
121
|
constructor(message, config) {
|
|
89
122
|
super(message, 'API_CLIENT_CONFIG_ERROR', 500, undefined, config);
|
|
@@ -91,6 +124,9 @@ class ApiClientConfigError extends HttpClientError {
|
|
|
91
124
|
}
|
|
92
125
|
}
|
|
93
126
|
exports.ApiClientConfigError = ApiClientConfigError;
|
|
127
|
+
/**
|
|
128
|
+
* 缓存错误
|
|
129
|
+
*/
|
|
94
130
|
class CacheError extends HttpClientError {
|
|
95
131
|
constructor(message, config) {
|
|
96
132
|
super(message, 'CACHE_ERROR', undefined, undefined, config);
|
|
@@ -98,11 +134,18 @@ class CacheError extends HttpClientError {
|
|
|
98
134
|
}
|
|
99
135
|
}
|
|
100
136
|
exports.CacheError = CacheError;
|
|
137
|
+
/**
|
|
138
|
+
* 错误工厂函数
|
|
139
|
+
*/
|
|
101
140
|
class ErrorFactory {
|
|
141
|
+
/**
|
|
142
|
+
* 根据axios错误创建对应的HTTP客户端错误
|
|
143
|
+
*/
|
|
102
144
|
static fromAxiosError(error) {
|
|
103
145
|
const config = error.config;
|
|
104
146
|
const response = error.response;
|
|
105
147
|
const message = error.message || 'Unknown error';
|
|
148
|
+
// 网络错误
|
|
106
149
|
if (!error.response) {
|
|
107
150
|
if (error.code === 'ECONNABORTED') {
|
|
108
151
|
return new TimeoutError(`Request timeout: ${message}`, config);
|
|
@@ -130,18 +173,33 @@ class ErrorFactory {
|
|
|
130
173
|
return new HttpClientError((responseData === null || responseData === void 0 ? void 0 : responseData.message) || `HTTP error (${statusCode})`, 'HTTP_ERROR', statusCode, response, config);
|
|
131
174
|
}
|
|
132
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* 创建重试失败错误
|
|
178
|
+
*/
|
|
133
179
|
static createRetryExhaustedError(attempts, lastError, config) {
|
|
134
180
|
return new RetryExhaustedError(`Retry failed after ${attempts} attempts. Last error: ${lastError.message}`, attempts, lastError, config);
|
|
135
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* 创建熔断器开启错误
|
|
184
|
+
*/
|
|
136
185
|
static createCircuitBreakerOpenError(circuitName, failureCount, config) {
|
|
137
186
|
return new CircuitBreakerOpenError(`Circuit breaker '${circuitName}' is open after ${failureCount} failures`, circuitName, failureCount, config);
|
|
138
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* 创建响应格式错误
|
|
190
|
+
*/
|
|
139
191
|
static createResponseFormatError(message, responseData, config) {
|
|
140
192
|
return new ResponseFormatError(message, responseData, config);
|
|
141
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* 创建API客户端配置错误
|
|
196
|
+
*/
|
|
142
197
|
static createApiClientConfigError(message, config) {
|
|
143
198
|
return new ApiClientConfigError(message, config);
|
|
144
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* 创建缓存错误
|
|
202
|
+
*/
|
|
145
203
|
static createCacheError(message, config) {
|
|
146
204
|
return new CacheError(message, config);
|
|
147
205
|
}
|
|
@@ -1,23 +1,64 @@
|
|
|
1
1
|
import { HttpClientService } from '../services/http-client.service';
|
|
2
|
+
/**
|
|
3
|
+
* 高级使用示例 - GitHub API客户端
|
|
4
|
+
* 集成现有的三层缓存架构
|
|
5
|
+
*/
|
|
2
6
|
export declare class GitHubHttpService {
|
|
3
7
|
private httpClient;
|
|
4
8
|
constructor(httpClient: HttpClientService);
|
|
9
|
+
/**
|
|
10
|
+
* 获取用户信息 - 带重试、熔断器、缓存和日志
|
|
11
|
+
*/
|
|
5
12
|
getUser(username: string): Promise<any>;
|
|
13
|
+
/**
|
|
14
|
+
* 搜索仓库 - 带重试和缓存
|
|
15
|
+
*/
|
|
6
16
|
searchRepositories(query: string, sort?: string, order?: string): Promise<any>;
|
|
17
|
+
/**
|
|
18
|
+
* 获取用户仓库 - 使用代理
|
|
19
|
+
*/
|
|
7
20
|
getUserRepositories(username: string): Promise<any>;
|
|
21
|
+
/**
|
|
22
|
+
* 创建仓库 - 带详细日志
|
|
23
|
+
*/
|
|
8
24
|
createRepository(repoData: any, token: string): Promise<any>;
|
|
25
|
+
/**
|
|
26
|
+
* 获取仓库贡献者 - 熔断器保护
|
|
27
|
+
*/
|
|
9
28
|
getRepositoryContributors(owner: string, repo: string): Promise<any>;
|
|
29
|
+
/**
|
|
30
|
+
* 批量获取用户信息 - 并行请求
|
|
31
|
+
*/
|
|
10
32
|
getMultipleUsers(usernames: string[]): Promise<any[]>;
|
|
33
|
+
/**
|
|
34
|
+
* 条件缓存示例
|
|
35
|
+
*/
|
|
11
36
|
getRepositoryDetails(owner: string, repo: string, options?: {
|
|
12
37
|
public?: boolean;
|
|
13
38
|
}): Promise<any>;
|
|
14
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* 支付服务示例 - 高安全性要求
|
|
42
|
+
* 使用Redis锁定确保并发安全
|
|
43
|
+
*/
|
|
15
44
|
export declare class PaymentHttpService {
|
|
16
45
|
private httpClient;
|
|
17
46
|
constructor(httpClient: HttpClientService);
|
|
47
|
+
/**
|
|
48
|
+
* 创建支付 - 严格的安全控制
|
|
49
|
+
*/
|
|
18
50
|
createPayment(paymentData: any, apiKey: string): Promise<any>;
|
|
51
|
+
/**
|
|
52
|
+
* 查询支付状态 - 可缓存
|
|
53
|
+
*/
|
|
19
54
|
getPaymentStatus(paymentId: string, apiKey: string): Promise<any>;
|
|
55
|
+
/**
|
|
56
|
+
* 退款操作 - 重试机制
|
|
57
|
+
*/
|
|
20
58
|
refundPayment(paymentId: string, refundData: any, apiKey: string): Promise<any>;
|
|
59
|
+
/**
|
|
60
|
+
* 动态调用示例 - 手动设置调用信息
|
|
61
|
+
*/
|
|
21
62
|
callExternalApi(url: string, method?: string, data?: any): Promise<any>;
|
|
22
63
|
private generateIdempotencyKey;
|
|
23
64
|
}
|
|
@@ -23,15 +23,25 @@ const common_1 = require("@nestjs/common");
|
|
|
23
23
|
const decorators_1 = require("../decorators");
|
|
24
24
|
const http_client_service_1 = require("../services/http-client.service");
|
|
25
25
|
const cache_options_interface_1 = require("../../cache/interfaces/cache-options.interface");
|
|
26
|
+
/**
|
|
27
|
+
* 高级使用示例 - GitHub API客户端
|
|
28
|
+
* 集成现有的三层缓存架构
|
|
29
|
+
*/
|
|
26
30
|
let GitHubHttpService = class GitHubHttpService {
|
|
27
31
|
constructor(httpClient) {
|
|
28
32
|
this.httpClient = httpClient;
|
|
29
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* 获取用户信息 - 带重试、熔断器、缓存和日志
|
|
36
|
+
*/
|
|
30
37
|
getUser(username) {
|
|
31
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
39
|
return this.httpClient.get(`/users/${username}`);
|
|
33
40
|
});
|
|
34
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* 搜索仓库 - 带重试和缓存
|
|
44
|
+
*/
|
|
35
45
|
searchRepositories(query_1) {
|
|
36
46
|
return __awaiter(this, arguments, void 0, function* (query, sort = 'stars', order = 'desc') {
|
|
37
47
|
return this.httpClient.get('/search/repositories', {
|
|
@@ -44,6 +54,9 @@ let GitHubHttpService = class GitHubHttpService {
|
|
|
44
54
|
});
|
|
45
55
|
});
|
|
46
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* 获取用户仓库 - 使用代理
|
|
59
|
+
*/
|
|
47
60
|
getUserRepositories(username) {
|
|
48
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
62
|
return this.httpClient.get(`/users/${username}/repos`, {
|
|
@@ -55,6 +68,9 @@ let GitHubHttpService = class GitHubHttpService {
|
|
|
55
68
|
});
|
|
56
69
|
});
|
|
57
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* 创建仓库 - 带详细日志
|
|
73
|
+
*/
|
|
58
74
|
createRepository(repoData, token) {
|
|
59
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
76
|
return this.httpClient.post('/user/repos', repoData, {
|
|
@@ -65,11 +81,17 @@ let GitHubHttpService = class GitHubHttpService {
|
|
|
65
81
|
});
|
|
66
82
|
});
|
|
67
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* 获取仓库贡献者 - 熔断器保护
|
|
86
|
+
*/
|
|
68
87
|
getRepositoryContributors(owner, repo) {
|
|
69
88
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
89
|
return this.httpClient.get(`/repos/${owner}/${repo}/contributors`);
|
|
71
90
|
});
|
|
72
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* 批量获取用户信息 - 并行请求
|
|
94
|
+
*/
|
|
73
95
|
getMultipleUsers(usernames) {
|
|
74
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
97
|
const promises = usernames.map((username) => this.getUser(username).catch((error) => {
|
|
@@ -79,6 +101,9 @@ let GitHubHttpService = class GitHubHttpService {
|
|
|
79
101
|
return Promise.all(promises);
|
|
80
102
|
});
|
|
81
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* 条件缓存示例
|
|
106
|
+
*/
|
|
82
107
|
getRepositoryDetails(owner, repo, options) {
|
|
83
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
109
|
return this.httpClient.get(`/repos/${owner}/${repo}`);
|
|
@@ -92,9 +117,9 @@ __decorate([
|
|
|
92
117
|
retryDelay: (retryCount) => Math.pow(2, retryCount) * 1000,
|
|
93
118
|
retryCondition: (error) => {
|
|
94
119
|
if (!error.response)
|
|
95
|
-
return true;
|
|
120
|
+
return true; // 网络错误
|
|
96
121
|
const status = error.response.status;
|
|
97
|
-
return status >= 500 || status === 429;
|
|
122
|
+
return status >= 500 || status === 429; // 5xx错误或429限流
|
|
98
123
|
},
|
|
99
124
|
}),
|
|
100
125
|
(0, decorators_1.HttpCircuitBreaker)({
|
|
@@ -102,17 +127,17 @@ __decorate([
|
|
|
102
127
|
recoveryTimeoutMs: 30000,
|
|
103
128
|
}),
|
|
104
129
|
(0, decorators_1.HttpCacheable)({
|
|
105
|
-
ttl: 300000,
|
|
106
|
-
layers: ['cls', 'memory', 'redis'],
|
|
130
|
+
ttl: 300000, // 5分钟缓存
|
|
131
|
+
layers: ['cls', 'memory', 'redis'], // 使用三层缓存
|
|
107
132
|
namespace: 'github',
|
|
108
133
|
}),
|
|
109
134
|
(0, decorators_1.HttpLogRequest)({
|
|
110
135
|
databaseLog: true,
|
|
111
136
|
logHeaders: true,
|
|
112
137
|
logBody: false,
|
|
113
|
-
serviceClass: 'GitHubHttpService',
|
|
114
|
-
methodName: 'getUser',
|
|
115
|
-
operationName: 'github.getUser',
|
|
138
|
+
serviceClass: 'GitHubHttpService', // 自定义服务类名
|
|
139
|
+
methodName: 'getUser', // 自定义方法名
|
|
140
|
+
operationName: 'github.getUser', // 自定义操作名
|
|
116
141
|
}),
|
|
117
142
|
(0, decorators_1.HttpTimeout)(15000),
|
|
118
143
|
__metadata("design:type", Function),
|
|
@@ -122,10 +147,10 @@ __decorate([
|
|
|
122
147
|
__decorate([
|
|
123
148
|
(0, decorators_1.HttpRetry)({ retries: 3 }),
|
|
124
149
|
(0, decorators_1.HttpCacheable)({
|
|
125
|
-
ttl: 600000,
|
|
126
|
-
layers: ['memory', 'redis'],
|
|
150
|
+
ttl: 600000, // 10分钟缓存
|
|
151
|
+
layers: ['memory', 'redis'], // 仅使用内存和Redis缓存
|
|
127
152
|
namespace: 'github-search',
|
|
128
|
-
condition: (args) => args[0].length > 2,
|
|
153
|
+
condition: (args) => args[0].length > 2, // 只缓存搜索词长度大于2的请求
|
|
129
154
|
}),
|
|
130
155
|
__metadata("design:type", Function),
|
|
131
156
|
__metadata("design:paramtypes", [String, String, String]),
|
|
@@ -138,7 +163,7 @@ __decorate([
|
|
|
138
163
|
protocol: 'http',
|
|
139
164
|
}),
|
|
140
165
|
(0, decorators_1.HttpCacheable)({
|
|
141
|
-
ttl: 120000,
|
|
166
|
+
ttl: 120000, // 2分钟缓存
|
|
142
167
|
namespace: 'github-repos',
|
|
143
168
|
}),
|
|
144
169
|
__metadata("design:type", Function),
|
|
@@ -162,7 +187,7 @@ __decorate([
|
|
|
162
187
|
recoveryTimeoutMs: 60000,
|
|
163
188
|
}),
|
|
164
189
|
(0, decorators_1.HttpCacheable)({
|
|
165
|
-
ttl: 900000,
|
|
190
|
+
ttl: 900000, // 15分钟缓存
|
|
166
191
|
namespace: 'github-contributors',
|
|
167
192
|
}),
|
|
168
193
|
__metadata("design:type", Function),
|
|
@@ -171,11 +196,11 @@ __decorate([
|
|
|
171
196
|
], GitHubHttpService.prototype, "getRepositoryContributors", null);
|
|
172
197
|
__decorate([
|
|
173
198
|
(0, decorators_1.HttpCacheable)({
|
|
174
|
-
ttl: 120000,
|
|
175
|
-
layers: ['memory'],
|
|
199
|
+
ttl: 120000, // 2分钟缓存
|
|
200
|
+
layers: ['memory'], // 仅内存缓存
|
|
176
201
|
namespace: 'github-repo-details',
|
|
177
|
-
condition: (args) => { var _a; return ((_a = args[2]) === null || _a === void 0 ? void 0 : _a.public) === true; },
|
|
178
|
-
unless: (result, args) => (result === null || result === void 0 ? void 0 : result.archived) === true,
|
|
202
|
+
condition: (args) => { var _a; return ((_a = args[2]) === null || _a === void 0 ? void 0 : _a.public) === true; }, // 只缓存公开仓库
|
|
203
|
+
unless: (result, args) => (result === null || result === void 0 ? void 0 : result.archived) === true, // 不缓存已归档的仓库
|
|
179
204
|
}),
|
|
180
205
|
__metadata("design:type", Function),
|
|
181
206
|
__metadata("design:paramtypes", [String, String, Object]),
|
|
@@ -191,7 +216,7 @@ exports.GitHubHttpService = GitHubHttpService = __decorate([
|
|
|
191
216
|
cacheableMethods: ['GET', 'HEAD'],
|
|
192
217
|
cacheableStatusCodes: [200, 304],
|
|
193
218
|
options: {
|
|
194
|
-
layers: [cache_options_interface_1.CacheLayer.MEMORY, cache_options_interface_1.CacheLayer.REDIS],
|
|
219
|
+
layers: [cache_options_interface_1.CacheLayer.MEMORY, cache_options_interface_1.CacheLayer.REDIS], // 使用现有的三层缓存
|
|
195
220
|
},
|
|
196
221
|
},
|
|
197
222
|
logging: {
|
|
@@ -209,10 +234,17 @@ exports.GitHubHttpService = GitHubHttpService = __decorate([
|
|
|
209
234
|
(0, common_1.Injectable)(),
|
|
210
235
|
__metadata("design:paramtypes", [http_client_service_1.HttpClientService])
|
|
211
236
|
], GitHubHttpService);
|
|
237
|
+
/**
|
|
238
|
+
* 支付服务示例 - 高安全性要求
|
|
239
|
+
* 使用Redis锁定确保并发安全
|
|
240
|
+
*/
|
|
212
241
|
let PaymentHttpService = class PaymentHttpService {
|
|
213
242
|
constructor(httpClient) {
|
|
214
243
|
this.httpClient = httpClient;
|
|
215
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* 创建支付 - 严格的安全控制
|
|
247
|
+
*/
|
|
216
248
|
createPayment(paymentData, apiKey) {
|
|
217
249
|
return __awaiter(this, void 0, void 0, function* () {
|
|
218
250
|
return this.httpClient.post('/payments', paymentData, {
|
|
@@ -224,6 +256,9 @@ let PaymentHttpService = class PaymentHttpService {
|
|
|
224
256
|
});
|
|
225
257
|
});
|
|
226
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* 查询支付状态 - 可缓存
|
|
261
|
+
*/
|
|
227
262
|
getPaymentStatus(paymentId, apiKey) {
|
|
228
263
|
return __awaiter(this, void 0, void 0, function* () {
|
|
229
264
|
return this.httpClient.get(`/payments/${paymentId}`, {
|
|
@@ -233,6 +268,9 @@ let PaymentHttpService = class PaymentHttpService {
|
|
|
233
268
|
});
|
|
234
269
|
});
|
|
235
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* 退款操作 - 重试机制
|
|
273
|
+
*/
|
|
236
274
|
refundPayment(paymentId, refundData, apiKey) {
|
|
237
275
|
return __awaiter(this, void 0, void 0, function* () {
|
|
238
276
|
return this.httpClient.post(`/payments/${paymentId}/refund`, refundData, {
|
|
@@ -243,8 +281,12 @@ let PaymentHttpService = class PaymentHttpService {
|
|
|
243
281
|
});
|
|
244
282
|
});
|
|
245
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* 动态调用示例 - 手动设置调用信息
|
|
286
|
+
*/
|
|
246
287
|
callExternalApi(url_1) {
|
|
247
288
|
return __awaiter(this, arguments, void 0, function* (url, method = 'GET', data) {
|
|
289
|
+
// 手动设置调用信息
|
|
248
290
|
const { CallStackExtractor } = require('../utils');
|
|
249
291
|
CallStackExtractor.setCallInfo('PaymentHttpService', 'callExternalApi', `payment.${method.toLowerCase()}`);
|
|
250
292
|
try {
|
|
@@ -259,6 +301,7 @@ let PaymentHttpService = class PaymentHttpService {
|
|
|
259
301
|
});
|
|
260
302
|
}
|
|
261
303
|
finally {
|
|
304
|
+
// 清理调用信息
|
|
262
305
|
CallStackExtractor.clearCallInfo();
|
|
263
306
|
}
|
|
264
307
|
});
|
|
@@ -281,8 +324,8 @@ __decorate([
|
|
|
281
324
|
], PaymentHttpService.prototype, "createPayment", null);
|
|
282
325
|
__decorate([
|
|
283
326
|
(0, decorators_1.HttpCacheable)({
|
|
284
|
-
ttl: 30000,
|
|
285
|
-
layers: ['redis'],
|
|
327
|
+
ttl: 30000, // 30秒缓存
|
|
328
|
+
layers: ['redis'], // 仅Redis缓存,确保多实例共享
|
|
286
329
|
namespace: 'payment-status',
|
|
287
330
|
}),
|
|
288
331
|
__metadata("design:type", Function),
|
|
@@ -292,8 +335,9 @@ __decorate([
|
|
|
292
335
|
__decorate([
|
|
293
336
|
(0, decorators_1.HttpRetry)({
|
|
294
337
|
retries: 2,
|
|
295
|
-
retryDelay: (retryCount) => retryCount * 2000,
|
|
338
|
+
retryDelay: (retryCount) => retryCount * 2000, // 线性退避
|
|
296
339
|
retryCondition: (error) => {
|
|
340
|
+
// 只对网络错误和5xx错误重试,4xx错误不重试
|
|
297
341
|
if (!error.response)
|
|
298
342
|
return true;
|
|
299
343
|
return error.response.status >= 500;
|
|
@@ -302,7 +346,7 @@ __decorate([
|
|
|
302
346
|
(0, decorators_1.HttpLogRequest)({
|
|
303
347
|
logHeaders: false,
|
|
304
348
|
logBody: false,
|
|
305
|
-
databaseLog: true,
|
|
349
|
+
databaseLog: true, // 退款操作需要记录到数据库
|
|
306
350
|
}),
|
|
307
351
|
__metadata("design:type", Function),
|
|
308
352
|
__metadata("design:paramtypes", [String, Object, String]),
|
|
@@ -313,15 +357,15 @@ exports.PaymentHttpService = PaymentHttpService = __decorate([
|
|
|
313
357
|
baseURL: 'https://api.payment-provider.com',
|
|
314
358
|
timeout: 15000,
|
|
315
359
|
retry: {
|
|
316
|
-
enabled: false,
|
|
360
|
+
enabled: false, // 支付操作不自动重试
|
|
317
361
|
},
|
|
318
362
|
logging: {
|
|
319
363
|
enabled: true,
|
|
320
364
|
logRequests: true,
|
|
321
365
|
logResponses: true,
|
|
322
366
|
logErrors: true,
|
|
323
|
-
logHeaders: false,
|
|
324
|
-
logBody: false,
|
|
367
|
+
logHeaders: false, // 不记录敏感头信息
|
|
368
|
+
logBody: false, // 不记录支付数据
|
|
325
369
|
maxBodyLength: 1000,
|
|
326
370
|
sanitizeHeaders: ['authorization', 'x-api-key', 'x-client-secret'],
|
|
327
371
|
logLevel: 'info',
|
|
@@ -1,17 +1,48 @@
|
|
|
1
1
|
import { HttpClientService } from '../services/http-client.service';
|
|
2
2
|
import { HttpLogQueryService } from '../services/http-log-query.service';
|
|
3
3
|
import { HttpReplayService } from '../services/http-replay.service';
|
|
4
|
+
/**
|
|
5
|
+
* 使用等待锁的认证示例
|
|
6
|
+
* 演示如何在原有的HTTP客户端中使用等待锁机制
|
|
7
|
+
*/
|
|
4
8
|
export declare class AuthWithWaitingLockExample {
|
|
5
9
|
private readonly httpClient;
|
|
6
10
|
private readonly logQueryService;
|
|
7
11
|
private readonly replayService;
|
|
8
12
|
private readonly logger;
|
|
9
13
|
constructor(httpClient: HttpClientService, logQueryService: HttpLogQueryService, replayService: HttpReplayService);
|
|
14
|
+
/**
|
|
15
|
+
* 示例1: 基本的带等待锁的认证请求
|
|
16
|
+
* 演示如何使用authRequest方法确保只有一个进程获取token
|
|
17
|
+
*/
|
|
10
18
|
basicAuthWithLock(): Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* 示例2: 批量带等待锁的认证请求
|
|
21
|
+
* 演示如何在批量操作中共享token,避免重复认证
|
|
22
|
+
*/
|
|
11
23
|
batchAuthWithLock(): Promise<any[]>;
|
|
24
|
+
/**
|
|
25
|
+
* 示例3: 从HTTP日志生成curl命令
|
|
26
|
+
* 演示如何从已有的HTTP日志生成可执行的curl命令
|
|
27
|
+
*/
|
|
12
28
|
generateCurlFromLogs(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* 示例4: 请求重放功能
|
|
31
|
+
* 演示如何重放已有的HTTP请求
|
|
32
|
+
*/
|
|
13
33
|
demonstrateRequestReplay(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* 示例5: 批量重放和比较
|
|
36
|
+
* 演示如何批量重放请求并比较结果
|
|
37
|
+
*/
|
|
14
38
|
batchReplayAndCompare(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* 示例6: 综合演示 - 等待锁 + curl生成 + 请求重放
|
|
41
|
+
* 演示完整的工作流程
|
|
42
|
+
*/
|
|
15
43
|
comprehensiveDemo(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* 运行所有示例
|
|
46
|
+
*/
|
|
16
47
|
runAllExamples(): Promise<void>;
|
|
17
48
|
}
|