rxtutils 1.1.2-beta.14 → 1.1.2-beta.15

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.
@@ -1,4 +1,4 @@
1
- import { IndexedDBStorage } from './indexDB.js';
1
+ import { IndexedDBStorage } from '../../cache/indexDB.js';
2
2
 
3
3
  /**
4
4
  * 缓存存储类型
@@ -1,7 +1,7 @@
1
1
  export { default as Cache, ICache, ICacheOptions, StorageMap, StorageType } from './cache/index.js';
2
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';
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';
@@ -1,5 +1,6 @@
1
1
  import { AxiosResponse, Method, AxiosRequestConfig } from 'axios';
2
2
  import { StorageType } from '../cache/index.js';
3
+ export { default as RequestError, RequestErrorType } from '../../request/error.js';
3
4
 
4
5
  /**
5
6
  * 错误处理器返回类型
@@ -0,0 +1,2 @@
1
+ export { GetterNameMap, ReducedData, StoreGetter, createStoreGetter, createStoreGetterMemo } from '../../store/createGetter/index.js';
2
+ export { IHookStateInitAction, IHookStateInitialSetter, IHookStateResolvable, IHookStateSetAction, IHookStateSetter, default as createStateStore } from '../../store/createStateStore/index.js';
@@ -0,0 +1,2 @@
1
+ export { BaseValidator } from '../../validator/validator.js';
2
+ export { VArray, VBoolean, VEmail, VMax, VMaxLength, VMin, VMinLength, VNumber, VPattern, VRequired, VString } from '../../validator/decorators.js';
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ var index = require('./createGetter/index.cjs');
4
+ var index$1 = require('./createStateStore/index.cjs');
5
+
6
+
7
+
8
+ exports.createStoreGetter = index.createStoreGetter;
9
+ exports.createStoreGetterMemo = index.createStoreGetterMemo;
10
+ exports.createStateStore = index$1.default;
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ var validator = require('./validator.cjs');
4
+ var decorators = require('./decorators.cjs');
5
+
6
+
7
+
8
+ exports.BaseValidator = validator.BaseValidator;
9
+ exports.VArray = decorators.VArray;
10
+ exports.VBoolean = decorators.VBoolean;
11
+ exports.VEmail = decorators.VEmail;
12
+ exports.VMax = decorators.VMax;
13
+ exports.VMaxLength = decorators.VMaxLength;
14
+ exports.VMin = decorators.VMin;
15
+ exports.VMinLength = decorators.VMinLength;
16
+ exports.VNumber = decorators.VNumber;
17
+ exports.VPattern = decorators.VPattern;
18
+ exports.VRequired = decorators.VRequired;
19
+ exports.VString = decorators.VString;
@@ -0,0 +1,2 @@
1
+ export { createStoreGetter, createStoreGetterMemo } from './createGetter/index.mjs';
2
+ export { default as createStateStore } from './createStateStore/index.mjs';
@@ -0,0 +1,2 @@
1
+ export { BaseValidator } from '../../validator/validator.js';
2
+ export { VArray, VBoolean, VEmail, VMax, VMaxLength, VMin, VMinLength, VNumber, VPattern, VRequired, VString } from '../../validator/decorators.js';
@@ -0,0 +1,2 @@
1
+ export { BaseValidator } from './validator.mjs';
2
+ export { VArray, VBoolean, VEmail, VMax, VMaxLength, VMin, VMinLength, VNumber, VPattern, VRequired, VString } from './decorators.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rxtutils",
3
- "version": "1.1.2-beta.14",
3
+ "version": "1.1.2-beta.15",
4
4
  "type": "module",
5
5
  "main": "cjs/index.cjs",
6
6
  "module": "es/index.mjs",
package/cjs/index.d.ts DELETED
@@ -1,7 +0,0 @@
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';
@@ -1,139 +0,0 @@
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 };
@@ -1,141 +0,0 @@
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 };