@pisell/core 1.1.1 → 1.1.3
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/indexDB/index.js +87 -62
- package/lib/indexDB/index.js +38 -28
- package/package.json +1 -1
package/es/indexDB/index.js
CHANGED
|
@@ -134,14 +134,19 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
134
134
|
}, {
|
|
135
135
|
key: "add",
|
|
136
136
|
value: (function () {
|
|
137
|
-
var _add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(storeName, data
|
|
137
|
+
var _add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(storeName, data) {
|
|
138
138
|
var _this2 = this;
|
|
139
|
-
var
|
|
139
|
+
var log,
|
|
140
|
+
_this$stores$find,
|
|
141
|
+
key,
|
|
142
|
+
uuid,
|
|
143
|
+
_args2 = arguments;
|
|
140
144
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
141
145
|
while (1) switch (_context2.prev = _context2.next) {
|
|
142
146
|
case 0:
|
|
147
|
+
log = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : false;
|
|
143
148
|
if (this.useIndexDB) {
|
|
144
|
-
_context2.next =
|
|
149
|
+
_context2.next = 5;
|
|
145
150
|
break;
|
|
146
151
|
}
|
|
147
152
|
key = this.getStorageKey(storeName, data[((_this$stores$find = this.stores.find(function (s) {
|
|
@@ -149,7 +154,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
149
154
|
})) === null || _this$stores$find === void 0 ? void 0 : _this$stores$find.keyPath) || 'id']);
|
|
150
155
|
this.app.storage.setStorage(key, JSON.stringify(data));
|
|
151
156
|
return _context2.abrupt("return", data);
|
|
152
|
-
case
|
|
157
|
+
case 5:
|
|
153
158
|
uuid = "[ IndexDB ] ADD: - ".concat(storeName, " - ").concat(dayjs().valueOf());
|
|
154
159
|
return _context2.abrupt("return", new Promise(function (resolve, reject) {
|
|
155
160
|
if (!_this2.db) {
|
|
@@ -232,13 +237,13 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
232
237
|
return reject(new Error('事务被中止'));
|
|
233
238
|
};
|
|
234
239
|
}));
|
|
235
|
-
case
|
|
240
|
+
case 7:
|
|
236
241
|
case "end":
|
|
237
242
|
return _context2.stop();
|
|
238
243
|
}
|
|
239
244
|
}, _callee2, this);
|
|
240
245
|
}));
|
|
241
|
-
function add(_x, _x2
|
|
246
|
+
function add(_x, _x2) {
|
|
242
247
|
return _add.apply(this, arguments);
|
|
243
248
|
}
|
|
244
249
|
return add;
|
|
@@ -287,7 +292,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
287
292
|
}
|
|
288
293
|
}, _callee3, this);
|
|
289
294
|
}));
|
|
290
|
-
function exists(
|
|
295
|
+
function exists(_x3, _x4) {
|
|
291
296
|
return _exists.apply(this, arguments);
|
|
292
297
|
}
|
|
293
298
|
return exists;
|
|
@@ -304,12 +309,17 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
304
309
|
}, {
|
|
305
310
|
key: "get",
|
|
306
311
|
value: (function () {
|
|
307
|
-
var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(storeName, key
|
|
312
|
+
var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(storeName, key) {
|
|
308
313
|
var _this4 = this;
|
|
309
|
-
var
|
|
314
|
+
var log,
|
|
315
|
+
uuid,
|
|
316
|
+
storageKey,
|
|
317
|
+
data,
|
|
318
|
+
_args4 = arguments;
|
|
310
319
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
311
320
|
while (1) switch (_context4.prev = _context4.next) {
|
|
312
321
|
case 0:
|
|
322
|
+
log = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : false;
|
|
313
323
|
uuid = "[ IndexDB ] GET: - ".concat(storeName, " - ").concat(key, " - ").concat(dayjs().valueOf());
|
|
314
324
|
if (log) {
|
|
315
325
|
this.app.logger.addLog({
|
|
@@ -321,7 +331,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
321
331
|
});
|
|
322
332
|
}
|
|
323
333
|
if (this.useIndexDB) {
|
|
324
|
-
_context4.next =
|
|
334
|
+
_context4.next = 8;
|
|
325
335
|
break;
|
|
326
336
|
}
|
|
327
337
|
storageKey = this.getStorageKey(storeName, key);
|
|
@@ -330,7 +340,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
330
340
|
data = JSON.parse(data);
|
|
331
341
|
}
|
|
332
342
|
return _context4.abrupt("return", data);
|
|
333
|
-
case
|
|
343
|
+
case 8:
|
|
334
344
|
return _context4.abrupt("return", new Promise(function (resolve, reject) {
|
|
335
345
|
if (!_this4.db) {
|
|
336
346
|
if (log) {
|
|
@@ -418,13 +428,13 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
418
428
|
reject(e);
|
|
419
429
|
}
|
|
420
430
|
}));
|
|
421
|
-
case
|
|
431
|
+
case 9:
|
|
422
432
|
case "end":
|
|
423
433
|
return _context4.stop();
|
|
424
434
|
}
|
|
425
435
|
}, _callee4, this);
|
|
426
436
|
}));
|
|
427
|
-
function get(
|
|
437
|
+
function get(_x5, _x6) {
|
|
428
438
|
return _get.apply(this, arguments);
|
|
429
439
|
}
|
|
430
440
|
return get;
|
|
@@ -441,14 +451,19 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
441
451
|
}, {
|
|
442
452
|
key: "update",
|
|
443
453
|
value: (function () {
|
|
444
|
-
var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(storeName, data
|
|
454
|
+
var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(storeName, data) {
|
|
445
455
|
var _this5 = this;
|
|
446
|
-
var
|
|
456
|
+
var log,
|
|
457
|
+
_this$stores$find2,
|
|
458
|
+
key,
|
|
459
|
+
uuid,
|
|
460
|
+
_args5 = arguments;
|
|
447
461
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
448
462
|
while (1) switch (_context5.prev = _context5.next) {
|
|
449
463
|
case 0:
|
|
464
|
+
log = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : false;
|
|
450
465
|
if (this.useIndexDB) {
|
|
451
|
-
_context5.next =
|
|
466
|
+
_context5.next = 5;
|
|
452
467
|
break;
|
|
453
468
|
}
|
|
454
469
|
key = this.getStorageKey(storeName, data[((_this$stores$find2 = this.stores.find(function (s) {
|
|
@@ -456,7 +471,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
456
471
|
})) === null || _this$stores$find2 === void 0 ? void 0 : _this$stores$find2.keyPath) || 'id']);
|
|
457
472
|
this.app.storage.setStorage(key, JSON.stringify(data));
|
|
458
473
|
return _context5.abrupt("return", data);
|
|
459
|
-
case
|
|
474
|
+
case 5:
|
|
460
475
|
uuid = "[ IndexDB ] UPDATE: - ".concat(storeName, " - ").concat(dayjs().valueOf());
|
|
461
476
|
if (log) {
|
|
462
477
|
this.app.logger.addLog({
|
|
@@ -487,68 +502,78 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
487
502
|
var store = transaction.objectStore(storeName);
|
|
488
503
|
var request = store.put(data);
|
|
489
504
|
request.onsuccess = function () {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
505
|
+
if (log) {
|
|
506
|
+
_this5.app.logger.addLog({
|
|
507
|
+
type: 'info',
|
|
508
|
+
title: uuid,
|
|
509
|
+
metadata: {
|
|
510
|
+
msg: '数据更新完成'
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
}
|
|
497
514
|
return resolve(data);
|
|
498
515
|
};
|
|
499
516
|
request.onerror = function () {
|
|
500
517
|
var _request$error2;
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
518
|
+
if (log) {
|
|
519
|
+
_this5.app.logger.addLog({
|
|
520
|
+
type: 'info',
|
|
521
|
+
title: uuid,
|
|
522
|
+
metadata: {
|
|
523
|
+
msg: '数据更新失败'
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
}
|
|
508
527
|
return reject((_request$error2 = request.error) !== null && _request$error2 !== void 0 ? _request$error2 : new Error('更新数据失败'));
|
|
509
528
|
};
|
|
510
529
|
transaction.oncomplete = function () {
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
530
|
+
if (log) {
|
|
531
|
+
_this5.app.logger.addLog({
|
|
532
|
+
type: 'info',
|
|
533
|
+
title: uuid,
|
|
534
|
+
metadata: {
|
|
535
|
+
msg: '事务完成'
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
}
|
|
518
539
|
return console.log('✅ 事务完成');
|
|
519
540
|
};
|
|
520
541
|
transaction.onabort = function (e) {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
542
|
+
if (log) {
|
|
543
|
+
_this5.app.logger.addLog({
|
|
544
|
+
type: 'info',
|
|
545
|
+
title: uuid,
|
|
546
|
+
metadata: {
|
|
547
|
+
msg: '事务被中止'
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
}
|
|
528
551
|
return reject(new Error('事务被中止'));
|
|
529
552
|
};
|
|
530
553
|
transaction.onerror = function (e) {
|
|
531
554
|
var _transaction$error2;
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
555
|
+
if (log) {
|
|
556
|
+
_this5.app.logger.addLog({
|
|
557
|
+
type: 'info',
|
|
558
|
+
title: uuid,
|
|
559
|
+
metadata: {
|
|
560
|
+
msg: '事务错误'
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
}
|
|
539
564
|
return reject((_transaction$error2 = transaction.error) !== null && _transaction$error2 !== void 0 ? _transaction$error2 : new Error('事务错误'));
|
|
540
565
|
};
|
|
541
566
|
} catch (e) {
|
|
542
567
|
reject(e);
|
|
543
568
|
}
|
|
544
569
|
}));
|
|
545
|
-
case
|
|
570
|
+
case 8:
|
|
546
571
|
case "end":
|
|
547
572
|
return _context5.stop();
|
|
548
573
|
}
|
|
549
574
|
}, _callee5, this);
|
|
550
575
|
}));
|
|
551
|
-
function update(
|
|
576
|
+
function update(_x7, _x8) {
|
|
552
577
|
return _update.apply(this, arguments);
|
|
553
578
|
}
|
|
554
579
|
return update;
|
|
@@ -598,7 +623,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
598
623
|
}
|
|
599
624
|
}, _callee6, this);
|
|
600
625
|
}));
|
|
601
|
-
function _delete(
|
|
626
|
+
function _delete(_x9, _x10) {
|
|
602
627
|
return _delete2.apply(this, arguments);
|
|
603
628
|
}
|
|
604
629
|
return _delete;
|
|
@@ -667,7 +692,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
667
692
|
}
|
|
668
693
|
}, _callee7, this);
|
|
669
694
|
}));
|
|
670
|
-
function getByIndex(
|
|
695
|
+
function getByIndex(_x11, _x12, _x13) {
|
|
671
696
|
return _getByIndex.apply(this, arguments);
|
|
672
697
|
}
|
|
673
698
|
return getByIndex;
|
|
@@ -735,7 +760,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
735
760
|
}
|
|
736
761
|
}, _callee8, this);
|
|
737
762
|
}));
|
|
738
|
-
function existsByIndex(
|
|
763
|
+
function existsByIndex(_x14, _x15, _x16) {
|
|
739
764
|
return _existsByIndex.apply(this, arguments);
|
|
740
765
|
}
|
|
741
766
|
return existsByIndex;
|
|
@@ -804,7 +829,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
804
829
|
}
|
|
805
830
|
}, _callee9, this);
|
|
806
831
|
}));
|
|
807
|
-
function getAllByIndex(
|
|
832
|
+
function getAllByIndex(_x17, _x18, _x19) {
|
|
808
833
|
return _getAllByIndex.apply(this, arguments);
|
|
809
834
|
}
|
|
810
835
|
return getAllByIndex;
|
|
@@ -855,7 +880,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
855
880
|
}
|
|
856
881
|
}, _callee10, this);
|
|
857
882
|
}));
|
|
858
|
-
function count(
|
|
883
|
+
function count(_x20) {
|
|
859
884
|
return _count.apply(this, arguments);
|
|
860
885
|
}
|
|
861
886
|
return count;
|
|
@@ -909,7 +934,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
909
934
|
}
|
|
910
935
|
}, _callee11, this);
|
|
911
936
|
}));
|
|
912
|
-
function countByIndex(
|
|
937
|
+
function countByIndex(_x21, _x22, _x23) {
|
|
913
938
|
return _countByIndex.apply(this, arguments);
|
|
914
939
|
}
|
|
915
940
|
return countByIndex;
|
|
@@ -971,7 +996,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
971
996
|
}
|
|
972
997
|
}, _callee12, this);
|
|
973
998
|
}));
|
|
974
|
-
function getAll(
|
|
999
|
+
function getAll(_x24) {
|
|
975
1000
|
return _getAll.apply(this, arguments);
|
|
976
1001
|
}
|
|
977
1002
|
return getAll;
|
|
@@ -1029,7 +1054,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1029
1054
|
}
|
|
1030
1055
|
}, _callee13, this);
|
|
1031
1056
|
}));
|
|
1032
|
-
function clear(
|
|
1057
|
+
function clear(_x25) {
|
|
1033
1058
|
return _clear.apply(this, arguments);
|
|
1034
1059
|
}
|
|
1035
1060
|
return clear;
|
package/lib/indexDB/index.js
CHANGED
|
@@ -110,7 +110,7 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
110
110
|
* @returns {Promise<T>} 添加的数据
|
|
111
111
|
* @template T
|
|
112
112
|
*/
|
|
113
|
-
async add(storeName, data, log) {
|
|
113
|
+
async add(storeName, data, log = false) {
|
|
114
114
|
var _a;
|
|
115
115
|
if (!this.useIndexDB) {
|
|
116
116
|
const key = this.getStorageKey(storeName, data[((_a = this.stores.find((s) => s.name === storeName)) == null ? void 0 : _a.keyPath) || "id"]);
|
|
@@ -217,7 +217,7 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
217
217
|
* @returns {Promise<T|null>} 获取的数据,不存在则返回 null
|
|
218
218
|
* @template T
|
|
219
219
|
*/
|
|
220
|
-
async get(storeName, key, log) {
|
|
220
|
+
async get(storeName, key, log = false) {
|
|
221
221
|
const uuid = `[ IndexDB ] GET: - ${storeName} - ${key} - ${(0, import_dayjs.default)().valueOf()}`;
|
|
222
222
|
if (log) {
|
|
223
223
|
this.app.logger.addLog({
|
|
@@ -315,7 +315,7 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
315
315
|
* @returns {Promise<T>} 更新后的数据
|
|
316
316
|
* @template T
|
|
317
317
|
*/
|
|
318
|
-
async update(storeName, data, log) {
|
|
318
|
+
async update(storeName, data, log = false) {
|
|
319
319
|
var _a;
|
|
320
320
|
if (!this.useIndexDB) {
|
|
321
321
|
const key = this.getStorageKey(storeName, data[((_a = this.stores.find((s) => s.name === storeName)) == null ? void 0 : _a.keyPath) || "id"]);
|
|
@@ -347,43 +347,53 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
347
347
|
const store = transaction.objectStore(storeName);
|
|
348
348
|
const request = store.put(data);
|
|
349
349
|
request.onsuccess = () => {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
350
|
+
if (log) {
|
|
351
|
+
this.app.logger.addLog({
|
|
352
|
+
type: "info",
|
|
353
|
+
title: uuid,
|
|
354
|
+
metadata: { msg: "数据更新完成" }
|
|
355
|
+
});
|
|
356
|
+
}
|
|
355
357
|
return resolve(data);
|
|
356
358
|
};
|
|
357
359
|
request.onerror = () => {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
360
|
+
if (log) {
|
|
361
|
+
this.app.logger.addLog({
|
|
362
|
+
type: "info",
|
|
363
|
+
title: uuid,
|
|
364
|
+
metadata: { msg: "数据更新失败" }
|
|
365
|
+
});
|
|
366
|
+
}
|
|
363
367
|
return reject(request.error ?? new Error("更新数据失败"));
|
|
364
368
|
};
|
|
365
369
|
transaction.oncomplete = () => {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
370
|
+
if (log) {
|
|
371
|
+
this.app.logger.addLog({
|
|
372
|
+
type: "info",
|
|
373
|
+
title: uuid,
|
|
374
|
+
metadata: { msg: "事务完成" }
|
|
375
|
+
});
|
|
376
|
+
}
|
|
371
377
|
return console.log("✅ 事务完成");
|
|
372
378
|
};
|
|
373
379
|
transaction.onabort = (e) => {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
380
|
+
if (log) {
|
|
381
|
+
this.app.logger.addLog({
|
|
382
|
+
type: "info",
|
|
383
|
+
title: uuid,
|
|
384
|
+
metadata: { msg: "事务被中止" }
|
|
385
|
+
});
|
|
386
|
+
}
|
|
379
387
|
return reject(new Error("事务被中止"));
|
|
380
388
|
};
|
|
381
389
|
transaction.onerror = (e) => {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
390
|
+
if (log) {
|
|
391
|
+
this.app.logger.addLog({
|
|
392
|
+
type: "info",
|
|
393
|
+
title: uuid,
|
|
394
|
+
metadata: { msg: "事务错误" }
|
|
395
|
+
});
|
|
396
|
+
}
|
|
387
397
|
return reject(transaction.error ?? new Error("事务错误"));
|
|
388
398
|
};
|
|
389
399
|
} catch (e) {
|