@pisell/core 1.0.13 → 1.0.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.
Files changed (137) hide show
  1. package/es/app/app.d.ts +87 -0
  2. package/es/app/const.d.ts +4 -0
  3. package/es/app/index.d.ts +14 -0
  4. package/es/applicationManager/application.d.ts +50 -0
  5. package/es/applicationManager/index.d.ts +13 -0
  6. package/es/aws/index.d.ts +16 -0
  7. package/es/cmd/const.d.ts +11 -0
  8. package/es/cmd/index.d.ts +13 -0
  9. package/es/cmd/type.d.ts +5 -0
  10. package/es/config.d.ts +3 -0
  11. package/es/cookie/index.d.ts +13 -0
  12. package/es/data/index.d.ts +8 -0
  13. package/es/history/config.d.ts +24 -0
  14. package/es/history/index.d.ts +20 -0
  15. package/es/history/type.d.ts +2 -0
  16. package/es/hooks/index.d.ts +12 -0
  17. package/es/hooks/useDelayedValue/index.d.ts +2 -0
  18. package/es/hooks/useDispatch/index.d.ts +2 -0
  19. package/es/hooks/useLowCode/index.d.ts +13 -0
  20. package/es/hooks/useStore/index.d.ts +6 -0
  21. package/es/index.d.ts +6 -0
  22. package/es/indexDB/index.d.ts +248 -0
  23. package/es/indexDB/index.js +453 -70
  24. package/es/locales/en.d.ts +3 -0
  25. package/es/locales/index.d.ts +39 -0
  26. package/es/locales/original.d.ts +3 -0
  27. package/es/locales/type.d.ts +19 -0
  28. package/es/locales/zh-CN.d.ts +3 -0
  29. package/es/locales/zh-HK.d.ts +3 -0
  30. package/es/logger/feishu.d.ts +11 -0
  31. package/es/menuManager/hooks.d.ts +17 -0
  32. package/es/menuManager/index.d.ts +28 -0
  33. package/es/models/global.d.ts +32 -0
  34. package/es/models/index.d.ts +45 -0
  35. package/es/models/type.d.ts +2 -0
  36. package/es/plugin/index.d.ts +0 -0
  37. package/es/pubsub/example.d.ts +5 -0
  38. package/es/pubsub/index.d.ts +63 -0
  39. package/es/request/cache.d.ts +46 -0
  40. package/es/request/cancelToken.d.ts +38 -0
  41. package/es/request/config.d.ts +3 -0
  42. package/es/request/constants.d.ts +2 -0
  43. package/es/request/index.d.ts +24 -0
  44. package/es/request/pisell2Request.d.ts +6 -0
  45. package/es/request/type.d.ts +41 -0
  46. package/es/request/utils.d.ts +46 -0
  47. package/es/routes/config.d.ts +7 -0
  48. package/es/routes/index.d.ts +28 -0
  49. package/es/socket/components/SocketMonitorPage.d.ts +6 -0
  50. package/es/socket/components/index.d.ts +2 -0
  51. package/es/socket/constants.d.ts +33 -0
  52. package/es/socket/events.d.ts +31 -0
  53. package/es/socket/heartbeat.d.ts +66 -0
  54. package/es/socket/index.d.ts +61 -0
  55. package/es/socket/monitor.d.ts +169 -0
  56. package/es/socket/reconnect.d.ts +61 -0
  57. package/es/socket/socket.d.ts +130 -0
  58. package/es/socket/types.d.ts +84 -0
  59. package/es/storage/index.d.ts +17 -0
  60. package/es/tasks/index.d.ts +83 -0
  61. package/es/tasks/type.d.ts +62 -0
  62. package/es/tasks/useTasks.d.ts +5 -0
  63. package/es/type.d.ts +2 -0
  64. package/es/variables/VariablesProvider.d.ts +7 -0
  65. package/es/variables/config.d.ts +3 -0
  66. package/es/variables/index.d.ts +6 -0
  67. package/es/variables/type.d.ts +2 -0
  68. package/es/website/index.d.ts +6 -0
  69. package/lib/app/app.d.ts +87 -0
  70. package/lib/app/const.d.ts +4 -0
  71. package/lib/app/index.d.ts +14 -0
  72. package/lib/applicationManager/application.d.ts +50 -0
  73. package/lib/applicationManager/index.d.ts +13 -0
  74. package/lib/aws/index.d.ts +16 -0
  75. package/lib/cmd/const.d.ts +11 -0
  76. package/lib/cmd/index.d.ts +13 -0
  77. package/lib/cmd/type.d.ts +5 -0
  78. package/lib/config.d.ts +3 -0
  79. package/lib/cookie/index.d.ts +13 -0
  80. package/lib/data/index.d.ts +8 -0
  81. package/lib/history/config.d.ts +24 -0
  82. package/lib/history/index.d.ts +20 -0
  83. package/lib/history/type.d.ts +2 -0
  84. package/lib/hooks/index.d.ts +12 -0
  85. package/lib/hooks/useDelayedValue/index.d.ts +2 -0
  86. package/lib/hooks/useDispatch/index.d.ts +2 -0
  87. package/lib/hooks/useLowCode/index.d.ts +13 -0
  88. package/lib/hooks/useStore/index.d.ts +6 -0
  89. package/lib/index.d.ts +6 -0
  90. package/lib/indexDB/index.d.ts +248 -0
  91. package/lib/indexDB/index.js +159 -0
  92. package/lib/locales/en.d.ts +3 -0
  93. package/lib/locales/index.d.ts +39 -0
  94. package/lib/locales/original.d.ts +3 -0
  95. package/lib/locales/type.d.ts +19 -0
  96. package/lib/locales/zh-CN.d.ts +3 -0
  97. package/lib/locales/zh-HK.d.ts +3 -0
  98. package/lib/logger/feishu.d.ts +11 -0
  99. package/lib/menuManager/hooks.d.ts +17 -0
  100. package/lib/menuManager/index.d.ts +28 -0
  101. package/lib/models/global.d.ts +32 -0
  102. package/lib/models/index.d.ts +45 -0
  103. package/lib/models/type.d.ts +2 -0
  104. package/lib/plugin/index.d.ts +0 -0
  105. package/lib/pubsub/example.d.ts +5 -0
  106. package/lib/pubsub/index.d.ts +63 -0
  107. package/lib/request/cache.d.ts +46 -0
  108. package/lib/request/cancelToken.d.ts +38 -0
  109. package/lib/request/config.d.ts +3 -0
  110. package/lib/request/constants.d.ts +2 -0
  111. package/lib/request/index.d.ts +24 -0
  112. package/lib/request/pisell2Request.d.ts +6 -0
  113. package/lib/request/type.d.ts +41 -0
  114. package/lib/request/utils.d.ts +46 -0
  115. package/lib/routes/config.d.ts +7 -0
  116. package/lib/routes/index.d.ts +28 -0
  117. package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
  118. package/lib/socket/components/index.d.ts +2 -0
  119. package/lib/socket/constants.d.ts +33 -0
  120. package/lib/socket/events.d.ts +31 -0
  121. package/lib/socket/heartbeat.d.ts +66 -0
  122. package/lib/socket/index.d.ts +61 -0
  123. package/lib/socket/monitor.d.ts +169 -0
  124. package/lib/socket/reconnect.d.ts +61 -0
  125. package/lib/socket/socket.d.ts +130 -0
  126. package/lib/socket/types.d.ts +84 -0
  127. package/lib/storage/index.d.ts +17 -0
  128. package/lib/tasks/index.d.ts +83 -0
  129. package/lib/tasks/type.d.ts +62 -0
  130. package/lib/tasks/useTasks.d.ts +5 -0
  131. package/lib/type.d.ts +2 -0
  132. package/lib/variables/VariablesProvider.d.ts +7 -0
  133. package/lib/variables/config.d.ts +3 -0
  134. package/lib/variables/index.d.ts +6 -0
  135. package/lib/variables/type.d.ts +2 -0
  136. package/lib/website/index.d.ts +6 -0
  137. package/package.json +8 -8
