koatty_validation 1.3.6 → 1.4.0

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/dist/index.d.ts CHANGED
@@ -1,21 +1,27 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2024-11-06 10:51:37
3
+ * @Date: 2025-06-10 23:32:33
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
7
7
  */
8
8
  import { CountryCode } from 'libphonenumber-js';
9
- import { IsIpVersion } from 'class-validator';
10
9
  import { ValidationOptions } from 'class-validator';
11
10
 
12
11
  /**
13
- * Use a custom function for validation
14
- * @param func
15
- * @param validationOptions
16
- * @returns
12
+ * 缓存装饰器 - 用于缓存验证函数结果
13
+ */
14
+ export declare function cached(validator: string, ttl?: number): (target: any, propertyName: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
15
+
16
+ /**
17
+ * 缓存配置选项
17
18
  */
18
- export declare function CheckFunc(func: (value: unknown) => boolean, validationOptions?: ValidationOptions): PropertyDecorator;
19
+ export declare interface CacheOptions {
20
+ max?: number;
21
+ ttl?: number;
22
+ allowStale?: boolean;
23
+ updateAgeOnGet?: boolean;
24
+ }
19
25
 
20
26
  /**
21
27
  * Check the base types.
@@ -32,14 +38,19 @@ export declare function checkParamsType(value: any, type: string): any;
32
38
  export declare const ClassValidator: ValidateClass;
33
39
 
34
40
  /**
35
- * Checks if the string contains the seed.
36
- *
37
- * @export
38
- * @param {string} seed
39
- * @param {ValidationOptions} [validationOptions]
40
- * @returns {PropertyDecorator}
41
+ * 清空所有缓存
41
42
  */
42
- export declare function Contains(seed: string, validationOptions?: ValidationOptions): PropertyDecorator;
43
+ export declare function clearAllCaches(): void;
44
+
45
+ /**
46
+ * 配置缓存设置
47
+ */
48
+ export declare function configureCaches(options: {
49
+ validation?: CacheOptions;
50
+ regex?: CacheOptions;
51
+ }): void;
52
+
53
+ export declare const Contains: (...args: any[]) => (object: Object, propertyName: string) => void;
43
54
 
44
55
  /**
45
56
  * convertDtoParamsType
@@ -59,23 +70,143 @@ export declare function convertDtoParamsType(clazz: any, cls: any): any;
59
70
  */
60
71
  export declare function convertParamsType(param: any, type: string): any;
61
72
 
73
+ /**
74
+ * 创建带参数的验证装饰器
75
+ * @param name 装饰器名称
76
+ * @param validator 验证函数
77
+ * @param defaultMessage 默认错误信息
78
+ * @returns 装饰器工厂函数
79
+ */
80
+ export declare function createParameterizedDecorator(name: string, validator: ValidatorFunction, defaultMessage?: string): (...args: any[]) => (object: Object, propertyName: string) => void;
81
+
82
+ /**
83
+ * 创建简单验证装饰器(不需要额外参数)
84
+ * @param name 装饰器名称
85
+ * @param validator 验证函数
86
+ * @param defaultMessage 默认错误信息
87
+ * @returns 装饰器函数
88
+ */
89
+ export declare function createSimpleDecorator(name: string, validator: ValidatorFunction, defaultMessage?: string): (...args: any[]) => (object: Object, propertyName: string) => void;
90
+
91
+ /**
92
+ * 创建验证装饰器的工厂函数
93
+ * @param options 装饰器配置选项
94
+ * @returns 装饰器工厂函数
95
+ */
96
+ export declare function createValidationDecorator(options: DecoratorOptions): (...args: any[]) => (object: Object, propertyName: string) => void;
97
+
98
+ /**
99
+ * 创建验证错误
100
+ */
101
+ export declare function createValidationError(field: string, value: any, constraint: string, customMessage?: string, context?: Record<string, any>): ValidationErrorDetail;
102
+
103
+ /**
104
+ * 批量创建验证错误
105
+ */
106
+ export declare function createValidationErrors(errors: Array<{
107
+ field: string;
108
+ value: any;
109
+ constraint: string;
110
+ message?: string;
111
+ context?: Record<string, any>;
112
+ }>): KoattyValidationError;
113
+
114
+ /**
115
+ * 装饰器选项
116
+ */
117
+ export declare interface DecoratorOptions {
118
+ name: string;
119
+ validator: ValidatorFunction;
120
+ defaultMessage?: string;
121
+ requiresValue?: boolean;
122
+ }
123
+
62
124
  export declare const ENABLE_VALIDATED = "ENABLE_VALIDATED";
63
125
 
126
+ export declare const Equals: (...args: any[]) => (object: Object, propertyName: string) => void;
127
+
128
+ /**
129
+ * 错误信息国际化
130
+ */
131
+ export declare const ERROR_MESSAGES: {
132
+ readonly zh: {
133
+ readonly IsCnName: "必须是有效的中文姓名";
134
+ readonly IsIdNumber: "必须是有效的身份证号码";
135
+ readonly IsZipCode: "必须是有效的邮政编码";
136
+ readonly IsMobile: "必须是有效的手机号码";
137
+ readonly IsPlateNumber: "必须是有效的车牌号码";
138
+ readonly IsNotEmpty: "不能为空";
139
+ readonly IsDate: "必须是有效的日期";
140
+ readonly IsEmail: "必须是有效的邮箱地址";
141
+ readonly IsIP: "必须是有效的IP地址";
142
+ readonly IsPhoneNumber: "必须是有效的电话号码";
143
+ readonly IsUrl: "必须是有效的URL地址";
144
+ readonly IsHash: "必须是有效的哈希值";
145
+ readonly Equals: "必须等于 {comparison}";
146
+ readonly NotEquals: "不能等于 {comparison}";
147
+ readonly Contains: "必须包含 {seed}";
148
+ readonly IsIn: "必须是以下值之一: {possibleValues}";
149
+ readonly IsNotIn: "不能是以下值之一: {possibleValues}";
150
+ readonly Gt: "必须大于 {min}";
151
+ readonly Gte: "必须大于或等于 {min}";
152
+ readonly Lt: "必须小于 {max}";
153
+ readonly Lte: "必须小于或等于 {max}";
154
+ readonly invalidParameter: "参数 {field} 无效";
155
+ readonly validationFailed: "验证失败";
156
+ };
157
+ readonly en: {
158
+ readonly IsCnName: "must be a valid Chinese name";
159
+ readonly IsIdNumber: "must be a valid ID number";
160
+ readonly IsZipCode: "must be a valid zip code";
161
+ readonly IsMobile: "must be a valid mobile number";
162
+ readonly IsPlateNumber: "must be a valid plate number";
163
+ readonly IsNotEmpty: "should not be empty";
164
+ readonly IsDate: "must be a valid date";
165
+ readonly IsEmail: "must be a valid email";
166
+ readonly IsIP: "must be a valid IP address";
167
+ readonly IsPhoneNumber: "must be a valid phone number";
168
+ readonly IsUrl: "must be a valid URL";
169
+ readonly IsHash: "must be a valid hash";
170
+ readonly Equals: "must equal to {comparison}";
171
+ readonly NotEquals: "should not equal to {comparison}";
172
+ readonly Contains: "must contain {seed}";
173
+ readonly IsIn: "must be one of the following values: {possibleValues}";
174
+ readonly IsNotIn: "should not be one of the following values: {possibleValues}";
175
+ readonly Gt: "must be greater than {min}";
176
+ readonly Gte: "must be greater than or equal to {min}";
177
+ readonly Lt: "must be less than {max}";
178
+ readonly Lte: "must be less than or equal to {max}";
179
+ readonly invalidParameter: "invalid parameter {field}";
180
+ readonly validationFailed: "validation failed";
181
+ };
182
+ };
183
+
64
184
  /**
65
- * Checks if value matches ("===") the comparison.
66
- *
67
- * @export
68
- * @param {*} comparison
69
- * @param {ValidationOptions} [validationOptions]
70
- * @returns {PropertyDecorator}
185
+ * 全局错误信息格式化器实例
71
186
  */
72
- export declare function Equals(comparison: any, validationOptions?: ValidationOptions): PropertyDecorator;
187
+ export declare const errorFormatter: ErrorMessageFormatter;
73
188
 
74
189
  /**
75
- * Marks property as included in the process of transformation.
76
- *
77
- * @export
78
- * @returns {PropertyDecorator}
190
+ * 错误信息格式化器
191
+ */
192
+ export declare class ErrorMessageFormatter {
193
+ constructor(language?: SupportedLanguage);
194
+ /**
195
+ * 设置语言
196
+ */
197
+ setLanguage(language: SupportedLanguage): void;
198
+ /**
199
+ * 格式化错误消息
200
+ */
201
+ formatMessage(constraint: string, field: string, value?: any, context?: Record<string, any>): string;
202
+ /**
203
+ * 格式化值用于消息显示
204
+ * @private
205
+ */
206
+ }
207
+
208
+ /**
209
+ * 标记属性为可导出
79
210
  */
80
211
  export declare function Expose(): PropertyDecorator;
81
212
 
@@ -93,64 +224,57 @@ export declare const FunctionValidator: {
93
224
  };
94
225
 
95
226
  /**
96
- * Checks if the first number is greater than or equal to the min value.
97
- *
98
- * @export
99
- * @param {number} min
100
- * @param {ValidationOptions} [validationOptions]
101
- * @returns {PropertyDecorator}
102
- */
103
- export declare function Gt(min: number, validationOptions?: ValidationOptions): PropertyDecorator;
227
+ * 获取所有缓存统计信息
228
+ */
229
+ export declare function getAllCacheStats(): {
230
+ validation: {
231
+ size: number;
232
+ max: number;
233
+ calculatedSize: number;
234
+ keyCount: number;
235
+ };
236
+ regex: {
237
+ size: number;
238
+ max: number;
239
+ calculatedSize: number;
240
+ };
241
+ performance: Record<string, any>;
242
+ hotspots: {
243
+ name: string;
244
+ avgTime: number;
245
+ count: number;
246
+ }[];
247
+ };
104
248
 
105
- /**
106
- * Checks if the first number is greater than or equal to the min value.
107
- *
108
- * @export
109
- * @param {number} min
110
- * @param {ValidationOptions} [validationOptions]
111
- * @returns {PropertyDecorator}
112
- */
113
- export declare function Gte(min: number, validationOptions?: ValidationOptions): PropertyDecorator;
249
+ export declare const Gt: (...args: any[]) => (object: Object, propertyName: string) => void;
114
250
 
115
- export declare type HashAlgorithm = "md4" | "md5" | "sha1" | "sha256" | "sha384" | "sha512" | "ripemd128" | "ripemd160" | "tiger128" | "tiger160" | "tiger192" | "crc32" | "crc32b";
251
+ export declare const Gte: (...args: any[]) => (object: Object, propertyName: string) => void;
116
252
 
117
253
  /**
118
- * Checks if value is a chinese name.
119
- *
120
- * @export
121
- * @param {string} property
122
- * @param {ValidationOptions} [validationOptions]
123
- * @returns {PropertyDecorator}
254
+ * 哈希算法类型
124
255
  */
125
- export declare function IsCnName(validationOptions?: ValidationOptions): PropertyDecorator;
256
+ export declare type HashAlgorithm = "md4" | "md5" | "sha1" | "sha256" | "sha384" | "sha512" | "ripemd128" | "ripemd160" | "tiger128" | "tiger160" | "tiger192" | "crc32" | "crc32b";
126
257
 
127
- /**
128
- * Checks if a given value is a real date.
129
- *
130
- * @export
131
- * @param {ValidationOptions} [validationOptions]
132
- * @returns {PropertyDecorator}
133
- */
134
- export declare function IsDate(validationOptions?: ValidationOptions): PropertyDecorator;
258
+ export declare const IsCnName: (...args: any[]) => (object: Object, propertyName: string) => void;
259
+
260
+ export declare const IsDate: (...args: any[]) => (object: Object, propertyName: string) => void;
135
261
 
136
262
  /**
137
- * Alias of Expose
138
- *
139
- * @export
140
- * @returns {PropertyDecorator}
263
+ * Expose的别名
141
264
  */
142
265
  export declare function IsDefined(): PropertyDecorator;
143
266
 
267
+ export declare function IsEmail(options?: IsEmailOptions, validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
268
+
144
269
  /**
145
- * Checks if the string is an email. If given value is not a string, then it returns false.
146
- *
147
- * @export
148
- * @param {IsEmailOptions} [options]
149
- * @param {ValidationOptions} [validationOptions]
150
- * @returns {PropertyDecorator}
270
+ * koatty_validation 类型定义
271
+ * @author richen
272
+ * @copyright Copyright (c) - <richenlin(at)gmail.com>
273
+ * @license MIT
274
+ */
275
+ /**
276
+ * 邮箱验证选项
151
277
  */
152
- export declare function IsEmail(options?: IsEmailOptions, validationOptions?: ValidationOptions): PropertyDecorator;
153
-
154
278
  export declare interface IsEmailOptions {
155
279
  allow_display_name?: boolean;
156
280
  require_display_name?: boolean;
@@ -158,109 +282,29 @@ export declare interface IsEmailOptions {
158
282
  require_tld?: boolean;
159
283
  }
160
284
 
161
- /**
162
- * check if the string is a hash of type algorithm. Algorithm is one of ['md4', 'md5', 'sha1', 'sha256',
163
- * 'sha384', 'sha512', 'ripemd128', 'ripemd160', 'tiger128', 'tiger160', 'tiger192', 'crc32', 'crc32b']
164
- *
165
- * @export
166
- * @param {HashAlgorithm} algorithm
167
- * @param {ValidationOptions} [validationOptions]
168
- * @returns {PropertyDecorator}
169
- */
170
- export declare function IsHash(algorithm: HashAlgorithm, validationOptions?: ValidationOptions): PropertyDecorator;
285
+ export declare function IsHash(algorithm: HashAlgorithm, validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
171
286
 
172
- /**
173
- * Checks if value is a idCard number(chinese).
174
- *
175
- * @export
176
- * @param {string} property
177
- * @param {ValidationOptions} [validationOptions]
178
- * @returns {PropertyDecorator}
179
- */
180
- export declare function IsIdNumber(validationOptions?: ValidationOptions): PropertyDecorator;
287
+ export declare const IsIdNumber: (...args: any[]) => (object: Object, propertyName: string) => void;
181
288
 
182
- /**
183
- * Checks if given value is in a array of allowed values.
184
- *
185
- * @export
186
- * @param {any[]} possibleValues
187
- * @param {ValidationOptions} [validationOptions]
188
- * @returns {PropertyDecorator}
189
- */
190
- export declare function IsIn(possibleValues: any[], validationOptions?: ValidationOptions): PropertyDecorator;
289
+ export declare const IsIn: (...args: any[]) => (object: Object, propertyName: string) => void;
191
290
 
192
- /**
193
- * Checks if the string is an IP (version 4 or 6). If given value is not a string, then it returns false.
194
- *
195
- * @export
196
- * @param {number} [version]
197
- * @param {ValidationOptions} [validationOptions]
198
- * @returns {PropertyDecorator}
199
- */
200
- export declare function IsIP(version?: IsIpVersion, validationOptions?: ValidationOptions): PropertyDecorator;
291
+ export declare function IsIP(version?: any, validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
201
292
 
202
- /**
203
- * Checks if value is a mobile phone number(chinese).
204
- *
205
- * @export
206
- * @param {string} property
207
- * @param {ValidationOptions} [validationOptions]
208
- * @returns {PropertyDecorator}
209
- */
210
- export declare function IsMobile(validationOptions?: ValidationOptions): PropertyDecorator;
293
+ export declare const IsMobile: (...args: any[]) => (object: Object, propertyName: string) => void;
211
294
 
212
- /**
213
- * Checks value is not empty, undefined, null, '', NaN, [], {} and any empty string(including spaces, tabs, formfeeds, etc.), returns false.
214
- *
215
- * @export
216
- * @param {ValidationOptions} [validationOptions]
217
- * @returns {PropertyDecorator}
218
- */
219
- export declare function IsNotEmpty(validationOptions?: ValidationOptions): PropertyDecorator;
295
+ export declare const IsNotEmpty: (...args: any[]) => (object: Object, propertyName: string) => void;
220
296
 
221
- /**
222
- * Checks if given value not in a array of allowed values.
223
- *
224
- * @export
225
- * @param {any[]} possibleValues
226
- * @param {ValidationOptions} [validationOptions]
227
- * @returns {PropertyDecorator}
228
- */
229
- export declare function IsNotIn(possibleValues: any[], validationOptions?: ValidationOptions): PropertyDecorator;
297
+ export declare const IsNotIn: (...args: any[]) => (object: Object, propertyName: string) => void;
230
298
 
231
- /**
232
- * Checks if the string is a valid phone number.
233
- *
234
- * @export
235
- * @param {string} {string} region 2 characters uppercase country code (e.g. DE, US, CH).
236
- * If users must enter the intl. prefix (e.g. +41), then you may pass "ZZ" or null as region.
237
- * See [google-libphonenumber, metadata.js:countryCodeToRegionCodeMap on github]
238
- * {@link https://github.com/ruimarinho/google-libphonenumber/blob/1e46138878cff479aafe2ce62175c6c49cb58720/src/metadata.js#L33}
239
- * @param {ValidationOptions} [validationOptions]
240
- * @returns {PropertyDecorator}
241
- */
242
- export declare function IsPhoneNumber(region?: CountryCode, validationOptions?: ValidationOptions): PropertyDecorator;
299
+ export declare function IsPhoneNumber(region?: CountryCode, validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
243
300
 
244
- /**
245
- * Checks if value is a plate number(chinese).
246
- *
247
- * @export
248
- * @param {string} property
249
- * @param {ValidationOptions} [validationOptions]
250
- * @returns {PropertyDecorator}
251
- */
252
- export declare function IsPlateNumber(validationOptions?: ValidationOptions): PropertyDecorator;
301
+ export declare const IsPlateNumber: (...args: any[]) => (object: Object, propertyName: string) => void;
302
+
303
+ export declare function IsUrl(options?: IsURLOptions, validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
253
304
 
254
305
  /**
255
- * Checks if the string is an url.
256
- *
257
- * @export
258
- * @param {IsURLOptions} [options]
259
- * @param {ValidationOptions} [validationOptions]
260
- * @returns {PropertyDecorator}
306
+ * URL验证选项
261
307
  */
262
- export declare function IsUrl(options?: IsURLOptions, validationOptions?: ValidationOptions): PropertyDecorator;
263
-
264
308
  export declare interface IsURLOptions {
265
309
  protocols?: string[];
266
310
  require_tld?: boolean;
@@ -275,64 +319,75 @@ export declare interface IsURLOptions {
275
319
  disallow_auth?: boolean;
276
320
  }
277
321
 
278
- /**
279
- * Checks if value is a zipCode(chinese).
280
- *
281
- * @export
282
- * @param {string} property
283
- * @param {ValidationOptions} [validationOptions]
284
- * @returns {PropertyDecorator}
285
- */
286
- export declare function IsZipCode(validationOptions?: ValidationOptions): PropertyDecorator;
322
+ export declare const IsZipCode: (...args: any[]) => (object: Object, propertyName: string) => void;
287
323
 
288
324
  /**
289
- * Checks if the string's length falls in a range. Note: this function takes into account surrogate pairs.
290
- * If given value is not a string, then it returns false.
291
- *
292
- * @export
293
- * @param {number} min
294
- * @param {number} [max]
295
- * @param {ValidationOptions} [validationOptions]
296
- * @returns {PropertyDecorator}
325
+ * 增强的验证错误类
297
326
  */
298
- export declare function Length(min: number, max?: number, validationOptions?: ValidationOptions): PropertyDecorator;
327
+ export declare class KoattyValidationError extends Error {
328
+ readonly errors: ValidationErrorDetail[];
329
+ readonly statusCode: number;
330
+ readonly timestamp: Date;
331
+ constructor(errors: ValidationErrorDetail[], message?: string);
332
+ /**
333
+ * 获取第一个错误信息
334
+ */
335
+ getFirstError(): ValidationErrorDetail | undefined;
336
+ /**
337
+ * 获取指定字段的错误
338
+ */
339
+ getFieldErrors(field: string): ValidationErrorDetail[];
340
+ /**
341
+ * 转换为JSON格式
342
+ */
343
+ toJSON(): {
344
+ name: string;
345
+ message: string;
346
+ statusCode: number;
347
+ timestamp: Date;
348
+ errors: ValidationErrorDetail[];
349
+ };
350
+ }
299
351
 
300
- /**
301
- * Checks if the first number is less than or equal to the max value.
302
- *
303
- * @export
304
- * @param {number} max
305
- * @param {ValidationOptions} [validationOptions]
306
- * @returns {PropertyDecorator}
307
- */
308
- export declare function Lt(max: number, validationOptions?: ValidationOptions): PropertyDecorator;
352
+ export declare const Lt: (...args: any[]) => (object: Object, propertyName: string) => void;
309
353
 
310
- /**
311
- * Checks if the first number is less than or equal to the max value.
312
- *
313
- * @export
314
- * @param {number} max
315
- * @param {ValidationOptions} [validationOptions]
316
- * @returns {PropertyDecorator}
317
- */
318
- export declare function Lte(max: number, validationOptions?: ValidationOptions): PropertyDecorator;
354
+ export declare const Lte: (...args: any[]) => (object: Object, propertyName: string) => void;
319
355
 
320
356
  /**
321
- * Checks if value does not match ("!==") the comparison.
322
- *
323
- * @export
324
- * @param {*} comparison
325
- * @param {ValidationOptions} [validationOptions]
326
- * @returns {PropertyDecorator}
357
+ * 元数据缓存
327
358
  */
328
- export declare function NotEquals(comparison: any, validationOptions?: ValidationOptions): PropertyDecorator;
359
+ declare class MetadataCache {
360
+ static getInstance(): MetadataCache;
361
+ /**
362
+ * 获取类的元数据缓存
363
+ */
364
+ getClassCache(target: Function): Map<string, any>;
365
+ /**
366
+ * 缓存元数据
367
+ */
368
+ setMetadata(target: Function, key: string, value: any): void;
369
+ /**
370
+ * 获取缓存的元数据
371
+ */
372
+ getMetadata(target: Function, key: string): any;
373
+ /**
374
+ * 检查是否已缓存
375
+ */
376
+ hasMetadata(target: Function, key: string): boolean;
377
+ /**
378
+ * 清空指定类的缓存
379
+ */
380
+ clearClassCache(target: Function): void;
381
+ }
382
+
383
+ export declare const metadataCache: MetadataCache;
384
+
385
+ export declare const NotEquals: (...args: any[]) => (object: Object, propertyName: string) => void;
329
386
 
330
387
  export declare const PARAM_CHECK_KEY = "PARAM_CHECK_KEY";
331
388
 
332
389
  export declare const PARAM_RULE_KEY = "PARAM_RULE_KEY";
333
390
 
334
- export declare const PARAM_TYPE_KEY = "PARAM_TYPE_KEY";
335
-
336
391
  /**
337
392
  * paramterTypes
338
393
  *
@@ -362,6 +417,42 @@ export declare enum paramterTypes {
362
417
  "undefined" = 19
363
418
  }
364
419
 
420
+ /**
421
+ * 性能监控
422
+ */
423
+ declare class PerformanceMonitor {
424
+ static getInstance(): PerformanceMonitor;
425
+ /**
426
+ * 开始计时
427
+ */
428
+ startTimer(name: string): () => void;
429
+ /**
430
+ * 记录性能指标
431
+ */
432
+ /**
433
+ * 获取性能报告
434
+ */
435
+ getReport(): Record<string, any>;
436
+ /**
437
+ * 获取热点分析(执行时间最长的操作)
438
+ */
439
+ getHotspots(limit?: number): Array<{
440
+ name: string;
441
+ avgTime: number;
442
+ count: number;
443
+ }>;
444
+ /**
445
+ * 清空指标
446
+ */
447
+ clear(): void;
448
+ /**
449
+ * 导出性能数据为CSV格式
450
+ */
451
+ exportToCSV(): string;
452
+ }
453
+
454
+ export declare const performanceMonitor: PerformanceMonitor;
455
+
365
456
  /**
366
457
  * plain object convert to class instance
367
458
  *
@@ -374,13 +465,54 @@ export declare enum paramterTypes {
374
465
  export declare function plainToClass(clazz: any, data: any, convert?: boolean): any;
375
466
 
376
467
  /**
377
- * Validation parameter's type and values.
378
- *
379
- * @export
380
- * @param {(ValidRules | ValidRules[] | Function)} rule
381
- * @param {*} [options] If the options type is a string, the value is the error message of the validation rule.
382
- * Some validation rules require additional parameters, ext: @Valid("Gte", {message:"Requires value greater than or equal to 100", value: 100})
383
- * @returns {*} {ParameterDecorator}
468
+ * 正则表达式缓存
469
+ */
470
+ declare class RegexCache {
471
+ constructor(options?: CacheOptions);
472
+ static getInstance(options?: CacheOptions): RegexCache;
473
+ /**
474
+ * 获取缓存的正则表达式
475
+ */
476
+ get(pattern: string, flags?: string): RegExp;
477
+ /**
478
+ * 预编译常用正则表达式
479
+ */
480
+ precompile(patterns: Array<{
481
+ pattern: string;
482
+ flags?: string;
483
+ }>): void;
484
+ /**
485
+ * 获取缓存统计
486
+ */
487
+ getStats(): {
488
+ size: number;
489
+ max: number;
490
+ calculatedSize: number;
491
+ };
492
+ /**
493
+ * 清空缓存
494
+ */
495
+ clear(): void;
496
+ }
497
+
498
+ export declare const regexCache: RegexCache;
499
+
500
+ /**
501
+ * 设置全局语言
502
+ */
503
+ export declare function setValidationLanguage(language: SupportedLanguage): void;
504
+
505
+ /**
506
+ * 改进的错误处理机制
507
+ * @author richen
508
+ */
509
+ /**
510
+ * 支持的语言
511
+ */
512
+ export declare type SupportedLanguage = 'zh' | 'en';
513
+
514
+ /**
515
+ * 参数验证装饰器
384
516
  */
385
517
  export declare function Valid(rule: ValidRules | ValidRules[] | Function, options?: string | ValidOtpions): ParameterDecorator;
386
518
 
@@ -406,13 +538,75 @@ declare class ValidateClass {
406
538
  }
407
539
 
408
540
  /**
409
- * Validation parameter's type and values from DTO class.
410
- *
411
- * @export
412
- * @returns {MethodDecorator}
541
+ * 方法验证装饰器
413
542
  */
414
543
  export declare function Validated(): MethodDecorator;
415
544
 
545
+ /**
546
+ * 验证结果缓存
547
+ */
548
+ declare class ValidationCache {
549
+ constructor(options?: CacheOptions);
550
+ static getInstance(options?: CacheOptions): ValidationCache;
551
+ /**
552
+ * 生成缓存键
553
+ */
554
+ /**
555
+ * 序列化值用于缓存键
556
+ */
557
+ /**
558
+ * 获取缓存的验证结果
559
+ */
560
+ get(validator: string, value: any, ...args: any[]): boolean | undefined;
561
+ /**
562
+ * 缓存验证结果
563
+ */
564
+ set(validator: string, value: any, result: boolean, ...args: any[]): void;
565
+ /**
566
+ * 检查是否存在缓存
567
+ */
568
+ has(validator: string, value: any, ...args: any[]): boolean;
569
+ /**
570
+ * 删除特定缓存
571
+ */
572
+ delete(validator: string, value: any, ...args: any[]): boolean;
573
+ /**
574
+ * 清空缓存
575
+ */
576
+ clear(): void;
577
+ /**
578
+ * 获取缓存统计
579
+ */
580
+ getStats(): {
581
+ size: number;
582
+ max: number;
583
+ calculatedSize: number;
584
+ keyCount: number;
585
+ };
586
+ /**
587
+ * 设置缓存TTL
588
+ */
589
+ setTTL(validator: string, value: any, ttl: number, ...args: any[]): void;
590
+ }
591
+
592
+ export declare const validationCache: ValidationCache;
593
+
594
+ /**
595
+ * 验证错误详情
596
+ */
597
+ export declare interface ValidationErrorDetail {
598
+ field: string;
599
+ value: any;
600
+ constraint: string;
601
+ message: string;
602
+ context?: Record<string, any>;
603
+ }
604
+
605
+ /**
606
+ * 验证函数类型定义
607
+ */
608
+ export declare type ValidatorFunction = (value: any, ...args: any[]) => boolean;
609
+
416
610
  /**
417
611
  * Validator Functions
418
612
  */
@@ -425,7 +619,7 @@ export declare const ValidFuncs: {
425
619
  /**
426
620
  * Checks if a given value is a real date.
427
621
  */
428
- IsDate: (value: unknown) => boolean;
622
+ IsDate: (value: unknown) => value is Date;
429
623
  /**
430
624
  * Checks if the string is an email. If given value is not a string, then it returns false.
431
625
  */
@@ -510,6 +704,9 @@ export declare const ValidFuncs: {
510
704
  Lte: (num: unknown, max: number) => boolean;
511
705
  };
512
706
 
707
+ /**
708
+ * 验证选项
709
+ */
513
710
  export declare type ValidOtpions = {
514
711
  message: string;
515
712
  value: any;
@@ -523,4 +720,9 @@ export declare type ValidOtpions = {
523
720
  */
524
721
  export declare type ValidRules = "IsNotEmpty" | "IsDate" | "IsEmail" | "IsIP" | "IsPhoneNumber" | "IsUrl" | "IsHash" | "IsCnName" | "IsIdNumber" | "IsZipCode" | "IsMobile" | "IsPlateNumber" | "Equals" | "NotEquals" | "Contains" | "IsIn" | "IsNotIn" | "Gt" | "Lt" | "Gte" | "Lte";
525
722
 
723
+ /**
724
+ * 预热缓存 - 预编译常用正则表达式
725
+ */
726
+ export declare function warmupCaches(): void;
727
+
526
728
  export { }