@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.
- package/es/app/app.d.ts +87 -0
- package/es/app/const.d.ts +4 -0
- package/es/app/index.d.ts +14 -0
- package/es/applicationManager/application.d.ts +50 -0
- package/es/applicationManager/index.d.ts +13 -0
- package/es/aws/index.d.ts +16 -0
- package/es/cmd/const.d.ts +11 -0
- package/es/cmd/index.d.ts +13 -0
- package/es/cmd/type.d.ts +5 -0
- package/es/config.d.ts +3 -0
- package/es/cookie/index.d.ts +13 -0
- package/es/data/index.d.ts +8 -0
- package/es/history/config.d.ts +24 -0
- package/es/history/index.d.ts +20 -0
- package/es/history/type.d.ts +2 -0
- package/es/hooks/index.d.ts +12 -0
- package/es/hooks/useDelayedValue/index.d.ts +2 -0
- package/es/hooks/useDispatch/index.d.ts +2 -0
- package/es/hooks/useLowCode/index.d.ts +13 -0
- package/es/hooks/useStore/index.d.ts +6 -0
- package/es/index.d.ts +6 -0
- package/es/indexDB/index.d.ts +248 -0
- package/es/indexDB/index.js +453 -70
- package/es/locales/en.d.ts +3 -0
- package/es/locales/index.d.ts +39 -0
- package/es/locales/original.d.ts +3 -0
- package/es/locales/type.d.ts +19 -0
- package/es/locales/zh-CN.d.ts +3 -0
- package/es/locales/zh-HK.d.ts +3 -0
- package/es/logger/feishu.d.ts +11 -0
- package/es/menuManager/hooks.d.ts +17 -0
- package/es/menuManager/index.d.ts +28 -0
- package/es/models/global.d.ts +32 -0
- package/es/models/index.d.ts +45 -0
- package/es/models/type.d.ts +2 -0
- package/es/plugin/index.d.ts +0 -0
- package/es/pubsub/example.d.ts +5 -0
- package/es/pubsub/index.d.ts +63 -0
- package/es/request/cache.d.ts +46 -0
- package/es/request/cancelToken.d.ts +38 -0
- package/es/request/config.d.ts +3 -0
- package/es/request/constants.d.ts +2 -0
- package/es/request/index.d.ts +24 -0
- package/es/request/pisell2Request.d.ts +6 -0
- package/es/request/type.d.ts +41 -0
- package/es/request/utils.d.ts +46 -0
- package/es/routes/config.d.ts +7 -0
- package/es/routes/index.d.ts +28 -0
- package/es/socket/components/SocketMonitorPage.d.ts +6 -0
- package/es/socket/components/index.d.ts +2 -0
- package/es/socket/constants.d.ts +33 -0
- package/es/socket/events.d.ts +31 -0
- package/es/socket/heartbeat.d.ts +66 -0
- package/es/socket/index.d.ts +61 -0
- package/es/socket/monitor.d.ts +169 -0
- package/es/socket/reconnect.d.ts +61 -0
- package/es/socket/socket.d.ts +130 -0
- package/es/socket/types.d.ts +84 -0
- package/es/storage/index.d.ts +17 -0
- package/es/tasks/index.d.ts +83 -0
- package/es/tasks/type.d.ts +62 -0
- package/es/tasks/useTasks.d.ts +5 -0
- package/es/type.d.ts +2 -0
- package/es/variables/VariablesProvider.d.ts +7 -0
- package/es/variables/config.d.ts +3 -0
- package/es/variables/index.d.ts +6 -0
- package/es/variables/type.d.ts +2 -0
- package/es/website/index.d.ts +6 -0
- package/lib/app/app.d.ts +87 -0
- package/lib/app/const.d.ts +4 -0
- package/lib/app/index.d.ts +14 -0
- package/lib/applicationManager/application.d.ts +50 -0
- package/lib/applicationManager/index.d.ts +13 -0
- package/lib/aws/index.d.ts +16 -0
- package/lib/cmd/const.d.ts +11 -0
- package/lib/cmd/index.d.ts +13 -0
- package/lib/cmd/type.d.ts +5 -0
- package/lib/config.d.ts +3 -0
- package/lib/cookie/index.d.ts +13 -0
- package/lib/data/index.d.ts +8 -0
- package/lib/history/config.d.ts +24 -0
- package/lib/history/index.d.ts +20 -0
- package/lib/history/type.d.ts +2 -0
- package/lib/hooks/index.d.ts +12 -0
- package/lib/hooks/useDelayedValue/index.d.ts +2 -0
- package/lib/hooks/useDispatch/index.d.ts +2 -0
- package/lib/hooks/useLowCode/index.d.ts +13 -0
- package/lib/hooks/useStore/index.d.ts +6 -0
- package/lib/index.d.ts +6 -0
- package/lib/indexDB/index.d.ts +248 -0
- package/lib/indexDB/index.js +159 -0
- package/lib/locales/en.d.ts +3 -0
- package/lib/locales/index.d.ts +39 -0
- package/lib/locales/original.d.ts +3 -0
- package/lib/locales/type.d.ts +19 -0
- package/lib/locales/zh-CN.d.ts +3 -0
- package/lib/locales/zh-HK.d.ts +3 -0
- package/lib/logger/feishu.d.ts +11 -0
- package/lib/menuManager/hooks.d.ts +17 -0
- package/lib/menuManager/index.d.ts +28 -0
- package/lib/models/global.d.ts +32 -0
- package/lib/models/index.d.ts +45 -0
- package/lib/models/type.d.ts +2 -0
- package/lib/plugin/index.d.ts +0 -0
- package/lib/pubsub/example.d.ts +5 -0
- package/lib/pubsub/index.d.ts +63 -0
- package/lib/request/cache.d.ts +46 -0
- package/lib/request/cancelToken.d.ts +38 -0
- package/lib/request/config.d.ts +3 -0
- package/lib/request/constants.d.ts +2 -0
- package/lib/request/index.d.ts +24 -0
- package/lib/request/pisell2Request.d.ts +6 -0
- package/lib/request/type.d.ts +41 -0
- package/lib/request/utils.d.ts +46 -0
- package/lib/routes/config.d.ts +7 -0
- package/lib/routes/index.d.ts +28 -0
- package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
- package/lib/socket/components/index.d.ts +2 -0
- package/lib/socket/constants.d.ts +33 -0
- package/lib/socket/events.d.ts +31 -0
- package/lib/socket/heartbeat.d.ts +66 -0
- package/lib/socket/index.d.ts +61 -0
- package/lib/socket/monitor.d.ts +169 -0
- package/lib/socket/reconnect.d.ts +61 -0
- package/lib/socket/socket.d.ts +130 -0
- package/lib/socket/types.d.ts +84 -0
- package/lib/storage/index.d.ts +17 -0
- package/lib/tasks/index.d.ts +83 -0
- package/lib/tasks/type.d.ts +62 -0
- package/lib/tasks/useTasks.d.ts +5 -0
- package/lib/type.d.ts +2 -0
- package/lib/variables/VariablesProvider.d.ts +7 -0
- package/lib/variables/config.d.ts +3 -0
- package/lib/variables/index.d.ts +6 -0
- package/lib/variables/type.d.ts +2 -0
- package/lib/website/index.d.ts +6 -0
- package/package.json +8 -8
package/es/indexDB/index.js
CHANGED
|
@@ -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
|
|
188
|
-
var
|
|
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
|
|
191
|
-
while (1) switch (
|
|
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
|
-
|
|
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
|
|
251
|
+
return _context4.abrupt("return", data);
|
|
203
252
|
case 5:
|
|
204
|
-
return
|
|
205
|
-
if (!
|
|
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 =
|
|
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
|
|
270
|
+
return _context4.stop();
|
|
222
271
|
}
|
|
223
|
-
},
|
|
272
|
+
}, _callee4, this);
|
|
224
273
|
}));
|
|
225
|
-
function get(
|
|
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
|
|
242
|
-
var
|
|
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
|
|
245
|
-
while (1) switch (
|
|
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
|
-
|
|
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
|
|
304
|
+
return _context5.abrupt("return", data);
|
|
256
305
|
case 4:
|
|
257
|
-
return
|
|
258
|
-
if (!
|
|
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 =
|
|
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
|
|
323
|
+
return _context5.stop();
|
|
275
324
|
}
|
|
276
|
-
},
|
|
325
|
+
}, _callee5, this);
|
|
277
326
|
}));
|
|
278
|
-
function update(
|
|
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
|
|
294
|
-
var
|
|
342
|
+
var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(storeName, key) {
|
|
343
|
+
var _this6 = this;
|
|
295
344
|
var storageKey;
|
|
296
|
-
return _regeneratorRuntime().wrap(function
|
|
297
|
-
while (1) switch (
|
|
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
|
-
|
|
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
|
|
354
|
+
return _context6.abrupt("return", true);
|
|
306
355
|
case 4:
|
|
307
|
-
return
|
|
308
|
-
if (!
|
|
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 =
|
|
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
|
|
373
|
+
return _context6.stop();
|
|
325
374
|
}
|
|
326
|
-
},
|
|
375
|
+
}, _callee6, this);
|
|
327
376
|
}));
|
|
328
|
-
function _delete(
|
|
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
|
|
344
|
-
var
|
|
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
|
|
347
|
-
while (1) switch (
|
|
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
|
-
|
|
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
|
|
727
|
+
return _context12.abrupt("return", results);
|
|
368
728
|
case 5:
|
|
369
|
-
return
|
|
370
|
-
if (!
|
|
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 =
|
|
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
|
|
746
|
+
return _context12.stop();
|
|
387
747
|
}
|
|
388
|
-
},
|
|
748
|
+
}, _callee12, this);
|
|
389
749
|
}));
|
|
390
|
-
function getAll(
|
|
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
|
|
405
|
-
var
|
|
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
|
|
408
|
-
while (1) switch (
|
|
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
|
-
|
|
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
|
|
783
|
+
return _this13.app.storage.removeStorage(key);
|
|
424
784
|
});
|
|
425
|
-
return
|
|
785
|
+
return _context13.abrupt("return", true);
|
|
426
786
|
case 6:
|
|
427
|
-
return
|
|
428
|
-
if (!
|
|
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 =
|
|
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
|
|
804
|
+
return _context13.stop();
|
|
445
805
|
}
|
|
446
|
-
},
|
|
806
|
+
}, _callee13, this);
|
|
447
807
|
}));
|
|
448
|
-
function clear(
|
|
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
|
-
* //
|
|
904
|
+
* // 11. 获取所有数据
|
|
528
905
|
* const allUsers = await db.getAll('users');
|
|
529
906
|
*
|
|
530
|
-
* //
|
|
907
|
+
* // 12. 删除数据
|
|
531
908
|
* await db.delete('users', '1');
|
|
532
909
|
*
|
|
533
|
-
* //
|
|
910
|
+
* // 13. 清空存储对象
|
|
534
911
|
* await db.clear('users');
|
|
535
912
|
*
|
|
536
|
-
* //
|
|
913
|
+
* // 14. 关闭数据库连接
|
|
537
914
|
* db.close();
|
|
538
915
|
*
|
|
539
|
-
* //
|
|
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;
|