@pisell/core 1.1.3 → 1.1.5

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.
@@ -3,7 +3,7 @@ import App from "../app";
3
3
  * IndexDB 管理器模块
4
4
  *
5
5
  * 这个模块提供了对浏览器 IndexedDB 的简单封装,并在不支持 IndexedDB 的环境中
6
- * 自动降级使用 localStorage 作为备选存储方案。
6
+ * 自动降级使用内存存储作为备选存储方案。
7
7
  */
8
8
  /**
9
9
  * 数据库配置选项接口
@@ -30,10 +30,11 @@ export interface DBOptions {
30
30
  options?: IDBIndexParameters;
31
31
  }[];
32
32
  }[];
33
+ timeout?: number;
33
34
  }
34
35
  /**
35
36
  * IndexDB 管理器类
36
- * 提供对 IndexedDB 的简单封装,支持自动降级到 localStorage
37
+ * 提供对 IndexedDB 的简单封装,支持自动降级到内存存储
37
38
  * @class IndexDBManager
38
39
  */
39
40
  declare class IndexDBManager {
@@ -49,25 +50,34 @@ declare class IndexDBManager {
49
50
  private stores;
50
51
  private useIndexDB;
51
52
  private app;
53
+ private memoryStorage;
54
+ private timeout;
52
55
  /**
53
56
  * 创建 IndexDBManager 实例
54
57
  * @param {DBOptions} options - 数据库配置选项
55
58
  */
56
59
  constructor(app: App, options: DBOptions);
60
+ /**
61
+ * 超时包装器 - 为 Promise 添加超时控制
62
+ * @param {Promise<T>} promise - 需要包装的 Promise
63
+ * @param {string} operation - 操作名称(用于错误提示)
64
+ * @returns {Promise<T>} 带超时控制的 Promise
65
+ * @private
66
+ */
67
+ private withTimeout;
57
68
  /**
58
69
  * 初始化数据库连接
59
- * 如果环境不支持 IndexedDB,将自动使用 localStorage
70
+ * 如果环境不支持 IndexedDB,将自动使用内存存储
60
71
  * @returns {Promise<boolean>} 连接是否成功
61
72
  */
62
73
  connect(): Promise<boolean>;
63
74
  /**
64
- * 生成用于 localStorage 的存储键
75
+ * 获取内存存储中指定 store 的 Map
65
76
  * @param {string} storeName - 存储对象名称
66
- * @param {string|number} [key] - 可选的键值
67
- * @returns {string} 格式化的存储键
77
+ * @returns {Map<string | number, any>} 存储 Map
68
78
  * @private
69
79
  */
70
- private getStorageKey;
80
+ private getMemoryStore;
71
81
  /**
72
82
  * 添加数据到指定的存储对象
73
83
  * @param {string} storeName - 存储对象名称
@@ -169,9 +179,9 @@ declare class IndexDBManager {
169
179
  close(): void;
170
180
  /**
171
181
  * 获取当前使用的存储方式
172
- * @returns {'indexDB'|'localStorage'} 当前使用的存储方式
182
+ * @returns {'indexDB'|'memory'} 当前使用的存储方式
173
183
  */
174
- getCurrentStorage(): 'indexDB' | 'localStorage';
184
+ getCurrentStorage(): 'indexDB' | 'memory';
175
185
  }
176
186
  /**
177
187
  * 使用示例:
@@ -240,12 +250,18 @@ declare class IndexDBManager {
240
250
  * db.close();
241
251
  *
242
252
  * // 15. 检查当前使用的存储方式
243
- * const storageType = db.getCurrentStorage(); // 'indexDB' 或 'localStorage'
253
+ * const storageType = db.getCurrentStorage(); // 'indexDB' 或 'memory'
244
254
  *
245
255
  * // 性能优化建议:
246
256
  * // - 使用 exists() 而不是 get() 来检查数据是否存在
247
257
  * // - 为常用查询字段创建索引
248
258
  * // - 使用索引查询方法来提高查询效率
249
259
  * // - 批量操作时使用事务(可以考虑后续扩展)
260
+ *
261
+ * // 降级方案说明:
262
+ * // - 当浏览器不支持 IndexedDB 时,会自动使用内存存储 (Map) 作为降级方案
263
+ * // - 内存存储的数据在页面刷新后会丢失,仅适合临时数据存储
264
+ * // - 内存存储支持所有 IndexedDB API,包括索引查询
265
+ * // - 对于需要持久化的数据,请确保浏览器支持 IndexedDB
250
266
  */
251
267
  export default IndexDBManager;