@@ -173,6 +173,55 @@ var IndexDBManager = /*#__PURE__*/function () {
173
173
  }
174
174
  return add;
175
175
  }()
176
+ /**
177
+ * 快速检查指定存储对象中的数据是否存在
178
+ * @param {string} storeName - 存储对象名称
179
+ * @param {string|number} key - 数据主键
180
+ * @returns {Promise<boolean>} 数据是否存在
181
+ */
182
+ )
183
+ }, {
184
+ key: "exists",
185
+ value: (function () {
186
+ var _exists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(storeName, key) {
187
+ var _this3 = this;
188
+ var storageKey;
189
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
190
+ while (1) switch (_context3.prev = _context3.next) {
191
+ case 0:
192
+ if (this.useIndexDB) {
193
+ _context3.next = 3;
194
+ break;
195
+ }
196
+ storageKey = this.getStorageKey(storeName, key);
197
+ return _context3.abrupt("return", this.app.storage.getStorage(storageKey) !== null);
198
+ case 3:
199
+ return _context3.abrupt("return", new Promise(function (resolve, reject) {
200
+ if (!_this3.db) {
201
+ reject(new Error('数据库未连接'));
202
+ return;
203
+ }
204
+ var transaction = _this3.db.transaction(storeName, 'readonly');
205
+ var store = transaction.objectStore(storeName);
206
+ var request = store.count(key);
207
+ request.onsuccess = function () {
208
+ return resolve(request.result > 0);
209
+ };
210
+ request.onerror = function () {
211
+ return reject(new Error('检查数据存在性失败'));
212
+ };
213
+ }));
214
+ case 4:
215
+ case "end":
216
+ return _context3.stop();
217
+ }
218
+ }, _callee3, this);
219
+ }));
220
+ function exists(_x3, _x4) {
221
+ return _exists.apply(this, arguments);
222
+ }
223
+ return exists;
224
+ }()
176
225
  /**
177
226
  * 获取指定存储对象中的数据
178
227
  * @param {string} storeName - 存储对象名称
@@ -184,14 +233,14 @@ var IndexDBManager = /*#__PURE__*/function () {
184
233
  }, {
185
234
  key: "get",
186
235
  value: (function () {
187
- var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(storeName, key) {
188
- var _this3 = this;
236
+ var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(storeName, key) {
237
+ var _this4 = this;
189
238
  var storageKey, data;
190
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
191
- while (1) switch (_context3.prev = _context3.next) {
239
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
240
+ while (1) switch (_context4.prev = _context4.next) {
192
241
  case 0:
193
242
  if (this.useIndexDB) {
194
- _context3.next = 5;
243
+ _context4.next = 5;
195
244
  break;
196
245
  }
197
246
  storageKey = this.getStorageKey(storeName, key);
@@ -199,14 +248,14 @@ var IndexDBManager = /*#__PURE__*/function () {
199
248
  if (data) {
200
249
  data = JSON.parse(data);
201
250
  }
202
- return _context3.abrupt("return", data);
251
+ return _context4.abrupt("return", data);
203
252
  case 5:
204
- return _context3.abrupt("return", new Promise(function (resolve, reject) {
205
- if (!_this3.db) {
253
+ return _context4.abrupt("return", new Promise(function (resolve, reject) {
254
+ if (!_this4.db) {
206
255
  reject(new Error('数据库未连接'));
207
256
  return;
208
257
  }
209
- var transaction = _this3.db.transaction(storeName, 'readonly');
258
+ var transaction = _this4.db.transaction(storeName, 'readonly');
210
259
  var store = transaction.objectStore(storeName);
211
260
  var request = store.get(key);
212
261
  request.onsuccess = function () {
@@ -218,11 +267,11 @@ var IndexDBManager = /*#__PURE__*/function () {
218
267
  }));
219
268
  case 6:
220
269
  case "end":
221
- return _context3.stop();
270
+ return _context4.stop();
222
271
  }
223
- }, _callee3, this);
272
+ }, _callee4, this);
224
273
  }));
225
- function get(_x3, _x4) {
274
+ function get(_x5, _x6) {
226
275
  return _get.apply(this, arguments);
227
276
  }
228
277
  return get;
@@ -238,28 +287,28 @@ var IndexDBManager = /*#__PURE__*/function () {
238
287
  }, {
239
288
  key: "update",
240
289
  value: (function () {
241
- var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(storeName, data) {
242
- var _this4 = this;
290
+ var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(storeName, data) {
291
+ var _this5 = this;
243
292
  var _this$stores$find2, key;
244
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
245
- while (1) switch (_context4.prev = _context4.next) {
293
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
294
+ while (1) switch (_context5.prev = _context5.next) {
246
295
  case 0:
247
296
  if (this.useIndexDB) {
248
- _context4.next = 4;
297
+ _context5.next = 4;
249
298
  break;
250
299
  }
251
300
  key = this.getStorageKey(storeName, data[((_this$stores$find2 = this.stores.find(function (s) {
252
301
  return s.name === storeName;
253
302
  })) === null || _this$stores$find2 === void 0 ? void 0 : _this$stores$find2.keyPath) || 'id']);
254
303
  this.app.storage.setStorage(key, JSON.stringify(data));
255
- return _context4.abrupt("return", data);
304
+ return _context5.abrupt("return", data);
256
305
  case 4:
257
- return _context4.abrupt("return", new Promise(function (resolve, reject) {
258
- if (!_this4.db) {
306
+ return _context5.abrupt("return", new Promise(function (resolve, reject) {
307
+ if (!_this5.db) {
259
308
  reject(new Error('数据库未连接'));
260
309
  return;
261
310
  }
262
- var transaction = _this4.db.transaction(storeName, 'readwrite');
311
+ var transaction = _this5.db.transaction(storeName, 'readwrite');
263
312
  var store = transaction.objectStore(storeName);
264
313
  var request = store.put(data);
265
314
  request.onsuccess = function () {
@@ -271,11 +320,11 @@ var IndexDBManager = /*#__PURE__*/function () {
271
320
  }));
272
321
  case 5:
273
322
  case "end":
274
- return _context4.stop();
323
+ return _context5.stop();
275
324
  }
276
- }, _callee4, this);
325
+ }, _callee5, this);
277
326
  }));
278
- function update(_x5, _x6) {
327
+ function update(_x7, _x8) {
279
328
  return _update.apply(this, arguments);
280
329
  }
281
330
  return update;
@@ -290,26 +339,26 @@ var IndexDBManager = /*#__PURE__*/function () {
290
339
  }, {
291
340
  key: "delete",
292
341
  value: (function () {
293
- var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(storeName, key) {
294
- var _this5 = this;
342
+ var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(storeName, key) {
343
+ var _this6 = this;
295
344
  var storageKey;
296
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
297
- while (1) switch (_context5.prev = _context5.next) {
345
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
346
+ while (1) switch (_context6.prev = _context6.next) {
298
347
  case 0:
299
348
  if (this.useIndexDB) {
300
- _context5.next = 4;
349
+ _context6.next = 4;
301
350
  break;
302
351
  }
303
352
  storageKey = this.getStorageKey(storeName, key);
304
353
  this.app.storage.removeStorage(storageKey);
305
- return _context5.abrupt("return", true);
354
+ return _context6.abrupt("return", true);
306
355
  case 4:
307
- return _context5.abrupt("return", new Promise(function (resolve, reject) {
308
- if (!_this5.db) {
356
+ return _context6.abrupt("return", new Promise(function (resolve, reject) {
357
+ if (!_this6.db) {
309
358
  reject(new Error('数据库未连接'));
310
359
  return;
311
360
  }
312
- var transaction = _this5.db.transaction(storeName, 'readwrite');
361
+ var transaction = _this6.db.transaction(storeName, 'readwrite');
313
362
  var store = transaction.objectStore(storeName);
314
363
  var request = store.delete(key);
315
364
  request.onsuccess = function () {
@@ -321,15 +370,326 @@ var IndexDBManager = /*#__PURE__*/function () {
321
370
  }));
322
371
  case 5:
323
372
  case "end":
324
- return _context5.stop();
373
+ return _context6.stop();
325
374
  }
326
- }, _callee5, this);
375
+ }, _callee6, this);
327
376
  }));
328
- function _delete(_x7, _x8) {
377
+ function _delete(_x9, _x10) {
329
378
  return _delete2.apply(this, arguments);
330
379
  }
331
380
  return _delete;
332
381
  }()
382
+ /**
383
+ * 通过索引获取数据
384
+ * @param {string} storeName - 存储对象名称
385
+ * @param {string} indexName - 索引名称
386
+ * @param {string|number} indexValue - 索引值
387
+ * @returns {Promise<T|null>} 获取的数据,不存在则返回 null
388
+ * @template T
389
+ */
390
+ )
391
+ }, {
392
+ key: "getByIndex",
393
+ value: (function () {
394
+ var _getByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(storeName, indexName, indexValue) {
395
+ var _this7 = this;
396
+ var _storeConfig$indexes, allData, storeConfig, index;
397
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
398
+ while (1) switch (_context7.prev = _context7.next) {
399
+ case 0:
400
+ if (this.useIndexDB) {
401
+ _context7.next = 9;
402
+ break;
403
+ }
404
+ _context7.next = 3;
405
+ return this.getAll(storeName);
406
+ case 3:
407
+ allData = _context7.sent;
408
+ storeConfig = this.stores.find(function (s) {
409
+ return s.name === storeName;
410
+ });
411
+ index = storeConfig === null || storeConfig === void 0 || (_storeConfig$indexes = storeConfig.indexes) === null || _storeConfig$indexes === void 0 ? void 0 : _storeConfig$indexes.find(function (i) {
412
+ return i.name === indexName;
413
+ });
414
+ if (index) {
415
+ _context7.next = 8;
416
+ break;
417
+ }
418
+ return _context7.abrupt("return", null);
419
+ case 8:
420
+ return _context7.abrupt("return", allData.find(function (item) {
421
+ return item[index.keyPath] === indexValue;
422
+ }) || null);
423
+ case 9:
424
+ return _context7.abrupt("return", new Promise(function (resolve, reject) {
425
+ if (!_this7.db) {
426
+ reject(new Error('数据库未连接'));
427
+ return;
428
+ }
429
+ var transaction = _this7.db.transaction(storeName, 'readonly');
430
+ var store = transaction.objectStore(storeName);
431
+ var index = store.index(indexName);
432
+ var request = index.get(indexValue);
433
+ request.onsuccess = function () {
434
+ return resolve(request.result || null);
435
+ };
436
+ request.onerror = function () {
437
+ return reject(new Error('通过索引获取数据失败'));
438
+ };
439
+ }));
440
+ case 10:
441
+ case "end":
442
+ return _context7.stop();
443
+ }
444
+ }, _callee7, this);
445
+ }));
446
+ function getByIndex(_x11, _x12, _x13) {
447
+ return _getByIndex.apply(this, arguments);
448
+ }
449
+ return getByIndex;
450
+ }()
451
+ /**
452
+ * 通过索引检查数据是否存在
453
+ * @param {string} storeName - 存储对象名称
454
+ * @param {string} indexName - 索引名称
455
+ * @param {string|number} indexValue - 索引值
456
+ * @returns {Promise<boolean>} 数据是否存在
457
+ */
458
+ )
459
+ }, {
460
+ key: "existsByIndex",
461
+ value: (function () {
462
+ var _existsByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(storeName, indexName, indexValue) {
463
+ var _this8 = this;
464
+ var _storeConfig$indexes2, allData, storeConfig, index;
465
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
466
+ while (1) switch (_context8.prev = _context8.next) {
467
+ case 0:
468
+ if (this.useIndexDB) {
469
+ _context8.next = 9;
470
+ break;
471
+ }
472
+ _context8.next = 3;
473
+ return this.getAll(storeName);
474
+ case 3:
475
+ allData = _context8.sent;
476
+ storeConfig = this.stores.find(function (s) {
477
+ return s.name === storeName;
478
+ });
479
+ index = storeConfig === null || storeConfig === void 0 || (_storeConfig$indexes2 = storeConfig.indexes) === null || _storeConfig$indexes2 === void 0 ? void 0 : _storeConfig$indexes2.find(function (i) {
480
+ return i.name === indexName;
481
+ });
482
+ if (index) {
483
+ _context8.next = 8;
484
+ break;
485
+ }
486
+ return _context8.abrupt("return", false);
487
+ case 8:
488
+ return _context8.abrupt("return", allData.some(function (item) {
489
+ return item[index.keyPath] === indexValue;
490
+ }));
491
+ case 9:
492
+ return _context8.abrupt("return", new Promise(function (resolve, reject) {
493
+ if (!_this8.db) {
494
+ reject(new Error('数据库未连接'));
495
+ return;
496
+ }
497
+ var transaction = _this8.db.transaction(storeName, 'readonly');
498
+ var store = transaction.objectStore(storeName);
499
+ var index = store.index(indexName);
500
+ var request = index.count(indexValue);
501
+ request.onsuccess = function () {
502
+ return resolve(request.result > 0);
503
+ };
504
+ request.onerror = function () {
505
+ return reject(new Error('通过索引检查数据存在性失败'));
506
+ };
507
+ }));
508
+ case 10:
509
+ case "end":
510
+ return _context8.stop();
511
+ }
512
+ }, _callee8, this);
513
+ }));
514
+ function existsByIndex(_x14, _x15, _x16) {
515
+ return _existsByIndex.apply(this, arguments);
516
+ }
517
+ return existsByIndex;
518
+ }()
519
+ /**
520
+ * 通过索引获取多条数据
521
+ * @param {string} storeName - 存储对象名称
522
+ * @param {string} indexName - 索引名称
523
+ * @param {string|number} indexValue - 索引值
524
+ * @returns {Promise<T[]>} 数据数组
525
+ * @template T
526
+ */
527
+ )
528
+ }, {
529
+ key: "getAllByIndex",
530
+ value: (function () {
531
+ var _getAllByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(storeName, indexName, indexValue) {
532
+ var _this9 = this;
533
+ var _storeConfig$indexes3, allData, storeConfig, index;
534
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
535
+ while (1) switch (_context9.prev = _context9.next) {
536
+ case 0:
537
+ if (this.useIndexDB) {
538
+ _context9.next = 9;
539
+ break;
540
+ }
541
+ _context9.next = 3;
542
+ return this.getAll(storeName);
543
+ case 3:
544
+ allData = _context9.sent;
545
+ storeConfig = this.stores.find(function (s) {
546
+ return s.name === storeName;
547
+ });
548
+ index = storeConfig === null || storeConfig === void 0 || (_storeConfig$indexes3 = storeConfig.indexes) === null || _storeConfig$indexes3 === void 0 ? void 0 : _storeConfig$indexes3.find(function (i) {
549
+ return i.name === indexName;
550
+ });
551
+ if (index) {
552
+ _context9.next = 8;
553
+ break;
554
+ }
555
+ return _context9.abrupt("return", []);
556
+ case 8:
557
+ return _context9.abrupt("return", allData.filter(function (item) {
558
+ return item[index.keyPath] === indexValue;
559
+ }));
560
+ case 9:
561
+ return _context9.abrupt("return", new Promise(function (resolve, reject) {
562
+ if (!_this9.db) {
563
+ reject(new Error('数据库未连接'));
564
+ return;
565
+ }
566
+ var transaction = _this9.db.transaction(storeName, 'readonly');
567
+ var store = transaction.objectStore(storeName);
568
+ var index = store.index(indexName);
569
+ var request = index.getAll(indexValue);
570
+ request.onsuccess = function () {
571
+ return resolve(request.result);
572
+ };
573
+ request.onerror = function () {
574
+ return reject(new Error('通过索引获取多条数据失败'));
575
+ };
576
+ }));
577
+ case 10:
578
+ case "end":
579
+ return _context9.stop();
580
+ }
581
+ }, _callee9, this);
582
+ }));
583
+ function getAllByIndex(_x17, _x18, _x19) {
584
+ return _getAllByIndex.apply(this, arguments);
585
+ }
586
+ return getAllByIndex;
587
+ }()
588
+ /**
589
+ * 统计指定存储对象中的数据数量
590
+ * @param {string} storeName - 存储对象名称
591
+ * @returns {Promise<number>} 数据数量
592
+ */
593
+ )
594
+ }, {
595
+ key: "count",
596
+ value: (function () {
597
+ var _count = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(storeName) {
598
+ var _this10 = this;
599
+ var allData;
600
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
601
+ while (1) switch (_context10.prev = _context10.next) {
602
+ case 0:
603
+ if (this.useIndexDB) {
604
+ _context10.next = 5;
605
+ break;
606
+ }
607
+ _context10.next = 3;
608
+ return this.getAll(storeName);
609
+ case 3:
610
+ allData = _context10.sent;
611
+ return _context10.abrupt("return", allData.length);
612
+ case 5:
613
+ return _context10.abrupt("return", new Promise(function (resolve, reject) {
614
+ if (!_this10.db) {
615
+ reject(new Error('数据库未连接'));
616
+ return;
617
+ }
618
+ var transaction = _this10.db.transaction(storeName, 'readonly');
619
+ var store = transaction.objectStore(storeName);
620
+ var request = store.count();
621
+ request.onsuccess = function () {
622
+ return resolve(request.result);
623
+ };
624
+ request.onerror = function () {
625
+ return reject(new Error('统计数据数量失败'));
626
+ };
627
+ }));
628
+ case 6:
629
+ case "end":
630
+ return _context10.stop();
631
+ }
632
+ }, _callee10, this);
633
+ }));
634
+ function count(_x20) {
635
+ return _count.apply(this, arguments);
636
+ }
637
+ return count;
638
+ }()
639
+ /**
640
+ * 通过索引统计数据数量
641
+ * @param {string} storeName - 存储对象名称
642
+ * @param {string} indexName - 索引名称
643
+ * @param {string|number} indexValue - 索引值
644
+ * @returns {Promise<number>} 数据数量
645
+ */
646
+ )
647
+ }, {
648
+ key: "countByIndex",
649
+ value: (function () {
650
+ var _countByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(storeName, indexName, indexValue) {
651
+ var _this11 = this;
652
+ var matchingData;
653
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
654
+ while (1) switch (_context11.prev = _context11.next) {
655
+ case 0:
656
+ if (this.useIndexDB) {
657
+ _context11.next = 5;
658
+ break;
659
+ }
660
+ _context11.next = 3;
661
+ return this.getAllByIndex(storeName, indexName, indexValue);
662
+ case 3:
663
+ matchingData = _context11.sent;
664
+ return _context11.abrupt("return", matchingData.length);
665
+ case 5:
666
+ return _context11.abrupt("return", new Promise(function (resolve, reject) {
667
+ if (!_this11.db) {
668
+ reject(new Error('数据库未连接'));
669
+ return;
670
+ }
671
+ var transaction = _this11.db.transaction(storeName, 'readonly');
672
+ var store = transaction.objectStore(storeName);
673
+ var index = store.index(indexName);
674
+ var request = index.count(indexValue);
675
+ request.onsuccess = function () {
676
+ return resolve(request.result);
677
+ };
678
+ request.onerror = function () {
679
+ return reject(new Error('通过索引统计数据数量失败'));
680
+ };
681
+ }));
682
+ case 6:
683
+ case "end":
684
+ return _context11.stop();
685
+ }
686
+ }, _callee11, this);
687
+ }));
688
+ function countByIndex(_x21, _x22, _x23) {
689
+ return _countByIndex.apply(this, arguments);
690
+ }
691
+ return countByIndex;
692
+ }()
333
693
  /**
334
694
  * 获取指定存储对象中的所有数据
335
695
  * @param {string} storeName - 存储对象名称
@@ -340,14 +700,14 @@ var IndexDBManager = /*#__PURE__*/function () {
340
700
  }, {
341
701
  key: "getAll",
342
702
  value: (function () {
343
- var _getAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(storeName) {
344
- var _this6 = this;
703
+ var _getAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(storeName) {
704
+ var _this12 = this;
345
705
  var prefix, results, i, key, value;
346
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
347
- while (1) switch (_context6.prev = _context6.next) {
706
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
707
+ while (1) switch (_context12.prev = _context12.next) {
348
708
  case 0:
349
709
  if (this.useIndexDB) {
350
- _context6.next = 5;
710
+ _context12.next = 5;
351
711
  break;
352
712
  }
353
713
  prefix = this.getStorageKey(storeName);
@@ -364,14 +724,14 @@ var IndexDBManager = /*#__PURE__*/function () {
364
724
  }
365
725
  }
366
726
  }
367
- return _context6.abrupt("return", results);
727
+ return _context12.abrupt("return", results);
368
728
  case 5:
369
- return _context6.abrupt("return", new Promise(function (resolve, reject) {
370
- if (!_this6.db) {
729
+ return _context12.abrupt("return", new Promise(function (resolve, reject) {
730
+ if (!_this12.db) {
371
731
  reject(new Error('数据库未连接'));
372
732
  return;
373
733
  }
374
- var transaction = _this6.db.transaction(storeName, 'readonly');
734
+ var transaction = _this12.db.transaction(storeName, 'readonly');
375
735
  var store = transaction.objectStore(storeName);
376
736
  var request = store.getAll();
377
737
  request.onsuccess = function () {
@@ -383,11 +743,11 @@ var IndexDBManager = /*#__PURE__*/function () {
383
743
  }));
384
744
  case 6:
385
745
  case "end":
386
- return _context6.stop();
746
+ return _context12.stop();
387
747
  }
388
- }, _callee6, this);
748
+ }, _callee12, this);
389
749
  }));
390
- function getAll(_x9) {
750
+ function getAll(_x24) {
391
751
  return _getAll.apply(this, arguments);
392
752
  }
393
753
  return getAll;
@@ -401,14 +761,14 @@ var IndexDBManager = /*#__PURE__*/function () {
401
761
  }, {
402
762
  key: "clear",
403
763
  value: (function () {
404
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(storeName) {
405
- var _this7 = this;
764
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(storeName) {
765
+ var _this13 = this;
406
766
  var prefix, keysToRemove, i, key;
407
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
408
- while (1) switch (_context7.prev = _context7.next) {
767
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
768
+ while (1) switch (_context13.prev = _context13.next) {
409
769
  case 0:
410
770
  if (this.useIndexDB) {
411
- _context7.next = 6;
771
+ _context13.next = 6;
412
772
  break;
413
773
  }
414
774
  prefix = this.getStorageKey(storeName);
@@ -420,16 +780,16 @@ var IndexDBManager = /*#__PURE__*/function () {
420
780
  }
421
781
  }
422
782
  keysToRemove.forEach(function (key) {
423
- return _this7.app.storage.removeStorage(key);
783
+ return _this13.app.storage.removeStorage(key);
424
784
  });
425
- return _context7.abrupt("return", true);
785
+ return _context13.abrupt("return", true);
426
786
  case 6:
427
- return _context7.abrupt("return", new Promise(function (resolve, reject) {
428
- if (!_this7.db) {
787
+ return _context13.abrupt("return", new Promise(function (resolve, reject) {
788
+ if (!_this13.db) {
429
789
  reject(new Error('数据库未连接'));
430
790
  return;
431
791
  }
432
- var transaction = _this7.db.transaction(storeName, 'readwrite');
792
+ var transaction = _this13.db.transaction(storeName, 'readwrite');
433
793
  var store = transaction.objectStore(storeName);
434
794
  var request = store.clear();
435
795
  request.onsuccess = function () {
@@ -441,11 +801,11 @@ var IndexDBManager = /*#__PURE__*/function () {
441
801
  }));
442
802
  case 7:
443
803
  case "end":
444
- return _context7.stop();
804
+ return _context13.stop();
445
805
  }
446
- }, _callee7, this);
806
+ }, _callee13, this);
447
807
  }));
448
- function clear(_x10) {
808
+ function clear(_x25) {
449
809
  return _clear.apply(this, arguments);
450
810
  }
451
811
  return clear;
@@ -499,7 +859,8 @@ var IndexDBManager = /*#__PURE__*/function () {
499
859
  * name: 'users',
500
860
  * keyPath: 'id',
501
861
  * indexes: [
502
- * { name: 'email', keyPath: 'email', options: { unique: true } }
862
+ * { name: 'email', keyPath: 'email', options: { unique: true } },
863
+ * { name: 'department', keyPath: 'department', options: { unique: false } }
503
864
  * ]
504
865
  * },
505
866
  * {
@@ -510,33 +871,55 @@ var IndexDBManager = /*#__PURE__*/function () {
510
871
  * };
511
872
  *
512
873
  * // 2. 创建并连接数据库
513
- * const db = new IndexDBManager(dbOptions);
874
+ * const db = new IndexDBManager(app, dbOptions);
514
875
  * await db.connect();
515
876
  *
516
877
  * // 3. 添加数据
517
- * const user = { id: '1', name: '张三', email: 'zhangsan@example.com' };
878
+ * const user = { id: '1', name: '张三', email: 'zhangsan@example.com', department: 'IT' };
518
879
  * await db.add('users', user);
519
880
  *
520
881
  * // 4. 获取数据
521
882
  * const retrievedUser = await db.get('users', '1');
522
883
  *
523
- * // 5. 更新数据
884
+ * // 5. 快速检查数据是否存在(推荐用法)
885
+ * const userExists = await db.exists('users', '1'); // 返回 true/false,比 get 更高效
886
+ *
887
+ * // 6. 通过索引获取数据
888
+ * const userByEmail = await db.getByIndex('users', 'email', 'zhangsan@example.com');
889
+ *
890
+ * // 7. 通过索引检查数据是否存在
891
+ * const emailExists = await db.existsByIndex('users', 'email', 'zhangsan@example.com');
892
+ *
893
+ * // 8. 通过索引获取多条数据
894
+ * const itUsers = await db.getAllByIndex('users', 'department', 'IT');
895
+ *
896
+ * // 9. 统计数据数量
897
+ * const totalUsers = await db.count('users');
898
+ * const itUserCount = await db.countByIndex('users', 'department', 'IT');
899
+ *
900
+ * // 10. 更新数据
524
901
  * user.name = '张三 (已更新)';
525
902
  * await db.update('users', user);
526
903
  *
527
- * // 6. 获取所有数据
904
+ * // 11. 获取所有数据
528
905
  * const allUsers = await db.getAll('users');
529
906
  *
530
- * // 7. 删除数据
907
+ * // 12. 删除数据
531
908
  * await db.delete('users', '1');
532
909
  *
533
- * // 8. 清空存储对象
910
+ * // 13. 清空存储对象
534
911
  * await db.clear('users');
535
912
  *
536
- * // 9. 关闭数据库连接
913
+ * // 14. 关闭数据库连接
537
914
  * db.close();
538
915
  *
539
- * // 10. 检查当前使用的存储方式
916
+ * // 15. 检查当前使用的存储方式
540
917
  * const storageType = db.getCurrentStorage(); // 'indexDB' 或 'localStorage'
918
+ *
919
+ * // 性能优化建议:
920
+ * // - 使用 exists() 而不是 get() 来检查数据是否存在
921
+ * // - 为常用查询字段创建索引
922
+ * // - 使用索引查询方法来提高查询效率
923
+ * // - 批量操作时使用事务(可以考虑后续扩展)
541
924
  */
542
925
  export default IndexDBManager;