rxtutils 1.1.2-beta.12 → 1.1.2-beta.13

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.
@@ -0,0 +1,141 @@
1
+ import { IndexedDBStorage } from './indexDB.js';
2
+
3
+ /**
4
+ * 缓存存储类型
5
+ * - sessionStorage: 会话存储,浏览器关闭后清除
6
+ * - localStorage: 本地存储,永久保存
7
+ * - indexedDB: IndexedDB 数据库存储
8
+ */
9
+ type StorageType = "sessionStorage" | "localStorage" | "indexedDB";
10
+ /**
11
+ * 缓存项接口定义
12
+ * 定义了单个缓存项的数据结构
13
+ *
14
+ * @template Param 缓存参数类型
15
+ * @template Data 缓存数据类型
16
+ */
17
+ interface ICache<Param, Data> {
18
+ /**
19
+ * 缓存的参数
20
+ * 用于标识和查找缓存项
21
+ */
22
+ params: Param;
23
+ /**
24
+ * 缓存的数据
25
+ * 实际存储的内容
26
+ */
27
+ data: Data;
28
+ /**
29
+ * 过期时间
30
+ * - ISO 8601 格式的字符串
31
+ * - 由 moment().add(cacheTime, 'seconds').toJSON() 生成
32
+ * - 示例:'2025-06-12T10:30:00.000Z'
33
+ */
34
+ expireTime: string;
35
+ }
36
+ /**
37
+ * 缓存选项接口
38
+ * @template Param 缓存参数类型
39
+ */
40
+ interface ICacheOptions<Param> {
41
+ /**
42
+ * 存储类型
43
+ * - 'sessionStorage': 会话存储,浏览器关闭后清除
44
+ * - 'localStorage': 本地存储,永久保存
45
+ * - 'indexedDB': IndexedDB 数据库存储
46
+ * - undefined: 仅在内存中缓存(默认值)
47
+ */
48
+ storageType?: StorageType;
49
+ /**
50
+ * 缓存键名
51
+ * - 当使用 localStorage/sessionStorage 时必须提供
52
+ * - 用于在存储中标识不同的缓存数据
53
+ * @default undefined 不使用持久化存储
54
+ */
55
+ cacheKey?: string;
56
+ /**
57
+ * 缓存时间(秒)
58
+ * - 超过这个时间的缓存项会被自动清除
59
+ * @default 60 一分钟
60
+ */
61
+ cacheTime?: number;
62
+ /**
63
+ * 缓存键比较函数
64
+ * - 用于判断两个缓存参数是否相等
65
+ * - 相等则认为是同一个缓存项
66
+ * @param prev 前一个参数
67
+ * @param next 后一个参数
68
+ * @returns 是否相等
69
+ * @default defaultEquals 使用 JSON.stringify 进行比较
70
+ */
71
+ cacheKeyEquals: (prev: Param, next: Param) => boolean;
72
+ /**
73
+ * IndexedDB 数据库名称
74
+ * - 仅在 storageType 为 'indexedDB' 时使用
75
+ * @default '__apiCacheDatabase__'
76
+ */
77
+ indexDBName?: string;
78
+ }
79
+ /** 存储类型映射表 */
80
+ declare const StorageMap: Record<StorageType | string, Storage>;
81
+ /**
82
+ * 缓存类
83
+ * @template Param 缓存参数类型
84
+ * @template Data 缓存数据类型
85
+ */
86
+ declare class Cache<Param, Data> {
87
+ /** 内存中的缓存数组 */
88
+ cache: ICache<Param, Data>[];
89
+ /** 缓存选项 */
90
+ private cacheOptions;
91
+ /** 存储实例 */
92
+ storage?: Storage | IndexedDBStorage;
93
+ /**
94
+ * 构造函数
95
+ * @param cacheType 存储类型
96
+ * @param cacheKey 缓存键名
97
+ * @param cacheTime 缓存时间(秒)
98
+ * @param indexDBName IndexedDB 数据库名称,默认值为 '__apiCacheDatabase__'
99
+ * @param cacheKeyEquals 缓存键比较函数,默认使用 defaultEquals
100
+ */
101
+ constructor(cacheType?: StorageType, cacheKey?: string, cacheTime?: number, indexDBName?: string, cacheKeyEquals?: (prev: Param, next: Param) => boolean);
102
+ /**
103
+ * 初始化缓存
104
+ * 从存储中加载已保存的缓存数据,并进行解析和过期处理
105
+ * @private
106
+ */
107
+ private _init;
108
+ /**
109
+ * 过滤掉已过期的缓存项
110
+ * 通过比较当前时间和过期时间,移除过期的缓存项
111
+ * @private
112
+ */
113
+ private _filterExpired;
114
+ /**
115
+ * 将当前缓存数据保存到存储中
116
+ * 如果设置了缓存键名且存储实例存在,则将缓存数据序列化后保存
117
+ * @private
118
+ */
119
+ private _saveToStorage;
120
+ /**
121
+ * 设置缓存数据
122
+ * @param params 缓存的参数
123
+ * @param data 要缓存的数据
124
+ * @param cacheOptions 可选的缓存配置,可以覆盖默认的缓存时间
125
+ */
126
+ setCache(params: Param, data: Data, cacheOptions?: Omit<ICacheOptions<Param>, "storageType" | "cacheKey" | "cacheKeyEquals">): void;
127
+ /**
128
+ * 获取缓存数据
129
+ * @param params 查询参数
130
+ * @returns 如果找到有效的缓存数据则返回数据,否则返回 null
131
+ */
132
+ getCache(params: Param): Data;
133
+ /**
134
+ * 清空所有缓存数据
135
+ * 清空内存中的缓存数组并同步到存储中
136
+ */
137
+ clear(): void;
138
+ }
139
+
140
+ export { StorageMap, Cache as default };
141
+ export type { ICache, ICacheOptions, StorageType };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * IndexedDB 存储类
3
+ * 提供了对 IndexedDB 数据库操作的简单封装
4
+ */
5
+ declare class IndexedDBStorage {
6
+ /** 数据库名称 */
7
+ private dbName;
8
+ /** 存储对象名称 */
9
+ private storeName;
10
+ /** 数据库连接实例 */
11
+ private db;
12
+ /**
13
+ * 构造函数
14
+ * @param dbName 数据库名称
15
+ * @param storeName 存储对象名称
16
+ */
17
+ constructor(dbName: string, storeName: string);
18
+ /**
19
+ * 打开数据库连接
20
+ * 如果数据库不存在则创建新的数据库和存储对象
21
+ * @private
22
+ * @returns Promise<IDBDatabase> 数据库连接实例
23
+ */
24
+ private _open;
25
+ /**
26
+ * 获取存储对象
27
+ * @param mode 事务模式,默认为只读模式
28
+ * - readonly: 只读模式
29
+ * - readwrite: 读写模式
30
+ * @private
31
+ * @returns Promise<IDBObjectStore> 存储对象实例
32
+ */
33
+ private _getStore;
34
+ /**
35
+ * 设置键值对
36
+ * @param key 键名
37
+ * @param value 要存储的值
38
+ * @returns Promise<void> 存储操作的结果
39
+ * @throws 当存储操作失败时抛出错误
40
+ */
41
+ setItem<T>(key: string, value: T): Promise<void>;
42
+ /**
43
+ * 获取键对应的值
44
+ * @param key 要获取的键名
45
+ * @returns Promise<T> 返回存储的值,如果不存在则返回 undefined
46
+ * @throws 当获取操作失败时抛出错误
47
+ * @template T 存储值的类型,默认为 any
48
+ */
49
+ getItem<T = any>(key: string): Promise<T>;
50
+ }
51
+
52
+ export { IndexedDBStorage };
package/cjs/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { default as Cache, ICache, ICacheOptions, StorageMap, StorageType } from './cache/index.js';
2
+ export { ErrorHandlerReturnType, Options, RequestOptions, default as createBaseRequest } from './request/index.js';
3
+ export { createStoreGetter, createStoreGetterMemo } from './store/createGetter/index.js';
4
+ export { IHookStateInitAction, IHookStateInitialSetter, IHookStateResolvable, IHookStateSetAction, IHookStateSetter, default as createStateStore } from './store/createStateStore/index.js';
5
+ export { BaseValidator } from './validator/validator.js';
6
+ export { VArray, VBoolean, VEmail, VMax, VMaxLength, VMin, VMinLength, VNumber, VPattern, VRequired, VString } from './validator/decorators.js';
7
+ export { default as RequestError, RequestErrorType } from './request/error.js';
@@ -0,0 +1,31 @@
1
+ /**
2
+ * 请求错误类型
3
+ * - server: 服务端业务错误
4
+ * - http: HTTP 网络错误
5
+ */
6
+ type RequestErrorType = 'server' | 'http';
7
+ /**
8
+ * 请求错误类
9
+ * 用于统一处理请求过程中的各种错误
10
+ *
11
+ * @template Data 错误数据类型
12
+ * @extends Error
13
+ */
14
+ declare class RequestError<Data = any> extends Error {
15
+ /** 错误码 */
16
+ code: string;
17
+ /** 错误类型 */
18
+ type: RequestErrorType;
19
+ /** 错误相关的数据 */
20
+ data?: Data;
21
+ /**
22
+ * 构造函数
23
+ * @param message 错误消息
24
+ * @param type 错误类型
25
+ * @param data 错误相关的数据
26
+ */
27
+ constructor(message: string, type: RequestErrorType, data?: Data);
28
+ }
29
+
30
+ export { RequestError as default };
31
+ export type { RequestErrorType };
@@ -0,0 +1,139 @@
1
+ import { AxiosResponse, Method, AxiosRequestConfig } from 'axios';
2
+ import { StorageType } from '../cache/index.js';
3
+
4
+ /**
5
+ * 错误处理器返回类型
6
+ * @template D 响应数据类型
7
+ */
8
+ type ErrorHandlerReturnType<D> = {
9
+ /** 替换响应数据 */
10
+ replaceResData?: D;
11
+ /**
12
+ * 是否抛出错误
13
+ * - true: 强制抛出错误
14
+ * - false: 不抛出错误
15
+ * - 'default': 使用默认错误处理逻辑
16
+ */
17
+ throwError?: boolean | "default";
18
+ };
19
+ /**
20
+ * 请求配置选项接口
21
+ * @template Params 请求参数类型
22
+ * @template Data 响应数据类型
23
+ */
24
+ interface Options<Params = any, Data = any> {
25
+ /** 请求基础URL,默认为空字符串 */
26
+ baseURL?: string;
27
+ /**
28
+ * 是否抛出错误
29
+ * @default true
30
+ */
31
+ throwError?: boolean;
32
+ /**
33
+ * 默认的消息展示函数
34
+ * @default window.alert
35
+ */
36
+ defaultMessageShower?: (message: string) => void;
37
+ /**
38
+ * 是否启用缓存功能
39
+ * @default false
40
+ */
41
+ enableCache?: boolean;
42
+ /**
43
+ * 缓存键比较函数
44
+ * @default defaultEquals 使用 JSON.stringify 进行比较
45
+ */
46
+ cacheKeyEquals?: (prev: Params, next: Params) => boolean;
47
+ /**
48
+ * 是否将响应数据存入缓存
49
+ * @default false
50
+ */
51
+ cacheData?: boolean;
52
+ /**
53
+ * 缓存时间(秒)
54
+ * @default 60
55
+ */
56
+ cacheTime?: number;
57
+ /**
58
+ * 缓存数据的存储类型
59
+ * - localStorage: 使用浏览器本地存储,数据永久保存
60
+ * - sessionStorage: 使用会话存储,关闭浏览器后清除
61
+ * - indexedDB: 使用 IndexedDB 数据库存储
62
+ * - 不填则仅在内存中缓存,页面刷新后清除
63
+ */
64
+ cacheDataInStorage?: StorageType;
65
+ /**
66
+ * 缓存数据的键名
67
+ * @default `${method}:${baseURL}${url}` 默认使用请求方法、基础URL和请求路径组合
68
+ */
69
+ cacheDataKey?: string;
70
+ /**
71
+ * IndexedDB 数据库名称
72
+ * @default '__apiCacheDatabase__'
73
+ */
74
+ indexDBName?: string;
75
+ /**
76
+ * 错误码在响应数据中的路径
77
+ * @default 'code'
78
+ */
79
+ errorCodePath?: string;
80
+ /**
81
+ * 错误码映射表
82
+ * 可以配置错误码对应的错误信息或处理函数
83
+ * @default {} 空对象,使用默认处理函数
84
+ */
85
+ errorCodeMap?: Record<string, string | ((code: string, data: Data, res: AxiosResponse<Data>, requestParam: RequestOptions<Params>) => ErrorHandlerReturnType<Data> | void)>;
86
+ /**
87
+ * 默认错误码处理函数
88
+ * 当错误码不在 errorCodeMap 中时调用
89
+ */
90
+ defaultErrorCodeHandler?: (code: string, data: Data, res: AxiosResponse<Data>) => Promise<ErrorHandlerReturnType<Data> | void>;
91
+ /**
92
+ * 成功状态的错误码列表
93
+ * @default ['0', '200']
94
+ */
95
+ successCodes?: string[];
96
+ /**
97
+ * HTTP 错误码映射表
98
+ * 可以配置 HTTP 状态码对应的错误信息或处理函数
99
+ * @default {} 空对象,使用默认处理函数
100
+ */
101
+ httpErrorCodeMap?: Record<string, string | ((code: number, res: AxiosResponse<Data>, requestParam: RequestOptions<Params>) => Promise<ErrorHandlerReturnType<Data> | void>)>;
102
+ /**
103
+ * 默认 HTTP 错误码处理函数
104
+ * 当 HTTP 状态码不在 httpErrorCodeMap 中时调用
105
+ */
106
+ defaultHttpErrorCodeHandler?: (code: number, error: any) => Promise<ErrorHandlerReturnType<Data> | void>;
107
+ /**
108
+ * 其他错误处理函数
109
+ * 处理非 HTTP 错误和非业务错误码的错误
110
+ */
111
+ otherErrorHandler?: (error: any) => Promise<ErrorHandlerReturnType<Data> | void>;
112
+ axiosOptions?: Omit<AxiosRequestConfig<Params>, "method" | "url" | "params" | "data">;
113
+ }
114
+ /**
115
+ * 请求参数接口
116
+ * @template Param 请求参数类型
117
+ */
118
+ interface RequestOptions<Param> {
119
+ /** HTTP 请求方法 */
120
+ method: Method;
121
+ /** 请求URL */
122
+ url: string;
123
+ /** POST/PUT 等请求的数据 */
124
+ data?: Param;
125
+ /** URL 查询参数 */
126
+ params?: Param;
127
+ }
128
+ /**
129
+ * 创建基础请求实例
130
+ * @param baseOptions 基础配置选项
131
+ * @returns 请求创建函数
132
+ */
133
+ declare function createBaseRequest(baseOptions?: Options): <Param, Data extends Record<any, any>>(requestOptions: RequestOptions<Param>, createOptions?: Omit<Options<Param, Data>, "baseURL">) => {
134
+ (requestParam?: Omit<RequestOptions<Param>, "url" | "method">, options?: Omit<Options<Param, Data>, "baseURL" | "cacheDataKey" | "cacheDataInStorage" | "cacheKeyEquals">): Promise<Data>;
135
+ clearCache(): void;
136
+ };
137
+
138
+ export { createBaseRequest as default };
139
+ export type { ErrorHandlerReturnType, Options, RequestOptions };
@@ -0,0 +1,30 @@
1
+ import createStateStore from '../createStateStore/index.js';
2
+
3
+ type StoreGetter<S = any> = {
4
+ [K in string]: (store: S) => any;
5
+ };
6
+ type GetterNameMap<G extends StoreGetter<any>> = {
7
+ [K in keyof G]: string;
8
+ };
9
+ type ReducedData<G extends StoreGetter<any>, M extends GetterNameMap<G>> = {
10
+ [K in keyof M as M[K]]: G[K extends keyof G ? K : never] extends (store: any) => infer R ? R : never;
11
+ };
12
+ /**
13
+ * 创建 store getter
14
+ * @param store store实例
15
+ * @param getters getter函数
16
+ * @param getterNameMaps 将 getter 函数和 getter 名称一一映射
17
+ * @returns getter object
18
+ */
19
+ declare const createStoreGetter: <S, G extends StoreGetter<S>, M extends GetterNameMap<G>>(store: ReturnType<typeof createStateStore<S>>, getters: G, getterNameMaps: M) => ReducedData<G, M>;
20
+ /**
21
+ *
22
+ * @param store store实例
23
+ * @param getters getter函数
24
+ * @param getterNameMaps 将 getter 函数和 getter 名称一一映射
25
+ * @returns getter memo hook
26
+ */
27
+ declare const createStoreGetterMemo: <S, G extends StoreGetter<S>, M extends GetterNameMap<G>>(store: ReturnType<typeof createStateStore<S>>, getters: G, getterNameMaps: M) => () => ReducedData<G, M>;
28
+
29
+ export { createStoreGetter, createStoreGetterMemo };
30
+ export type { GetterNameMap, ReducedData, StoreGetter };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * 状态初始化设置器类型
3
+ * 用于延迟初始化状态的函数类型
4
+ */
5
+ type IHookStateInitialSetter<S> = () => S;
6
+ /**
7
+ * 状态初始化动作类型
8
+ * 可以是直接的状态值或初始化设置器
9
+ */
10
+ type IHookStateInitAction<S> = S | IHookStateInitialSetter<S>;
11
+ /**
12
+ * 状态设置器类型
13
+ * 可以是接收前一个状态的函数或无参数的函数
14
+ */
15
+ type IHookStateSetter<S> = ((prevState: S) => S) | (() => S);
16
+ /**
17
+ * 状态设置动作类型
18
+ * 可以是直接的状态值或状态设置器
19
+ */
20
+ type IHookStateSetAction<S> = S | IHookStateSetter<S>;
21
+ /**
22
+ * 可解析的状态类型
23
+ * 包含所有可能的状态值或状态设置函数
24
+ */
25
+ type IHookStateResolvable<S> = S | IHookStateInitialSetter<S> | IHookStateSetter<S>;
26
+ /**
27
+ * 创建状态存储
28
+ * 提供一个简单的状态管理解决方案,支持组件间状态共享
29
+ *
30
+ * @template S 状态类型
31
+ * @param initialState 初始状态值或初始化函数
32
+ * @returns 包含状态操作方法的对象
33
+ */
34
+ declare function createStateStore<S>(initialState?: S): {
35
+ use: () => [S, (state: IHookStateSetAction<S>) => void];
36
+ get: () => S;
37
+ set: (state: IHookStateSetAction<S>) => void;
38
+ watch: (callback: (state: S) => S | void) => () => void;
39
+ };
40
+
41
+ export { createStateStore as default };
42
+ export type { IHookStateInitAction, IHookStateInitialSetter, IHookStateResolvable, IHookStateSetAction, IHookStateSetter };
@@ -0,0 +1,159 @@
1
+ import { BaseValidator } from './validator.js';
2
+
3
+ /**
4
+ * 验证器装饰器模块
5
+ * 提供一系列用于数据验证的装饰器,可用于类属性的验证规则定义
6
+ * 这些装饰器基于 BaseValidator 的 decoratorCreator 方法创建
7
+ */
8
+
9
+ /**
10
+ * 必填项验证装饰器
11
+ * 验证值是否存在且不在指定的无效值列表中
12
+ *
13
+ * @param noneVals 被视为无效的值数组,默认为 [undefined]
14
+ * @returns 装饰器工厂函数,可接收自定义错误消息
15
+ *
16
+ * @example
17
+ * class User extends BaseValidator {
18
+ * @(VRequired()('用户名不能为空'))
19
+ * username?: string;
20
+ * }
21
+ */
22
+ declare function VRequired(noneVals?: any[]): (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
23
+ /**
24
+ * 字符串类型验证装饰器
25
+ * 验证值是否为字符串类型
26
+ *
27
+ * @returns 装饰器工厂函数,可接收自定义错误消息
28
+ *
29
+ * @example
30
+ * class User extends BaseValidator {
31
+ * @VString('用户名必须为字符串')
32
+ * username?: string;
33
+ * }
34
+ */
35
+ declare const VString: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
36
+ /**
37
+ * 数字类型验证装饰器
38
+ * 验证值是否为数字类型
39
+ *
40
+ * @returns 装饰器工厂函数,可接收自定义错误消息
41
+ *
42
+ * @example
43
+ * class User extends BaseValidator {
44
+ * @VNumber('年龄必须为数字')
45
+ * age?: number;
46
+ * }
47
+ */
48
+ declare const VNumber: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
49
+ /**
50
+ * 数组类型验证装饰器
51
+ * 验证值是否为数组类型
52
+ *
53
+ * @returns 装饰器工厂函数,可接收自定义错误消息
54
+ *
55
+ * @example
56
+ * class User extends BaseValidator {
57
+ * @VArray('标签必须为数组')
58
+ * tags?: string[];
59
+ * }
60
+ */
61
+ declare const VArray: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
62
+ /**
63
+ * 布尔类型验证装饰器
64
+ * 验证值是否为布尔类型
65
+ *
66
+ * @returns 装饰器工厂函数,可接收自定义错误消息
67
+ *
68
+ * @example
69
+ * class User extends BaseValidator {
70
+ * @VBoolean('状态必须为布尔值')
71
+ * active?: boolean;
72
+ * }
73
+ */
74
+ declare const VBoolean: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
75
+ /**
76
+ * 最小值验证装饰器
77
+ * 验证数字是否大于或等于指定的最小值
78
+ *
79
+ * @param min 最小值
80
+ * @returns 装饰器工厂函数,可接收自定义错误消息
81
+ *
82
+ * @example
83
+ * class User extends BaseValidator {
84
+ * @(VMin(18)('年龄必须大于或等于18岁'))
85
+ * age?: number;
86
+ * }
87
+ */
88
+ declare const VMin: (min: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
89
+ /**
90
+ * 最大值验证装饰器
91
+ * 验证数字是否小于或等于指定的最大值
92
+ *
93
+ * @param max 最大值
94
+ * @returns 装饰器工厂函数,可接收自定义错误消息
95
+ *
96
+ * @example
97
+ * class User extends BaseValidator {
98
+ * @(VMax(120)('年龄必须小于或等于120岁'))
99
+ * age?: number;
100
+ * }
101
+ */
102
+ declare const VMax: (max: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
103
+ /**
104
+ * 最小长度验证装饰器
105
+ * 验证字符串或数组的长度是否大于或等于指定的最小长度
106
+ *
107
+ * @param minLen 最小长度
108
+ * @returns 装饰器工厂函数,可接收自定义错误消息
109
+ *
110
+ * @example
111
+ * class User extends BaseValidator {
112
+ * @(VMinLength(6)('密码长度不能少于6位'))
113
+ * password?: string;
114
+ * }
115
+ */
116
+ declare const VMinLength: (minLen: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
117
+ /**
118
+ * 最大长度验证装饰器
119
+ * 验证字符串或数组的长度是否小于或等于指定的最大长度
120
+ *
121
+ * @param maxLen 最大长度
122
+ * @returns 装饰器工厂函数,可接收自定义错误消息
123
+ *
124
+ * @example
125
+ * class User extends BaseValidator {
126
+ * @(VMaxLength(20)('用户名长度不能超过20位'))
127
+ * username?: string;
128
+ * }
129
+ */
130
+ declare const VMaxLength: (maxLen: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
131
+ /**
132
+ * 邮箱格式验证装饰器
133
+ * 验证字符串是否符合邮箱格式
134
+ *
135
+ * @returns 装饰器工厂函数,可接收自定义错误消息
136
+ *
137
+ * @example
138
+ * class User extends BaseValidator {
139
+ * @VEmail('邮箱格式不正确')
140
+ * email?: string;
141
+ * }
142
+ */
143
+ declare const VEmail: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
144
+ /**
145
+ * 正则表达式验证装饰器
146
+ * 验证字符串是否匹配指定的正则表达式模式
147
+ *
148
+ * @param pattern 正则表达式
149
+ * @returns 装饰器工厂函数,可接收自定义错误消息
150
+ *
151
+ * @example
152
+ * class User extends BaseValidator {
153
+ * @(VPattern(/^1[3-9]\d{9}$/)('手机号格式不正确'))
154
+ * phone?: string;
155
+ * }
156
+ */
157
+ declare const VPattern: (pattern: RegExp) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
158
+
159
+ export { VArray, VBoolean, VEmail, VMax, VMaxLength, VMin, VMinLength, VNumber, VPattern, VRequired, VString };