rxtutils 1.1.4-beta.9 → 1.1.6

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.
Files changed (64) hide show
  1. package/README.md +117 -49
  2. package/cjs/_utils/defaultEquals.cjs +4 -19
  3. package/cjs/cache/index.cjs +130 -163
  4. package/cjs/cache/indexDB.cjs +86 -99
  5. package/cjs/downloadBlob.cjs +14 -0
  6. package/cjs/hooks/index.cjs +3 -6
  7. package/cjs/hooks/useCombineControlValue.cjs +33 -41
  8. package/cjs/index.cjs +16 -17
  9. package/cjs/request/defaultHandlers.cjs +5 -27
  10. package/cjs/request/error.cjs +18 -30
  11. package/cjs/request/index.cjs +194 -174
  12. package/cjs/store/createGetter/index.cjs +26 -40
  13. package/cjs/store/createStateStore/index.cjs +47 -90
  14. package/cjs/store/index.cjs +4 -7
  15. package/cjs/validator/decorators.cjs +71 -228
  16. package/cjs/validator/index.cjs +4 -7
  17. package/cjs/validator/validator.cjs +101 -177
  18. package/es/_utils/defaultEquals.mjs +4 -17
  19. package/es/cache/index.d.ts +9 -13
  20. package/es/cache/index.mjs +132 -160
  21. package/es/cache/indexDB.d.ts +1 -3
  22. package/es/cache/indexDB.mjs +87 -98
  23. package/es/downloadBlob.d.ts +8 -0
  24. package/es/downloadBlob.mjs +14 -0
  25. package/es/hooks/index.d.ts +1 -1
  26. package/es/hooks/index.mjs +4 -1
  27. package/es/hooks/useCombineControlValue.d.ts +5 -8
  28. package/es/hooks/useCombineControlValue.mjs +34 -40
  29. package/es/index.d.ts +28 -8
  30. package/es/index.mjs +29 -7
  31. package/es/request/defaultHandlers.d.ts +24 -0
  32. package/es/request/defaultHandlers.mjs +8 -26
  33. package/es/request/error.d.ts +3 -6
  34. package/es/request/error.mjs +18 -28
  35. package/es/request/index.d.ts +32 -20
  36. package/es/request/index.mjs +194 -172
  37. package/es/store/createGetter/index.d.ts +6 -10
  38. package/es/store/createGetter/index.mjs +28 -39
  39. package/es/store/createStateStore/index.d.ts +9 -9
  40. package/es/store/createStateStore/index.mjs +49 -87
  41. package/es/store/index.d.ts +4 -2
  42. package/es/store/index.mjs +7 -2
  43. package/es/validator/decorators.d.ts +12 -21
  44. package/es/validator/decorators.mjs +81 -226
  45. package/es/validator/index.d.ts +2 -2
  46. package/es/validator/index.mjs +16 -2
  47. package/es/validator/validator.d.ts +5 -6
  48. package/es/validator/validator.mjs +102 -176
  49. package/package.json +85 -15
  50. package/cjs/_utils/deepAssign.cjs +0 -25
  51. package/cjs/cache/index.d.ts +0 -141
  52. package/cjs/cache/indexDB.d.ts +0 -52
  53. package/cjs/hooks/index.d.ts +0 -1
  54. package/cjs/hooks/useCombineControlValue.d.ts +0 -21
  55. package/cjs/index.d.ts +0 -8
  56. package/cjs/request/error.d.ts +0 -31
  57. package/cjs/request/index.d.ts +0 -147
  58. package/cjs/store/createGetter/index.d.ts +0 -30
  59. package/cjs/store/createStateStore/index.d.ts +0 -42
  60. package/cjs/store/index.d.ts +0 -2
  61. package/cjs/validator/decorators.d.ts +0 -159
  62. package/cjs/validator/index.d.ts +0 -2
  63. package/cjs/validator/validator.d.ts +0 -84
  64. package/es/_utils/deepAssign.mjs +0 -23
@@ -1,12 +1,11 @@
1
- import { IndexedDBStorage } from './indexDB.js';
2
-
1
+ import { IndexedDBStorage } from './indexDB';
3
2
  /**
4
3
  * 缓存存储类型
5
4
  * - sessionStorage: 会话存储,浏览器关闭后清除
6
5
  * - localStorage: 本地存储,永久保存
7
6
  * - indexedDB: IndexedDB 数据库存储
8
7
  */
