@pisell/core 1.1.1 → 1.1.2

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.
@@ -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, log) {
137
+ var _add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(storeName, data) {
138
138
  var _this2 = this;
139
- var _this$stores$find, key, uuid;
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] : true;
143
148
  if (this.useIndexDB) {
144
- _context2.next = 4;
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 4:
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 6:
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, _x3) {
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(_x4, _x5) {
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, log) {
312
+ var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(storeName, key) {
308
313
  var _this4 = this;
309
- var uuid, storageKey, data;
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] : true;
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 = 7;
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 7:
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 8:
431
+ case 9:
422
432
  case "end":
423
433
  return _context4.stop();
424
434
  }
425
435
  }, _callee4, this);
426
436
  }));
427
- function get(_x6, _x7, _x8) {
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, log) {
454
+ var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(storeName, data) {
445
455
  var _this5 = this;
446
- var _this$stores$find2, key, uuid;
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] : true;
450
465
  if (this.useIndexDB) {
451
- _context5.next = 4;
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 4:
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
- _this5.app.logger.addLog({
491
- type: 'info',
492
- title: uuid,
493
- metadata: {
494
- msg: '数据更新完成'
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
- _this5.app.logger.addLog({
502
- type: 'info',
503
- title: uuid,
504
- metadata: {
505
- msg: '数据更新失败'
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
- _this5.app.logger.addLog({
512
- type: 'info',
513
- title: uuid,
514
- metadata: {
515
- msg: '事务完成'
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
- _this5.app.logger.addLog({
522
- type: 'info',
523
- title: uuid,
524
- metadata: {
525
- msg: '事务被中止'
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
- _this5.app.logger.addLog({
533
- type: 'info',
534
- title: uuid,
535
- metadata: {
536
- msg: '事务错误'
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 7:
570
+ case 8:
546
571
  case "end":
547
572
  return _context5.stop();
548
573
  }
549
574
  }, _callee5, this);
550
575
  }));
551
- function update(_x9, _x10, _x11) {
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(_x12, _x13) {
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(_x14, _x15, _x16) {
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(_x17, _x18, _x19) {
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(_x20, _x21, _x22) {
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(_x23) {
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(_x24, _x25, _x26) {
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(_x27) {
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(_x28) {
1057
+ function clear(_x25) {
1033
1058
  return _clear.apply(this, arguments);
1034
1059
  }
1035
1060
  return clear;
@@ -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 = true) {
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 = true) {
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 = true) {
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
- this.app.logger.addLog({
351
- type: "info",
352
- title: uuid,
353
- metadata: { msg: "数据更新完成" }
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
- this.app.logger.addLog({
359
- type: "info",
360
- title: uuid,
361
- metadata: { msg: "数据更新失败" }
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
- this.app.logger.addLog({
367
- type: "info",
368
- title: uuid,
369
- metadata: { msg: "事务完成" }
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
- this.app.logger.addLog({
375
- type: "info",
376
- title: uuid,
377
- metadata: { msg: "事务被中止" }
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
- this.app.logger.addLog({
383
- type: "info",
384
- title: uuid,
385
- metadata: { msg: "事务错误" }
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/core",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "sideEffects": false,
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",