@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
|
@@ -1,193 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.AtLeastOneFieldConstraint = void 0;
|
|
19
|
-
exports.IsPassword = IsPassword;
|
|
20
|
-
exports.IsPhoneNumber = IsPhoneNumber;
|
|
21
|
-
exports.IsTmpKey = IsTmpKey;
|
|
22
|
-
exports.IsUndefinable = IsUndefinable;
|
|
23
|
-
exports.IsEmptyable = IsEmptyable;
|
|
24
|
-
exports.IsNullable = IsNullable;
|
|
25
|
-
exports.IsHttpUrl = IsHttpUrl;
|
|
26
|
-
exports.AtLeastOneField = AtLeastOneField;
|
|
27
|
-
exports.CustomValidation = CustomValidation;
|
|
28
|
-
exports.CustomValidationMethod = CustomValidationMethod;
|
|
29
|
-
const class_validator_1 = require("class-validator");
|
|
30
|
-
const lodash_1 = require("lodash");
|
|
31
|
-
const nestjs_i18n_1 = require("nestjs-i18n");
|
|
32
|
-
function IsPassword(validationOptions) {
|
|
33
|
-
return (object, propertyName) => {
|
|
34
|
-
(0, class_validator_1.registerDecorator)({
|
|
35
|
-
propertyName,
|
|
36
|
-
name: 'isPassword',
|
|
37
|
-
target: object.constructor,
|
|
38
|
-
constraints: [],
|
|
39
|
-
options: validationOptions,
|
|
40
|
-
validator: {
|
|
41
|
-
validate(value) {
|
|
42
|
-
return /^[\d!#$%&*@A-Z^a-z]*$/.test(value);
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function IsPhoneNumber(validationOptions) {
|
|
49
|
-
return (0, class_validator_1.IsPhoneNumber)(validationOptions === null || validationOptions === void 0 ? void 0 : validationOptions.region, Object.assign({ message: 'error.phoneNumber' }, validationOptions));
|
|
50
|
-
}
|
|
51
|
-
function IsTmpKey(validationOptions) {
|
|
52
|
-
return (object, propertyName) => {
|
|
53
|
-
(0, class_validator_1.registerDecorator)({
|
|
54
|
-
propertyName,
|
|
55
|
-
name: 'tmpKey',
|
|
56
|
-
target: object.constructor,
|
|
57
|
-
options: validationOptions,
|
|
58
|
-
validator: {
|
|
59
|
-
validate(value) {
|
|
60
|
-
return (0, lodash_1.isString)(value) && /^tmp\//.test(value);
|
|
61
|
-
},
|
|
62
|
-
defaultMessage() {
|
|
63
|
-
return 'error.invalidTmpKey';
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
function IsUndefinable(options) {
|
|
70
|
-
return (0, class_validator_1.ValidateIf)((obj, value) => value !== undefined, options);
|
|
71
|
-
}
|
|
72
|
-
function IsEmptyable(options) {
|
|
73
|
-
return (0, class_validator_1.ValidateIf)((obj, value) => !(value === null ||
|
|
74
|
-
value === undefined ||
|
|
75
|
-
((0, lodash_1.isString)(value) && value.trim() === '')), options);
|
|
76
|
-
}
|
|
77
|
-
function IsNullable(options) {
|
|
78
|
-
return (0, class_validator_1.ValidateIf)((obj, value) => value !== null, options);
|
|
79
|
-
}
|
|
80
|
-
function IsHttpUrl(validationOptions) {
|
|
81
|
-
return function (object, propertyName) {
|
|
82
|
-
(0, class_validator_1.registerDecorator)({
|
|
83
|
-
name: 'isHttpUrl',
|
|
84
|
-
target: object.constructor,
|
|
85
|
-
propertyName: propertyName,
|
|
86
|
-
options: validationOptions,
|
|
87
|
-
validator: {
|
|
88
|
-
validate(value) {
|
|
89
|
-
const httpUrlPattern = /^(https?:\/\/)/i;
|
|
90
|
-
return typeof value === 'string' && httpUrlPattern.test(value);
|
|
91
|
-
},
|
|
92
|
-
defaultMessage() {
|
|
93
|
-
return 'URL must start with http:// or https://';
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
let AtLeastOneFieldConstraint = class AtLeastOneFieldConstraint {
|
|
100
|
-
validate(value, args) {
|
|
101
|
-
const object = args.object;
|
|
102
|
-
const [requiredProperties] = args.constraints;
|
|
103
|
-
return requiredProperties.some((property) => {
|
|
104
|
-
const propValue = object[property];
|
|
105
|
-
return (propValue !== null &&
|
|
106
|
-
propValue !== undefined &&
|
|
107
|
-
propValue !== '' &&
|
|
108
|
-
!(Array.isArray(propValue) && propValue.length === 0));
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
defaultMessage(args) {
|
|
112
|
-
const [requiredProperties] = args.constraints;
|
|
113
|
-
return `At least one of the following fields must be provided: ${requiredProperties.join(', ')}`;
|
|
2
|
+
/**
|
|
3
|
+
* Validator decorators
|
|
4
|
+
*
|
|
5
|
+
* 所有验证装饰器已迁移到 validators 目录
|
|
6
|
+
* 此文件仅用于重新导出,保持导入路径的一致性
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
114
13
|
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
115
21
|
};
|
|
116
|
-
exports
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
function AtLeastOneField(properties, validationOptions) {
|
|
121
|
-
return function (object, propertyName) {
|
|
122
|
-
(0, class_validator_1.registerDecorator)({
|
|
123
|
-
target: object.constructor,
|
|
124
|
-
propertyName: propertyName,
|
|
125
|
-
options: Object.assign({ message: (0, nestjs_i18n_1.i18nValidationMessage)('validation.AT_LEAST_ONE_FIELD', {
|
|
126
|
-
properties: properties.join(', '),
|
|
127
|
-
}) }, validationOptions),
|
|
128
|
-
constraints: [properties],
|
|
129
|
-
validator: AtLeastOneFieldConstraint,
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
function CustomValidation(validationCallback, validationOptions) {
|
|
134
|
-
return function (object, propertyName) {
|
|
135
|
-
(0, class_validator_1.registerDecorator)({
|
|
136
|
-
name: 'customValidation',
|
|
137
|
-
target: object.constructor,
|
|
138
|
-
propertyName,
|
|
139
|
-
options: Object.assign({ message: (0, nestjs_i18n_1.i18nValidationMessage)('validation.CUSTOM_VALIDATION') }, validationOptions),
|
|
140
|
-
validator: {
|
|
141
|
-
validate(value, args) {
|
|
142
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
-
try {
|
|
144
|
-
return yield validationCallback(value, args);
|
|
145
|
-
}
|
|
146
|
-
catch (error) {
|
|
147
|
-
console.error('CustomValidation error:', error);
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
},
|
|
152
|
-
defaultMessage(args) {
|
|
153
|
-
return `Validation failed for ${args.property}`;
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
function CustomValidationMethod(methodName, validationOptions) {
|
|
160
|
-
return function (object, propertyName) {
|
|
161
|
-
(0, class_validator_1.registerDecorator)({
|
|
162
|
-
name: 'customValidationMethod',
|
|
163
|
-
target: object.constructor,
|
|
164
|
-
propertyName,
|
|
165
|
-
constraints: [methodName],
|
|
166
|
-
options: Object.assign({ message: (0, nestjs_i18n_1.i18nValidationMessage)('validation.CUSTOM_VALIDATION_METHOD') }, validationOptions),
|
|
167
|
-
validator: {
|
|
168
|
-
validate(value, args) {
|
|
169
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
-
const [method] = args.constraints;
|
|
171
|
-
const object = args.object;
|
|
172
|
-
if (typeof object[method] !== 'function') {
|
|
173
|
-
console.error(`CustomValidationMethod: Method '${method}' not found on object`);
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
try {
|
|
177
|
-
const result = yield object[method](value, args);
|
|
178
|
-
return Boolean(result);
|
|
179
|
-
}
|
|
180
|
-
catch (error) {
|
|
181
|
-
console.error(`CustomValidationMethod error in '${method}':`, error);
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
},
|
|
186
|
-
defaultMessage(args) {
|
|
187
|
-
const [method] = args.constraints;
|
|
188
|
-
return `Validation failed for ${args.property} using method ${method}`;
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
});
|
|
192
|
-
};
|
|
193
|
-
}
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
// 重新导出所有验证装饰器
|
|
24
|
+
__exportStar(require("../validators/common-validators"), exports);
|
|
25
|
+
__exportStar(require("../validators/custom-validate.validator"), exports);
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 将枚举值转换成数组
|
|
3
|
+
* @param Enum 枚举
|
|
4
|
+
*/
|
|
1
5
|
export declare function enumToArray<E>(Enum: any): E[];
|
|
6
|
+
/**
|
|
7
|
+
* 生成随机字符串
|
|
8
|
+
* @param {number} length 生成长度
|
|
9
|
+
* @param {string} charSet 指定字符集
|
|
10
|
+
* @returns {string} 生成字符串
|
|
11
|
+
*/
|
|
2
12
|
export declare const randomString: (length?: number, charSet?: string) => string;
|
|
13
|
+
/**
|
|
14
|
+
* 获取服务部署 IP 地址
|
|
15
|
+
*/
|
|
3
16
|
export declare function getIPAdress(): string;
|
package/helpers/common.helper.js
CHANGED
|
@@ -4,11 +4,21 @@ exports.randomString = void 0;
|
|
|
4
4
|
exports.enumToArray = enumToArray;
|
|
5
5
|
exports.getIPAdress = getIPAdress;
|
|
6
6
|
const os_1 = require("os");
|
|
7
|
+
/**
|
|
8
|
+
* 将枚举值转换成数组
|
|
9
|
+
* @param Enum 枚举
|
|
10
|
+
*/
|
|
7
11
|
function enumToArray(Enum) {
|
|
8
12
|
return Object.keys(Enum)
|
|
9
13
|
.filter((key) => typeof Enum[key] === 'number')
|
|
10
14
|
.map((key) => Enum[key]);
|
|
11
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* 生成随机字符串
|
|
18
|
+
* @param {number} length 生成长度
|
|
19
|
+
* @param {string} charSet 指定字符集
|
|
20
|
+
* @returns {string} 生成字符串
|
|
21
|
+
*/
|
|
12
22
|
const randomString = (length = 8, charSet) => {
|
|
13
23
|
charSet =
|
|
14
24
|
charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
@@ -20,6 +30,9 @@ const randomString = (length = 8, charSet) => {
|
|
|
20
30
|
return randomString;
|
|
21
31
|
};
|
|
22
32
|
exports.randomString = randomString;
|
|
33
|
+
/**
|
|
34
|
+
* 获取服务部署 IP 地址
|
|
35
|
+
*/
|
|
23
36
|
function getIPAdress() {
|
|
24
37
|
const interfaces = (0, os_1.networkInterfaces)();
|
|
25
38
|
for (const devName in interfaces) {
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { HttpClientConfig } from '../interfaces/http-client-config.interface';
|
|
2
|
+
/**
|
|
3
|
+
* HTTP客户端默认配置
|
|
4
|
+
*/
|
|
2
5
|
export declare const DEFAULT_HTTP_CLIENT_CONFIG: Partial<HttpClientConfig>;
|
|
6
|
+
/**
|
|
7
|
+
* 开发环境配置
|
|
8
|
+
*/
|
|
3
9
|
export declare const DEVELOPMENT_HTTP_CLIENT_CONFIG: Partial<HttpClientConfig>;
|
|
10
|
+
/**
|
|
11
|
+
* 生产环境配置
|
|
12
|
+
*/
|
|
4
13
|
export declare const PRODUCTION_HTTP_CLIENT_CONFIG: Partial<HttpClientConfig>;
|
|
14
|
+
/**
|
|
15
|
+
* 测试环境配置
|
|
16
|
+
*/
|
|
5
17
|
export declare const TEST_HTTP_CLIENT_CONFIG: Partial<HttpClientConfig>;
|
|
18
|
+
/**
|
|
19
|
+
* 根据环境获取配置
|
|
20
|
+
*/
|
|
6
21
|
export declare function getHttpClientConfig(env?: string): Partial<HttpClientConfig>;
|
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TEST_HTTP_CLIENT_CONFIG = exports.PRODUCTION_HTTP_CLIENT_CONFIG = exports.DEVELOPMENT_HTTP_CLIENT_CONFIG = exports.DEFAULT_HTTP_CLIENT_CONFIG = void 0;
|
|
4
4
|
exports.getHttpClientConfig = getHttpClientConfig;
|
|
5
5
|
const cache_options_interface_1 = require("../../cache/interfaces/cache-options.interface");
|
|
6
|
+
/**
|
|
7
|
+
* HTTP客户端默认配置
|
|
8
|
+
*/
|
|
6
9
|
exports.DEFAULT_HTTP_CLIENT_CONFIG = {
|
|
7
10
|
timeout: 30000,
|
|
8
11
|
retry: {
|
|
@@ -10,10 +13,11 @@ exports.DEFAULT_HTTP_CLIENT_CONFIG = {
|
|
|
10
13
|
retries: 3,
|
|
11
14
|
retryDelay: (retryCount) => Math.pow(2, retryCount) * 1000,
|
|
12
15
|
retryCondition: (error) => {
|
|
16
|
+
// 默认重试条件:网络错误、超时、5xx错误、429错误
|
|
13
17
|
if (!error.response)
|
|
14
|
-
return true;
|
|
18
|
+
return true; // 网络错误
|
|
15
19
|
const status = error.response.status;
|
|
16
|
-
return status >= 500 || status === 429;
|
|
20
|
+
return status >= 500 || status === 429; // 服务器错误或限流
|
|
17
21
|
},
|
|
18
22
|
shouldResetTimeout: true,
|
|
19
23
|
},
|
|
@@ -27,7 +31,7 @@ exports.DEFAULT_HTTP_CLIENT_CONFIG = {
|
|
|
27
31
|
},
|
|
28
32
|
cache: {
|
|
29
33
|
enabled: true,
|
|
30
|
-
defaultTtl: 300000,
|
|
34
|
+
defaultTtl: 300000, // 5分钟
|
|
31
35
|
cacheableMethods: ['GET', 'HEAD'],
|
|
32
36
|
cacheableStatusCodes: [200, 201, 304],
|
|
33
37
|
options: {
|
|
@@ -39,37 +43,49 @@ exports.DEFAULT_HTTP_CLIENT_CONFIG = {
|
|
|
39
43
|
logRequests: true,
|
|
40
44
|
logResponses: true,
|
|
41
45
|
logErrors: true,
|
|
42
|
-
logHeaders: false,
|
|
46
|
+
logHeaders: false, // 默认不记录头信息(安全考虑)
|
|
43
47
|
logBody: true,
|
|
44
48
|
maxBodyLength: 1000,
|
|
45
49
|
sanitizeHeaders: ['authorization', 'apikey', 'password', 'token', 'cookie'],
|
|
46
50
|
logLevel: 'info',
|
|
47
51
|
databaseLogging: {
|
|
48
|
-
enabled: false,
|
|
52
|
+
enabled: false, // 默认不启用数据库日志
|
|
49
53
|
dataSource: 'default',
|
|
50
54
|
tableName: 'http_logs',
|
|
51
55
|
},
|
|
52
56
|
},
|
|
53
57
|
logCleanup: {
|
|
54
|
-
enabled: false,
|
|
58
|
+
enabled: false, // 默认不启用日志清理
|
|
55
59
|
retentionDays: 30,
|
|
56
60
|
maxRecords: 100000,
|
|
57
61
|
batchSize: 1000,
|
|
58
|
-
schedule: '0 2 * * *',
|
|
62
|
+
schedule: '0 2 * * *', // 每天凌晨2点
|
|
59
63
|
strategy: 'retention',
|
|
60
64
|
},
|
|
61
65
|
};
|
|
66
|
+
/**
|
|
67
|
+
* 开发环境配置
|
|
68
|
+
*/
|
|
62
69
|
exports.DEVELOPMENT_HTTP_CLIENT_CONFIG = Object.assign(Object.assign({}, exports.DEFAULT_HTTP_CLIENT_CONFIG), { logging: Object.assign(Object.assign({}, exports.DEFAULT_HTTP_CLIENT_CONFIG.logging), { enabled: true, logHeaders: true, logBody: true, logLevel: 'debug', databaseLogging: {
|
|
63
|
-
enabled: true,
|
|
70
|
+
enabled: true, // 开发环境启用数据库日志
|
|
64
71
|
dataSource: 'default',
|
|
65
72
|
tableName: 'http_logs',
|
|
66
73
|
} }), logCleanup: Object.assign(Object.assign({}, exports.DEFAULT_HTTP_CLIENT_CONFIG.logCleanup), { enabled: false }) });
|
|
74
|
+
/**
|
|
75
|
+
* 生产环境配置
|
|
76
|
+
*/
|
|
67
77
|
exports.PRODUCTION_HTTP_CLIENT_CONFIG = Object.assign(Object.assign({}, exports.DEFAULT_HTTP_CLIENT_CONFIG), { timeout: 60000, retry: Object.assign(Object.assign({}, exports.DEFAULT_HTTP_CLIENT_CONFIG.retry), { retries: 5 }), circuitBreaker: Object.assign(Object.assign({}, exports.DEFAULT_HTTP_CLIENT_CONFIG.circuitBreaker), { failureThreshold: 3, recoveryTimeoutMs: 120000 }), logging: Object.assign(Object.assign({}, exports.DEFAULT_HTTP_CLIENT_CONFIG.logging), { enabled: true, logHeaders: false, logBody: false, logLevel: 'warn', databaseLogging: {
|
|
68
|
-
enabled: true,
|
|
78
|
+
enabled: true, // 生产环境启用数据库日志
|
|
69
79
|
dataSource: 'default',
|
|
70
80
|
tableName: 'http_logs',
|
|
71
81
|
} }), logCleanup: Object.assign(Object.assign({}, exports.DEFAULT_HTTP_CLIENT_CONFIG.logCleanup), { enabled: true, retentionDays: 7, maxRecords: 50000, schedule: '0 3 * * *' }) });
|
|
82
|
+
/**
|
|
83
|
+
* 测试环境配置
|
|
84
|
+
*/
|
|
72
85
|
exports.TEST_HTTP_CLIENT_CONFIG = Object.assign(Object.assign({}, exports.DEFAULT_HTTP_CLIENT_CONFIG), { timeout: 10000, retry: Object.assign(Object.assign({}, exports.DEFAULT_HTTP_CLIENT_CONFIG.retry), { retries: 1 }), circuitBreaker: Object.assign(Object.assign({}, exports.DEFAULT_HTTP_CLIENT_CONFIG.circuitBreaker), { failureThreshold: 10, recoveryTimeoutMs: 5000 }), logging: Object.assign(Object.assign({}, exports.DEFAULT_HTTP_CLIENT_CONFIG.logging), { enabled: false }), logCleanup: Object.assign(Object.assign({}, exports.DEFAULT_HTTP_CLIENT_CONFIG.logCleanup), { enabled: false }) });
|
|
86
|
+
/**
|
|
87
|
+
* 根据环境获取配置
|
|
88
|
+
*/
|
|
73
89
|
function getHttpClientConfig(env) {
|
|
74
90
|
switch (env === null || env === void 0 ? void 0 : env.toLowerCase()) {
|
|
75
91
|
case 'development':
|
|
@@ -8,7 +8,15 @@ export declare const LOGGING_OPTIONS_KEY = "http_logging_options";
|
|
|
8
8
|
export declare const TIMEOUT_OPTIONS_KEY = "http_timeout_options";
|
|
9
9
|
export declare const PROXY_OPTIONS_KEY = "http_proxy_options";
|
|
10
10
|
export declare const CALL_INFO_KEY = "http_call_info";
|
|
11
|
+
/**
|
|
12
|
+
* HTTP客户端装饰器
|
|
13
|
+
* 类似Spring Boot的@RestClient注解
|
|
14
|
+
*/
|
|
11
15
|
export declare const HttpClient: (options?: HttpClientConfig) => (target: any) => void;
|
|
16
|
+
/**
|
|
17
|
+
* 重试装饰器
|
|
18
|
+
* 基于axios-retry库
|
|
19
|
+
*/
|
|
12
20
|
export declare const HttpRetry: (options?: {
|
|
13
21
|
retries?: number;
|
|
14
22
|
retryDelay?: (retryCount: number) => number;
|
|
@@ -16,20 +24,38 @@ export declare const HttpRetry: (options?: {
|
|
|
16
24
|
shouldResetTimeout?: boolean;
|
|
17
25
|
onRetry?: (retryCount: number, error: any, requestConfig: any) => void;
|
|
18
26
|
}) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
27
|
+
/**
|
|
28
|
+
* 熔断器装饰器
|
|
29
|
+
* 类似Spring Cloud CircuitBreaker的@CircuitBreaker注解
|
|
30
|
+
*/
|
|
19
31
|
export declare const HttpCircuitBreaker: (options?: {
|
|
20
32
|
failureThreshold?: number;
|
|
21
33
|
recoveryTimeoutMs?: number;
|
|
22
34
|
monitoringPeriodMs?: number;
|
|
23
35
|
minimumThroughputThreshold?: number;
|
|
24
36
|
}) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
37
|
+
/**
|
|
38
|
+
* HTTP缓存装饰器
|
|
39
|
+
* 集成现有的三层缓存架构
|
|
40
|
+
*/
|
|
25
41
|
export declare const HttpCacheable: (options?: {
|
|
42
|
+
/** 缓存TTL(毫秒) */
|
|
26
43
|
ttl?: number;
|
|
44
|
+
/** 缓存键 */
|
|
27
45
|
key?: string | ((...args: any[]) => string);
|
|
46
|
+
/** 缓存层 */
|
|
28
47
|
layers?: Array<"cls" | "memory" | "redis">;
|
|
48
|
+
/** 缓存条件 */
|
|
29
49
|
condition?: (...args: any[]) => boolean | Promise<boolean>;
|
|
50
|
+
/** 除非条件 */
|
|
30
51
|
unless?: string | ((result: any, args: any[]) => boolean);
|
|
52
|
+
/** 命名空间 */
|
|
31
53
|
namespace?: string;
|
|
32
54
|
}) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
55
|
+
/**
|
|
56
|
+
* 请求日志装饰器
|
|
57
|
+
* 类似Spring Boot的@LogRequest注解
|
|
58
|
+
*/
|
|
33
59
|
export declare const HttpLogRequest: (options?: {
|
|
34
60
|
logHeaders?: boolean;
|
|
35
61
|
logBody?: boolean;
|
|
@@ -40,7 +66,14 @@ export declare const HttpLogRequest: (options?: {
|
|
|
40
66
|
methodName?: string;
|
|
41
67
|
operationName?: string;
|
|
42
68
|
}) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
69
|
+
/**
|
|
70
|
+
* 超时装饰器
|
|
71
|
+
* 类似Spring的@Timeout注解
|
|
72
|
+
*/
|
|
43
73
|
export declare const HttpTimeout: (timeoutMs: number) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
74
|
+
/**
|
|
75
|
+
* 代理装饰器
|
|
76
|
+
*/
|
|
44
77
|
export declare const HttpUseProxy: (options: {
|
|
45
78
|
host: string;
|
|
46
79
|
port: number;
|
|
@@ -50,15 +83,45 @@ export declare const HttpUseProxy: (options: {
|
|
|
50
83
|
password: string;
|
|
51
84
|
};
|
|
52
85
|
}) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
86
|
+
/**
|
|
87
|
+
* 装饰器工具函数
|
|
88
|
+
*/
|
|
53
89
|
export declare class HttpDecoratorUtils {
|
|
90
|
+
/**
|
|
91
|
+
* 获取方法上的重试配置
|
|
92
|
+
*/
|
|
54
93
|
static getRetryOptions(target: any, propertyKey: string): RetryConfig | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* 获取方法上的熔断器配置
|
|
96
|
+
*/
|
|
55
97
|
static getCircuitBreakerOptions(target: any, propertyKey: string): CircuitBreakerConfig | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* 获取方法上的缓存配置
|
|
100
|
+
*/
|
|
56
101
|
static getCacheOptions(target: any, propertyKey: string): HttpCacheConfig | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* 获取方法上的日志配置
|
|
104
|
+
*/
|
|
57
105
|
static getLoggingOptions(target: any, propertyKey: string): any;
|
|
106
|
+
/**
|
|
107
|
+
* 获取方法上的超时配置
|
|
108
|
+
*/
|
|
58
109
|
static getTimeoutOptions(target: any, propertyKey: string): number | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* 获取方法上的代理配置
|
|
112
|
+
*/
|
|
59
113
|
static getProxyOptions(target: any, propertyKey: string): any;
|
|
114
|
+
/**
|
|
115
|
+
* 获取类上的HTTP客户端配置
|
|
116
|
+
*/
|
|
60
117
|
static getHttpClientOptions(target: any): HttpClientConfig;
|
|
118
|
+
/**
|
|
119
|
+
* 获取方法上的调用信息配置
|
|
120
|
+
*/
|
|
61
121
|
static getCallInfoOptions(target: any, propertyKey: string): any;
|
|
122
|
+
/**
|
|
123
|
+
* 获取所有装饰器配置
|
|
124
|
+
*/
|
|
62
125
|
static getAllDecoratorConfigs(target: any, propertyKey: string): {
|
|
63
126
|
retry?: RetryConfig;
|
|
64
127
|
circuitBreaker?: CircuitBreakerConfig;
|