9
- type StorageType = "sessionStorage" | "localStorage" | "indexedDB";
8
+ export type StorageType = 'sessionStorage' | 'localStorage' | 'indexedDB';
10
9
  /**
11
10
  * 缓存项接口定义
12
11
  * 定义了单个缓存项的数据结构
@@ -14,7 +13,7 @@ type StorageType = "sessionStorage" | "localStorage" | "indexedDB";
14
13
  * @template Param 缓存参数类型
15
14
  * @template Data 缓存数据类型
16
15
  */
17
- interface ICache<Param, Data> {
16
+ export interface ICache<Param, Data> {
18
17
  /**
19
18
  * 缓存的参数
20
19
  * 用于标识和查找缓存项
@@ -28,7 +27,7 @@ interface ICache<Param, Data> {
28
27
  /**
29
28
  * 过期时间
30
29
  * - ISO 8601 格式的字符串
31
- * - 由 moment().add(cacheTime, 'seconds').toJSON() 生成
30
+ * - 由 addSeconds(new Date(), cacheTime).toISOString() 生成
32
31
  * - 示例:'2025-06-12T10:30:00.000Z'
33
32
  */
34
33
  expireTime: string;
@@ -37,7 +36,7 @@ interface ICache<Param, Data> {
37
36
  * 缓存选项接口
38
37
  * @template Param 缓存参数类型
39
38
  */
40
- interface ICacheOptions<Param> {
39
+ export interface ICacheOptions<Param> {
41
40
  /**
42
41
  * 存储类型
43
42
  * - 'sessionStorage': 会话存储,浏览器关闭后清除
@@ -77,13 +76,13 @@ interface ICacheOptions<Param> {
77
76
  indexDBName?: string;
78
77
  }
79
78
  /** 存储类型映射表 */
80
- declare const StorageMap: Record<StorageType | string, Storage>;
79
+ export declare const StorageMap: Record<StorageType | string, Storage>;
81
80
  /**
82
81
  * 缓存类
83
82
  * @template Param 缓存参数类型
84
83
  * @template Data 缓存数据类型
85
84
  */
86
- declare class Cache<Param, Data> {
85
+ export default class Cache<Param, Data> {
87
86
  /** 内存中的缓存数组 */
88
87
  cache: ICache<Param, Data>[];
89
88
  /** 缓存选项 */
@@ -123,19 +122,16 @@ declare class Cache<Param, Data> {
123
122
  * @param data 要缓存的数据
124
123
  * @param cacheOptions 可选的缓存配置,可以覆盖默认的缓存时间
125
124
  */
126
- setCache(params: Param, data: Data, cacheOptions?: Omit<ICacheOptions<Param>, "storageType" | "cacheKey" | "cacheKeyEquals">): void;
125
+ setCache(params: Param, data: Data, cacheOptions?: Omit<ICacheOptions<Param>, 'storageType' | 'cacheKey' | 'cacheKeyEquals'>): void;
127
126
  /**
128
127
  * 获取缓存数据
129
128
  * @param params 查询参数
130
129
  * @returns 如果找到有效的缓存数据则返回数据,否则返回 null
131
130
  */
132
- getCache(params: Param): Data;
131
+ getCache(params: Param): Data | null;
133
132
  /**
134
133
  * 清空所有缓存数据
135
134
  * 清空内存中的缓存数组并同步到存储中
136
135
  */
137
136
  clear(): void;
138
137
  }
139
-
140
- export { StorageMap, Cache as default };
141
- export type { ICache, ICacheOptions, StorageType };
@@ -1,165 +1,137 @@
1
- import { __awaiter, __generator, __assign } from 'tslib';
2
- import moment from 'moment';
3
- import { IndexedDBStorage } from './indexDB.mjs';
4
- import defaultEquals from '../_utils/defaultEquals.mjs';
5
-
6
- /** 存储类型映射表 */
7
- var StorageMap = {
8
- localStorage: localStorage,
9
- sessionStorage: sessionStorage,
1
+ import { isAfter, parseISO, addSeconds } from "date-fns";
2
+ import { IndexedDBStorage } from "./indexDB.mjs";
3
+ import defaultEquals from "../_utils/defaultEquals.mjs";
4
+ const StorageMap = {
5
+ localStorage,
6
+ sessionStorage
10
7
  };
11
- /**
12
- * 缓存类
13
- * @template Param 缓存参数类型
14
- * @template Data 缓存数据类型
15
- */
16
- var Cache = /** @class */ (function () {
17
- /**
18
- * 构造函数
19
- * @param cacheType 存储类型
20
- * @param cacheKey 缓存键名
21
- * @param cacheTime 缓存时间(秒)
22
- * @param indexDBName IndexedDB 数据库名称,默认值为 '__apiCacheDatabase__'
23
- * @param cacheKeyEquals 缓存键比较函数,默认使用 defaultEquals
24
- */
25
- function Cache(cacheType, cacheKey, cacheTime, indexDBName, cacheKeyEquals) {
26
- if (indexDBName === void 0) { indexDBName = "__apiCacheDatabase__"; }
27
- if (cacheKeyEquals === void 0) { cacheKeyEquals = defaultEquals; }
28
- /** 内存中的缓存数组 */
29
- this.cache = [];
30
- this.cacheOptions = {
31
- storageType: cacheType,
32
- cacheKey: cacheKey,
33
- cacheTime: cacheTime,
34
- indexDBName: indexDBName,
35
- cacheKeyEquals: cacheKeyEquals,
36
- };
37
- if (cacheType === "indexedDB") {
38
- this.storage = new IndexedDBStorage(indexDBName, "cacheStore");
39
- }
40
- else if (typeof cacheType === "string") {
41
- this.storage = StorageMap[cacheType];
42
- }
43
- this._init();
44
- }
45
- /**
46
- * 初始化缓存
47
- * 从存储中加载已保存的缓存数据,并进行解析和过期处理
48
- * @private
49
- */
50
- Cache.prototype._init = function () {
51
- return __awaiter(this, void 0, void 0, function () {
52
- var _a, cacheType, cacheKey, _b, _c, _d;
53
- return __generator(this, function (_e) {
54
- switch (_e.label) {
55
- case 0:
56
- _a = this.cacheOptions, cacheType = _a.storageType, cacheKey = _a.cacheKey;
57
- if (!(this.storage instanceof IndexedDBStorage)) return [3 /*break*/, 2];
58
- _b = this;
59
- _d = (_c = JSON).parse;
60
- return [4 /*yield*/, this.storage.getItem(cacheKey)];
61
- case 1:
62
- _b.cache = _d.apply(_c, [(_e.sent()) || "[]"]);
63
- return [3 /*break*/, 3];
64
- case 2:
65
- if (this.storage instanceof Storage) {
66
- this.storage = StorageMap[cacheType];
67
- if (this.storage) {
68
- if (typeof cacheKey === "string") {
69
- try {
70
- this.cache = JSON.parse(this.storage.getItem(cacheKey) || "[]");
71
- }
72
- catch (e) {
73
- this.cache = [];
74
- console.error("\u7F13\u5B58\u6570\u636E\u89E3\u6790\u5931\u8D25\uFF0Ckey:".concat(cacheKey));
75
- }
76
- }
77
- }
78
- }
79
- _e.label = 3;
80
- case 3:
81
- this._filterExpired();
82
- this._saveToStorage();
83
- return [2 /*return*/];
84
- }
85
- });
86
- });
87
- };
88
- /**
89
- * 过滤掉已过期的缓存项
90
- * 通过比较当前时间和过期时间,移除过期的缓存项
91
- * @private
92
- */
93
- Cache.prototype._filterExpired = function () {
94
- var newCache = this.cache.filter(function (item) {
95
- return moment(item.expireTime).isAfter(moment());
96
- });
97
- this.cache = newCache;
98
- };
99
- /**
100
- * 将当前缓存数据保存到存储中
101
- * 如果设置了缓存键名且存储实例存在,则将缓存数据序列化后保存
102
- * @private
103
- */
104
- Cache.prototype._saveToStorage = function () {
105
- if (this.storage) {
106
- if (typeof this.cacheOptions.cacheKey === "string") {
107
- this.storage.setItem(this.cacheOptions.cacheKey, JSON.stringify(this.cache));
108
- }
109
- }
110
- };
111
- /**
112
- * 设置缓存数据
113
- * @param params 缓存的参数
114
- * @param data 要缓存的数据
115
- * @param cacheOptions 可选的缓存配置,可以覆盖默认的缓存时间
116
- */
117
- Cache.prototype.setCache = function (params, data, cacheOptions) {
118
- var _a = __assign(__assign({}, this.cacheOptions), cacheOptions), cacheTime = _a.cacheTime, _b = _a.cacheKeyEquals, cacheKeyEquals = _b === void 0 ? defaultEquals : _b;
119
- var cacheItemIndex = this.cache.findIndex(function (item) {
120
- return cacheKeyEquals(item.params, params);
121
- });
122
- if (cacheItemIndex > -1) {
123
- this.cache.splice(cacheItemIndex, 1);
124
- }
125
- this.cache.push({
126
- params: params,
127
- data: data,
128
- expireTime: moment().add(cacheTime, "seconds").toJSON(),
129
- });
130
- this._saveToStorage();
8
+ class Cache {
9
+ /**
10
+ * 构造函数
11
+ * @param cacheType 存储类型
12
+ * @param cacheKey 缓存键名
13
+ * @param cacheTime 缓存时间(秒)
14
+ * @param indexDBName IndexedDB 数据库名称,默认值为 '__apiCacheDatabase__'
15
+ * @param cacheKeyEquals 缓存键比较函数,默认使用 defaultEquals
16
+ */
17
+ constructor(cacheType, cacheKey, cacheTime, indexDBName = "__apiCacheDatabase__", cacheKeyEquals = defaultEquals) {
18
+ this.cache = [];
19
+ this.cacheOptions = {
20
+ storageType: cacheType,
21
+ cacheKey,
22
+ cacheTime,
23
+ indexDBName,
24
+ cacheKeyEquals
131
25
  };
132
- /**
133
- * 获取缓存数据
134
- * @param params 查询参数
135
- * @returns 如果找到有效的缓存数据则返回数据,否则返回 null
136
- */
137
- Cache.prototype.getCache = function (params) {
138
- var _this = this;
139
- var itemIndex = this.cache.findIndex(function (item) {
140
- return _this.cacheOptions.cacheKeyEquals(item.params, params);
141
- });
142
- var item = this.cache[itemIndex];
143
- if (item) {
144
- if (moment(item.expireTime).isAfter(moment())) {
145
- return item.data;
146
- }
147
- else {
148
- this.cache.splice(itemIndex, 1);
149
- this._saveToStorage();
150
- }
26
+ if (cacheType === "indexedDB") {
27
+ this.storage = new IndexedDBStorage(indexDBName, "cacheStore");
28
+ } else if (typeof cacheType === "string") {
29
+ this.storage = StorageMap[cacheType];
30
+ }
31
+ this._init();
32
+ }
33
+ /**
34
+ * 初始化缓存
35
+ * 从存储中加载已保存的缓存数据,并进行解析和过期处理
36
+ * @private
37
+ */
38
+ async _init() {
39
+ const { storageType: cacheType, cacheKey } = this.cacheOptions;
40
+ if (this.storage instanceof IndexedDBStorage) {
41
+ this.cache = JSON.parse(await this.storage.getItem(cacheKey) || "[]");
42
+ } else if (this.storage instanceof Storage) {
43
+ this.storage = StorageMap[cacheType];
44
+ if (this.storage) {
45
+ if (typeof cacheKey === "string") {
46
+ try {
47
+ this.cache = JSON.parse(this.storage.getItem(cacheKey) || "[]");
48
+ } catch (e) {
49
+ this.cache = [];
50
+ console.error(`缓存数据解析失败,key:${cacheKey}`);
51
+ }
151
52
  }
152
- return null;
53
+ }
54
+ }
55
+ this._filterExpired();
56
+ this._saveToStorage();
57
+ }
58
+ /**
59
+ * 过滤掉已过期的缓存项
60
+ * 通过比较当前时间和过期时间,移除过期的缓存项
61
+ * @private
62
+ */
63
+ _filterExpired() {
64
+ const newCache = this.cache.filter((item) => {
65
+ return isAfter(parseISO(item.expireTime), /* @__PURE__ */ new Date());
66
+ });
67
+ this.cache = newCache;
68
+ }
69
+ /**
70
+ * 将当前缓存数据保存到存储中
71
+ * 如果设置了缓存键名且存储实例存在,则将缓存数据序列化后保存
72
+ * @private
73
+ */
74
+ _saveToStorage() {
75
+ if (this.storage) {
76
+ if (typeof this.cacheOptions.cacheKey === "string") {
77
+ this.storage.setItem(this.cacheOptions.cacheKey, JSON.stringify(this.cache));
78
+ }
79
+ }
80
+ }
81
+ /**
82
+ * 设置缓存数据
83
+ * @param params 缓存的参数
84
+ * @param data 要缓存的数据
85
+ * @param cacheOptions 可选的缓存配置,可以覆盖默认的缓存时间
86
+ */
87
+ setCache(params, data, cacheOptions) {
88
+ const { cacheTime, cacheKeyEquals = defaultEquals } = {
89
+ ...this.cacheOptions,
90
+ ...cacheOptions
153
91
  };
154
- /**
155
- * 清空所有缓存数据
156
- * 清空内存中的缓存数组并同步到存储中
157
- */
158
- Cache.prototype.clear = function () {
159
- this.cache = [];
92
+ const cacheItemIndex = this.cache.findIndex((item) => {
93
+ return cacheKeyEquals(item.params, params);
94
+ });
95
+ if (cacheItemIndex > -1) {
96
+ this.cache.splice(cacheItemIndex, 1);
97
+ }
98
+ this.cache.push({
99
+ params,
100
+ data,
101
+ expireTime: addSeconds(/* @__PURE__ */ new Date(), cacheTime ?? 0).toISOString()
102
+ });
103
+ this._saveToStorage();
104
+ }
105
+ /**
106
+ * 获取缓存数据
107
+ * @param params 查询参数
108
+ * @returns 如果找到有效的缓存数据则返回数据,否则返回 null
109
+ */
110
+ getCache(params) {
111
+ const itemIndex = this.cache.findIndex((item2) => {
112
+ return this.cacheOptions.cacheKeyEquals(item2.params, params);
113
+ });
114
+ const item = this.cache[itemIndex];
115
+ if (item) {
116
+ if (isAfter(parseISO(item.expireTime), /* @__PURE__ */ new Date())) {
117
+ return item.data;
118
+ } else {
119
+ this.cache.splice(itemIndex, 1);
160
120
  this._saveToStorage();
161
- };
162
- return Cache;
163
- }());
164
-
165
- export { StorageMap, Cache as default };
121
+ }
122
+ }
123
+ return null;
124
+ }
125
+ /**
126
+ * 清空所有缓存数据
127
+ * 清空内存中的缓存数组并同步到存储中
128
+ */
129
+ clear() {
130
+ this.cache = [];
131
+ this._saveToStorage();
132
+ }
133
+ }
134
+ export {
135
+ StorageMap,
136
+ Cache as default
137
+ };
@@ -2,7 +2,7 @@
2
2
  * IndexedDB 存储类
3
3
  * 提供了对 IndexedDB 数据库操作的简单封装
4
4
  */
5
- declare class IndexedDBStorage {
5
+ export declare class IndexedDBStorage {
6
6
  /** 数据库名称 */
7
7
  private dbName;
8
8
  /** 存储对象名称 */
@@ -48,5 +48,3 @@ declare class IndexedDBStorage {
48
48
  */
49
49
  getItem<T = any>(key: string): Promise<T>;
50
50
  }
51
-
52
- export { IndexedDBStorage };
@@ -1,98 +1,87 @@
1
- /**
2
- * IndexedDB 存储类
3
- * 提供了对 IndexedDB 数据库操作的简单封装
4
- */
5
- var IndexedDBStorage = /** @class */ (function () {
6
- /**
7
- * 构造函数
8
- * @param dbName 数据库名称
9
- * @param storeName 存储对象名称
10
- */
11
- function IndexedDBStorage(dbName, storeName) {
12
- /** 数据库连接实例 */
13
- this.db = null;
14
- this.dbName = dbName;
15
- this.storeName = storeName;
16
- }
17
- /**
18
- * 打开数据库连接
19
- * 如果数据库不存在则创建新的数据库和存储对象
20
- * @private
21
- * @returns Promise<IDBDatabase> 数据库连接实例
22
- */
23
- IndexedDBStorage.prototype._open = function () {
24
- var _this = this;
25
- return new Promise(function (resolve, reject) {
26
- if (_this.db) {
27
- resolve(_this.db);
28
- return;
29
- }
30
- var request = indexedDB.open(_this.dbName);
31
- request.onupgradeneeded = function (event) {
32
- var db = event.target.result;
33
- db.createObjectStore(_this.storeName, { keyPath: 'key' });
34
- };
35
- request.onerror = function () {
36
- var _a;
37
- reject("IndexedDB open request error: ".concat((_a = request.error) === null || _a === void 0 ? void 0 : _a.message));
38
- };
39
- request.onsuccess = function (event) {
40
- _this.db = event.target.result;
41
- resolve(_this.db);
42
- };
43
- });
44
- };
45
- /**
46
- * 获取存储对象
47
- * @param mode 事务模式,默认为只读模式
48
- * - readonly: 只读模式
49
- * - readwrite: 读写模式
50
- * @private
51
- * @returns Promise<IDBObjectStore> 存储对象实例
52
- */
53
- IndexedDBStorage.prototype._getStore = function (mode) {
54
- var _this = this;
55
- if (mode === void 0) { mode = 'readonly'; }
56
- return this._open().then(function (db) {
57
- var transaction = db.transaction(_this.storeName, mode);
58
- return transaction.objectStore(_this.storeName);
59
- });
60
- };
61
- /**
62
- * 设置键值对
63
- * @param key 键名
64
- * @param value 要存储的值
65
- * @returns Promise<void> 存储操作的结果
66
- * @throws 当存储操作失败时抛出错误
67
- */
68
- IndexedDBStorage.prototype.setItem = function (key, value) {
69
- return this._getStore('readwrite').then(function (store) {
70
- return new Promise(function (resolve, reject) {
71
- var request = store.put({ key: key, value: value });
72
- request.onsuccess = function () { return resolve(); };
73
- request.onerror = function () { var _a; return reject("Could not set the item: ".concat((_a = request.error) === null || _a === void 0 ? void 0 : _a.message)); };
74
- });
75
- });
76
- };
77
- /**
78
- * 获取键对应的值
79
- * @param key 要获取的键名
80
- * @returns Promise<T> 返回存储的值,如果不存在则返回 undefined
81
- * @throws 当获取操作失败时抛出错误
82
- * @template T 存储值的类型,默认为 any
83
- */
84
- IndexedDBStorage.prototype.getItem = function (key) {
85
- return this._getStore().then(function (store) {
86
- return new Promise(function (resolve, reject) {
87
- var request = store.get(key);
88
- request.onsuccess = function () {
89
- return resolve(request.result ? request.result.value : undefined);
90
- };
91
- request.onerror = function () { var _a; return reject("Could not get the item: ".concat((_a = request.error) === null || _a === void 0 ? void 0 : _a.message)); };
92
- });
93
- });
94
- };
95
- return IndexedDBStorage;
96
- }());
97
-
98
- export { IndexedDBStorage };
1
+ class IndexedDBStorage {
2
+ /**
3
+ * 构造函数
4
+ * @param dbName 数据库名称
5
+ * @param storeName 存储对象名称
6
+ */
7
+ constructor(dbName, storeName) {
8
+ this.db = null;
9
+ this.dbName = dbName;
10
+ this.storeName = storeName;
11
+ }
12
+ /**
13
+ * 打开数据库连接
14
+ * 如果数据库不存在则创建新的数据库和存储对象
15
+ * @private
16
+ * @returns Promise<IDBDatabase> 数据库连接实例
17
+ */
18
+ _open() {
19
+ return new Promise((resolve, reject) => {
20
+ if (this.db) {
21
+ resolve(this.db);
22
+ return;
23
+ }
24
+ const request = indexedDB.open(this.dbName);
25
+ request.onupgradeneeded = (event) => {
26
+ const db = event.target.result;
27
+ db.createObjectStore(this.storeName, { keyPath: "key" });
28
+ };
29
+ request.onerror = () => {
30
+ reject(`IndexedDB open request error: ${request.error?.message}`);
31
+ };
32
+ request.onsuccess = (event) => {
33
+ this.db = event.target.result;
34
+ resolve(this.db);
35
+ };
36
+ });
37
+ }
38
+ /**
39
+ * 获取存储对象
40
+ * @param mode 事务模式,默认为只读模式
41
+ * - readonly: 只读模式
42
+ * - readwrite: 读写模式
43
+ * @private
44
+ * @returns Promise<IDBObjectStore> 存储对象实例
45
+ */
46
+ _getStore(mode = "readonly") {
47
+ return this._open().then((db) => {
48
+ const transaction = db.transaction(this.storeName, mode);
49
+ return transaction.objectStore(this.storeName);
50
+ });
51
+ }
52
+ /**
53
+ * 设置键值对
54
+ * @param key 键名
55
+ * @param value 要存储的值
56
+ * @returns Promise<void> 存储操作的结果
57
+ * @throws 当存储操作失败时抛出错误
58
+ */
59
+ setItem(key, value) {
60
+ return this._getStore("readwrite").then((store) => {
61
+ return new Promise((resolve, reject) => {
62
+ const request = store.put({ key, value });
63
+ request.onsuccess = () => resolve();
64
+ request.onerror = () => reject(`Could not set the item: ${request.error?.message}`);
65
+ });
66
+ });
67
+ }
68
+ /**
69
+ * 获取键对应的值
70
+ * @param key 要获取的键名
71
+ * @returns Promise<T> 返回存储的值,如果不存在则返回 undefined
72
+ * @throws 当获取操作失败时抛出错误
73
+ * @template T 存储值的类型,默认为 any
74
+ */
75
+ getItem(key) {
76
+ return this._getStore().then((store) => {
77
+ return new Promise((resolve, reject) => {
78
+ const request = store.get(key);
79
+ request.onsuccess = () => resolve(request.result ? request.result.value : void 0);
80
+ request.onerror = () => reject(`Could not get the item: ${request.error?.message}`);
81
+ });
82
+ });
83
+ }
84
+ }
85
+ export {
86
+ IndexedDBStorage
87
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @desc 通过创建 a 标签下载 blob 文件
3
+ * @param blob blob 文件
4
+ * @param fileName 下载后的文件名
5
+ * @param autoRevoke 是否自动回收 url
6
+ * @returns url
7
+ */
8
+ export declare const downloadBlob: (blob: Blob, fileName: string, autoRevoke?: boolean) => string;
@@ -0,0 +1,14 @@
1
+ const downloadBlob = (blob, fileName, autoRevoke = true) => {
2
+ const url = URL.createObjectURL(blob);
3
+ const a = document.createElement("a");
4
+ a.href = url;
5
+ a.download = fileName;
6
+ a.click();
7
+ if (autoRevoke) {
8
+ URL.revokeObjectURL(url);
9
+ }
10
+ return url;
11
+ };
12
+ export {
13
+ downloadBlob
14
+ };
@@ -1 +1 @@
1
- export { useCombineControlValue } from './useCombineControlValue.js';
1
+ export { useCombineControlValue } from './useCombineControlValue';
@@ -1 +1,4 @@
1
- export { useCombineControlValue } from './useCombineControlValue.mjs';
1
+ import { useCombineControlValue } from "./useCombineControlValue.mjs";
2
+ export {
3
+ useCombineControlValue
4
+ };
@@ -1,21 +1,18 @@
1
- type UseCombineControlValueOptions<V> = {
1
+ export type UseCombineControlValueOptions<V> = {
2
2
  props: Record<string, any>;
3
3
  valueKey?: string;
4
4
  defaultValue?: V;
5
5
  onChange?: (val: V) => void;
6
6
  };
7
- type UseCombineControlValueEasyResult<V> = {
7
+ export type UseCombineControlValueEasyResult<V> = {
8
8
  value: V;
9
9
  onChange: (nextVal: V) => void;
10
10
  };
11
- type UseCombineControlValueResolveResult<V, R extends (...args: any[]) => any> = {
11
+ export type UseCombineControlValueResolveResult<V, R extends (...args: any[]) => any> = {
12
12
  value: V;
13
13
  onChange: (...args: Parameters<R>) => void;
14
14
  };
15
- declare function useCombineControlValue<V>(options: UseCombineControlValueOptions<V>): UseCombineControlValueEasyResult<V>;
16
- declare function useCombineControlValue<V, R extends (...args: any[]) => any>(options: Omit<UseCombineControlValueOptions<V>, 'onChange'> & {
15
+ export declare function useCombineControlValue<V>(options: UseCombineControlValueOptions<V>): UseCombineControlValueEasyResult<V>;
16
+ export declare function useCombineControlValue<V, R extends (...args: any[]) => any>(options: Omit<UseCombineControlValueOptions<V>, 'onChange'> & {
17
17
  onChange?: (...args: Parameters<R>) => void;
18
18
  }, resolveFn: (...args: Parameters<R>) => V): UseCombineControlValueResolveResult<V, R>;
19
-
20
- export { useCombineControlValue };
21
- export type { UseCombineControlValueEasyResult, UseCombineControlValueOptions, UseCombineControlValueResolveResult };