@pisell/core 1.0.33 → 1.0.35

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 (63) hide show
  1. package/es/app/app.d.ts +7 -7
  2. package/es/app/index.d.ts +1 -1
  3. package/es/applicationManager/application.d.ts +2 -2
  4. package/es/cmd/const.d.ts +5 -5
  5. package/es/hooks/useStore/index.d.ts +1 -1
  6. package/es/indexDB/index.d.ts +2 -2
  7. package/es/indexDB/index.js +633 -572
  8. package/es/locales/type.d.ts +3 -3
  9. package/es/logger/index.d.ts +1 -1
  10. package/es/models/index.d.ts +4 -4
  11. package/es/pubsub/index.d.ts +1 -1
  12. package/es/request/cache.d.ts +1 -1
  13. package/es/request/pisell2Request.d.ts +1 -1
  14. package/es/request/type.d.ts +1 -1
  15. package/es/routes/index.d.ts +2 -2
  16. package/es/socket/monitor.js +2 -0
  17. package/es/socket/types.d.ts +4 -3
  18. package/es/tasks/index.d.ts +0 -1
  19. package/es/tasks/index.js +0 -1
  20. package/es/tasks/type.d.ts +4 -4
  21. package/es/variables/index.d.ts +3 -3
  22. package/lib/app/app.d.ts +7 -7
  23. package/lib/app/app.js +21 -51
  24. package/lib/app/index.d.ts +1 -1
  25. package/lib/applicationManager/application.d.ts +2 -2
  26. package/lib/applicationManager/application.js +6 -12
  27. package/lib/applicationManager/index.js +4 -2
  28. package/lib/aws/index.js +0 -3
  29. package/lib/cmd/const.d.ts +5 -5
  30. package/lib/cmd/const.js +5 -5
  31. package/lib/cmd/index.js +0 -2
  32. package/lib/cookie/index.js +4 -2
  33. package/lib/data/index.js +0 -3
  34. package/lib/history/index.js +22 -24
  35. package/lib/hooks/useStore/index.d.ts +1 -1
  36. package/lib/indexDB/index.d.ts +2 -2
  37. package/lib/indexDB/index.js +233 -327
  38. package/lib/locales/index.js +94 -95
  39. package/lib/locales/type.d.ts +3 -3
  40. package/lib/logger/index.d.ts +1 -1
  41. package/lib/logger/index.js +8 -18
  42. package/lib/menuManager/index.js +12 -9
  43. package/lib/models/index.d.ts +4 -4
  44. package/lib/pubsub/index.d.ts +1 -1
  45. package/lib/pubsub/index.js +3 -1
  46. package/lib/request/cache.d.ts +1 -1
  47. package/lib/request/pisell2Request.d.ts +1 -1
  48. package/lib/request/type.d.ts +1 -1
  49. package/lib/routes/index.d.ts +2 -2
  50. package/lib/routes/index.js +1 -3
  51. package/lib/socket/components/SocketMonitorPage.js +12 -6
  52. package/lib/socket/heartbeat.js +5 -10
  53. package/lib/socket/index.js +3 -1
  54. package/lib/socket/monitor.js +26 -26
  55. package/lib/socket/reconnect.js +3 -10
  56. package/lib/socket/socket.js +10 -12
  57. package/lib/socket/types.d.ts +4 -3
  58. package/lib/storage/index.js +24 -25
  59. package/lib/tasks/index.d.ts +0 -1
  60. package/lib/tasks/index.js +329 -334
  61. package/lib/tasks/type.d.ts +4 -4
  62. package/lib/variables/index.d.ts +3 -3
  63. package/package.json +3 -2
@@ -1,5 +1,11 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
2
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
7
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
3
9
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
10
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
11
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -9,10 +15,12 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
9
15
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
10
16
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
11
17
  import dayjs from 'dayjs';
18
+ import Dexie from 'dexie';
19
+
12
20
  /**
13
21
  * IndexDB 管理器模块
14
22
  *
15
- * 这个模块提供了对浏览器 IndexedDB 的简单封装,并在不支持 IndexedDB 的环境中
23
+ * 这个模块使用 Dexie.js 提供了对浏览器 IndexedDB 的简单封装,并在不支持 IndexedDB 的环境中
16
24
  * 自动降级使用内存存储作为备选存储方案。
17
25
  */
18
26
 
@@ -31,7 +39,7 @@ import dayjs from 'dayjs';
31
39
  */
32
40
  /**
33
41
  * IndexDB 管理器类
34
- * 提供对 IndexedDB 的简单封装,支持自动降级到内存存储
42
+ * 使用 Dexie.js 提供对 IndexedDB 的封装,支持自动降级到内存存储
35
43
  * @class IndexDBManager
36
44
  */
37
45
  var IndexDBManager = /*#__PURE__*/function () {
@@ -79,8 +87,9 @@ var IndexDBManager = /*#__PURE__*/function () {
79
87
  key: "withTimeout",
80
88
  value: function withTimeout(promise, operation) {
81
89
  var _this2 = this;
82
- return Promise.race([promise, new Promise(function (_, reject) {
83
- setTimeout(function () {
90
+ var timeoutId = null;
91
+ var timeoutPromise = new Promise(function (_, reject) {
92
+ timeoutId = setTimeout(function () {
84
93
  var error = new Error("\u64CD\u4F5C\u8D85\u65F6: ".concat(operation, " \u5728 ").concat(_this2.timeout, "ms \u5185\u672A\u5B8C\u6210"));
85
94
  _this2.app.logger.addLog({
86
95
  type: 'error',
@@ -93,7 +102,16 @@ var IndexDBManager = /*#__PURE__*/function () {
93
102
  });
94
103
  reject(error);
95
104
  }, _this2.timeout);
96
- })]);
105
+ });
106
+ return Promise.race([promise.then(function (result) {
107
+ // Promise 成功完成,清除超时定时器
108
+ if (timeoutId) clearTimeout(timeoutId);
109
+ return result;
110
+ }, function (error) {
111
+ // Promise 失败,清除超时定时器
112
+ if (timeoutId) clearTimeout(timeoutId);
113
+ throw error;
114
+ }), timeoutPromise]);
97
115
  }
98
116
 
99
117
  /**
@@ -104,89 +122,99 @@ var IndexDBManager = /*#__PURE__*/function () {
104
122
  }, {
105
123
  key: "connect",
106
124
  value: (function () {
107
- var _connect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
125
+ var _connect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
108
126
  var _this3 = this;
109
- return _regeneratorRuntime().wrap(function _callee$(_context) {
110
- while (1) switch (_context.prev = _context.next) {
127
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
128
+ while (1) switch (_context2.prev = _context2.next) {
111
129
  case 0:
112
130
  if (this.useIndexDB) {
113
- _context.next = 2;
131
+ _context2.next = 2;
114
132
  break;
115
133
  }
116
- return _context.abrupt("return", true);
134
+ return _context2.abrupt("return", true);
117
135
  case 2:
118
- return _context.abrupt("return", this.withTimeout(new Promise(function (resolve, reject) {
119
- var request = indexedDB.open(_this3.dbName, _this3.version);
120
- request.onerror = function (event) {
121
- var _event$target;
122
- _this3.app.logger.addLog({
123
- type: 'error',
124
- title: '[ IndexDB ] ERROR',
125
- metadata: {
126
- msg: 'DB request error',
127
- data: event,
128
- message: event === null || event === void 0 || (_event$target = event.target) === null || _event$target === void 0 || (_event$target = _event$target.error) === null || _event$target === void 0 ? void 0 : _event$target.message
129
- }
130
- });
131
- };
132
- request.onsuccess = function (event) {
133
- _this3.db = event.target.result;
134
- resolve(true);
135
- };
136
- request.onblocked = function () {
137
- _this3.app.logger.addLog({
138
- type: 'error',
139
- title: '[ IndexDB ] blocked',
140
- metadata: {
141
- msg: 'DB blocked'
142
- }
143
- });
144
- };
145
- request.onupgradeneeded = function (event) {};
146
- request.onupgradeneeded = function (event) {
147
- var db = event.target.result;
148
- db.onerror = function (event) {
149
- var _event$target2;
150
- _this3.app.logger.addLog({
151
- type: 'error',
152
- title: '[ IndexDB ] ERROR',
153
- metadata: {
154
- msg: 'DB error',
155
- data: event,
156
- message: event === null || event === void 0 || (_event$target2 = event.target) === null || _event$target2 === void 0 || (_event$target2 = _event$target2.error) === null || _event$target2 === void 0 ? void 0 : _event$target2.message
157
- }
158
- });
159
- };
160
- db.onclose = function (event) {
161
- var _event$target3;
162
- _this3.app.logger.addLog({
163
- type: 'error',
164
- title: '[ IndexDB ] CLOSE',
165
- metadata: {
166
- msg: 'DB close',
167
- data: event,
168
- message: event === null || event === void 0 || (_event$target3 = event.target) === null || _event$target3 === void 0 || (_event$target3 = _event$target3.error) === null || _event$target3 === void 0 ? void 0 : _event$target3.message
169
- }
170
- });
171
- };
172
- _this3.stores.forEach(function (store) {
173
- if (!db.objectStoreNames.contains(store.name)) {
174
- var _store$indexes;
175
- var objectStore = db.createObjectStore(store.name, {
176
- keyPath: store.keyPath
136
+ return _context2.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
137
+ var schema;
138
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
139
+ while (1) switch (_context.prev = _context.next) {
140
+ case 0:
141
+ _context.prev = 0;
142
+ // 创建 Dexie 实例
143
+ _this3.db = new Dexie(_this3.dbName);
144
+
145
+ // 构建 schema
146
+ schema = {};
147
+ _this3.stores.forEach(function (store) {
148
+ var _store$indexes;
149
+ // Dexie schema 格式: "primaryKey, index1, index2, ..."
150
+ var indexes = ((_store$indexes = store.indexes) === null || _store$indexes === void 0 ? void 0 : _store$indexes.map(function (index) {
151
+ var _index$options, _index$options2;
152
+ var indexStr = index.name;
153
+ // Dexie 使用 & 表示复合索引,* 表示多值索引,+ 表示自增主键
154
+ if ((_index$options = index.options) !== null && _index$options !== void 0 && _index$options.unique) {
155
+ indexStr = "&".concat(indexStr);
156
+ }
157
+ if ((_index$options2 = index.options) !== null && _index$options2 !== void 0 && _index$options2.multiEntry) {
158
+ indexStr = "*".concat(indexStr);
159
+ }
160
+ return indexStr;
161
+ })) || [];
162
+
163
+ // 主键需要放在最前面,使用 ++ 表示自增,& 表示唯一
164
+ var primaryKey = store.keyPath;
165
+ schema[store.name] = [primaryKey].concat(_toConsumableArray(indexes)).join(',');
177
166
  });
178
- (_store$indexes = store.indexes) === null || _store$indexes === void 0 || _store$indexes.forEach(function (index) {
179
- objectStore.createIndex(index.name, index.keyPath, index.options);
167
+
168
+ // 定义数据库版本和 schema
169
+ _this3.db.version(_this3.version).stores(schema);
170
+
171
+ // 打开数据库
172
+ _context.next = 7;
173
+ return _this3.db.open();
174
+ case 7:
175
+ // 监听错误和关闭事件
176
+ _this3.db.on('blocked', function () {
177
+ _this3.app.logger.addLog({
178
+ type: 'error',
179
+ title: '[ IndexDB ] blocked',
180
+ metadata: {
181
+ msg: 'DB blocked'
182
+ }
183
+ });
184
+ });
185
+ _this3.db.on('close', function () {
186
+ _this3.app.logger.addLog({
187
+ type: 'error',
188
+ title: '[ IndexDB ] CLOSE',
189
+ metadata: {
190
+ msg: 'DB close'
191
+ }
192
+ });
193
+ });
194
+ return _context.abrupt("return", true);
195
+ case 12:
196
+ _context.prev = 12;
197
+ _context.t0 = _context["catch"](0);
198
+ _this3.app.logger.addLog({
199
+ type: 'error',
200
+ title: '[ IndexDB ] ERROR',
201
+ metadata: {
202
+ msg: 'DB request error',
203
+ message: _context.t0.message
204
+ }
180
205
  });
181
- }
182
- });
183
- };
184
- }), 'connect'));
206
+ throw _context.t0;
207
+ case 16:
208
+ case "end":
209
+ return _context.stop();
210
+ }
211
+ }, _callee, null, [[0, 12]]);
212
+ }))(), 'connect'));
185
213
  case 3:
186
214
  case "end":
187
- return _context.stop();
215
+ return _context2.stop();
188
216
  }
189
- }, _callee, this);
217
+ }, _callee2, this);
190
218
  }));
191
219
  function connect() {
192
220
  return _connect.apply(this, arguments);
@@ -222,21 +250,21 @@ var IndexDBManager = /*#__PURE__*/function () {
222
250
  }, {
223
251
  key: "add",
224
252
  value: (function () {
225
- var _add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(storeName, data) {
253
+ var _add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(storeName, data) {
226
254
  var _this4 = this;
227
255
  var log,
228
256
  storeConfig,
229
257
  keyPath,
230
- key,
258
+ _key,
231
259
  memStore,
232
260
  uuid,
233
- _args2 = arguments;
234
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
235
- while (1) switch (_context2.prev = _context2.next) {
261
+ _args4 = arguments;
262
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
263
+ while (1) switch (_context4.prev = _context4.next) {
236
264
  case 0:
237
- log = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : false;
265
+ log = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : false;
238
266
  if (this.useIndexDB) {
239
- _context2.next = 8;
267
+ _context4.next = 8;
240
268
  break;
241
269
  }
242
270
  // 使用内存存储
@@ -244,10 +272,10 @@ var IndexDBManager = /*#__PURE__*/function () {
244
272
  return s.name === storeName;
245
273
  });
246
274
  keyPath = (storeConfig === null || storeConfig === void 0 ? void 0 : storeConfig.keyPath) || 'id';
247
- key = data[keyPath];
275
+ _key = data[keyPath];
248
276
  memStore = this.getMemoryStore(storeName);
249
- memStore.set(key, data);
250
- return _context2.abrupt("return", data);
277
+ memStore.set(_key, data);
278
+ return _context4.abrupt("return", data);
251
279
  case 8:
252
280
  uuid = "[ IndexDB ] ADD: - ".concat(storeName, " - ").concat(dayjs().valueOf());
253
281
  if (log) {
@@ -260,92 +288,73 @@ var IndexDBManager = /*#__PURE__*/function () {
260
288
  }
261
289
  });
262
290
  }
263
- return _context2.abrupt("return", this.withTimeout(new Promise(function (resolve, reject) {
264
- if (!_this4.db) {
265
- if (log) {
266
- _this4.app.logger.addLog({
267
- type: 'error',
268
- title: uuid,
269
- metadata: {
270
- msg: '添加数据前 数据库未连接',
271
- data: data
291
+ return _context4.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
292
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
293
+ while (1) switch (_context3.prev = _context3.next) {
294
+ case 0:
295
+ if (_this4.db) {
296
+ _context3.next = 3;
297
+ break;
272
298
  }
273
- });
274
- }
275
- reject(new Error('数据库未连接'));
276
- return;
277
- }
278
- var transaction = _this4.db.transaction(storeName, 'readwrite');
279
- var store = transaction.objectStore(storeName);
280
- var request = store.add(data);
281
- request.onsuccess = function () {
282
- if (log) {
283
- _this4.app.logger.addLog({
284
- type: 'info',
285
- title: uuid,
286
- metadata: {
287
- msg: '添加数据成功'
299
+ if (log) {
300
+ _this4.app.logger.addLog({
301
+ type: 'error',
302
+ title: uuid,
303
+ metadata: {
304
+ msg: '添加数据前 数据库未连接',
305
+ data: data
306
+ }
307
+ });
288
308
  }
289
- });
290
- }
291
- return resolve(data);
292
- };
293
- request.onerror = function () {
294
- if (log) {
295
- _this4.app.logger.addLog({
296
- type: 'error',
297
- title: uuid,
298
- metadata: {
299
- msg: '添加数据失败'
309
+ throw new Error('数据库未连接');
310
+ case 3:
311
+ _context3.prev = 3;
312
+ _context3.next = 6;
313
+ return _this4.db.table(storeName).add(data);
314
+ case 6:
315
+ if (log) {
316
+ _this4.app.logger.addLog({
317
+ type: 'info',
318
+ title: uuid,
319
+ metadata: {
320
+ msg: '添加数据成功'
321
+ }
322
+ });
323
+ console.log('✅ 添加事务完成');
324
+ _this4.app.logger.addLog({
325
+ type: 'info',
326
+ title: uuid,
327
+ metadata: {
328
+ msg: '事务完成'
329
+ }
330
+ });
300
331
  }
301
- });
302
- }
303
- return reject(new Error('添加数据失败'));
304
- };
305
- transaction.oncomplete = function () {
306
- console.log('✅ 添加事务完成');
307
- if (log) {
308
- _this4.app.logger.addLog({
309
- type: 'info',
310
- title: uuid,
311
- metadata: {
312
- msg: '事务完成'
313
- }
314
- });
315
- }
316
- return;
317
- };
318
- transaction.onerror = function (e) {
319
- var _transaction$error;
320
- if (log) {
321
- _this4.app.logger.addLog({
322
- type: 'error',
323
- title: uuid,
324
- metadata: {
325
- msg: '事务错误'
326
- }
327
- });
328
- }
329
- return reject((_transaction$error = transaction.error) !== null && _transaction$error !== void 0 ? _transaction$error : new Error('事务错误'));
330
- };
331
- transaction.onabort = function (e) {
332
- if (log) {
333
- _this4.app.logger.addLog({
334
- type: 'error',
335
- title: uuid,
336
- metadata: {
337
- msg: '事务被中止'
332
+ return _context3.abrupt("return", data);
333
+ case 10:
334
+ _context3.prev = 10;
335
+ _context3.t0 = _context3["catch"](3);
336
+ if (log) {
337
+ _this4.app.logger.addLog({
338
+ type: 'error',
339
+ title: uuid,
340
+ metadata: {
341
+ msg: '添加数据失败',
342
+ error: _context3.t0.message
343
+ }
344
+ });
338
345
  }
339
- });
346
+ throw new Error('添加数据失败');
347
+ case 14:
348
+ case "end":
349
+ return _context3.stop();
340
350
  }
341
- return reject(new Error('事务被中止'));
342
- };
343
- }), "add(".concat(storeName, ")")));
351
+ }, _callee3, null, [[3, 10]]);
352
+ }))(), "add(".concat(storeName, ")")));
344
353
  case 11:
345
354
  case "end":
346
- return _context2.stop();
355
+ return _context4.stop();
347
356
  }
348
- }, _callee2, this);
357
+ }, _callee4, this);
349
358
  }));
350
359
  function add(_x, _x2) {
351
360
  return _add.apply(this, arguments);
@@ -362,40 +371,52 @@ var IndexDBManager = /*#__PURE__*/function () {
362
371
  }, {
363
372
  key: "exists",
364
373
  value: (function () {
365
- var _exists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(storeName, key) {
374
+ var _exists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(storeName, key) {
366
375
  var _this5 = this;
367
376
  var memStore;
368
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
369
- while (1) switch (_context3.prev = _context3.next) {
377
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
378
+ while (1) switch (_context6.prev = _context6.next) {
370
379
  case 0:
371
380
  if (this.useIndexDB) {
372
- _context3.next = 3;
381
+ _context6.next = 3;
373
382
  break;
374
383
  }
375
384
  // 使用内存存储
376
385
  memStore = this.getMemoryStore(storeName);
377
- return _context3.abrupt("return", memStore.has(key));
386
+ return _context6.abrupt("return", memStore.has(key));
378
387
  case 3:
379
- return _context3.abrupt("return", this.withTimeout(new Promise(function (resolve, reject) {
380
- if (!_this5.db) {
381
- reject(new Error('数据库未连接'));
382
- return;
383
- }
384
- var transaction = _this5.db.transaction(storeName, 'readonly');
385
- var store = transaction.objectStore(storeName);
386
- var request = store.count(key);
387
- request.onsuccess = function () {
388
- return resolve(request.result > 0);
389
- };
390
- request.onerror = function () {
391
- return reject(new Error('检查数据存在性失败'));
392
- };
393
- }), "exists(".concat(storeName, ")")));
388
+ return _context6.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
389
+ var result;
390
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
391
+ while (1) switch (_context5.prev = _context5.next) {
392
+ case 0:
393
+ if (_this5.db) {
394
+ _context5.next = 2;
395
+ break;
396
+ }
397
+ throw new Error('数据库未连接');
398
+ case 2:
399
+ _context5.prev = 2;
400
+ _context5.next = 5;
401
+ return _this5.db.table(storeName).get(key);
402
+ case 5:
403
+ result = _context5.sent;
404
+ return _context5.abrupt("return", result !== undefined);
405
+ case 9:
406
+ _context5.prev = 9;
407
+ _context5.t0 = _context5["catch"](2);
408
+ throw new Error('检查数据存在性失败');
409
+ case 12:
410
+ case "end":
411
+ return _context5.stop();
412
+ }
413
+ }, _callee5, null, [[2, 9]]);
414
+ }))(), "exists(".concat(storeName, ")")));
394
415
  case 4:
395
416
  case "end":
396
- return _context3.stop();
417
+ return _context6.stop();
397
418
  }
398
- }, _callee3, this);
419
+ }, _callee6, this);
399
420
  }));
400
421
  function exists(_x3, _x4) {
401
422
  return _exists.apply(this, arguments);
@@ -414,17 +435,17 @@ var IndexDBManager = /*#__PURE__*/function () {
414
435
  }, {
415
436
  key: "get",
416
437
  value: (function () {
417
- var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(storeName, key) {
438
+ var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(storeName, key) {
418
439
  var _this6 = this;
419
440
  var log,
420
441
  uuid,
421
442
  _memStore$get,
422
443
  memStore,
423
- _args4 = arguments;
424
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
425
- while (1) switch (_context4.prev = _context4.next) {
444
+ _args8 = arguments;
445
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
446
+ while (1) switch (_context8.prev = _context8.next) {
426
447
  case 0:
427
- log = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : false;
448
+ log = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : false;
428
449
  uuid = "[ IndexDB ] GET: - ".concat(storeName, " - ").concat(key, " - ").concat(dayjs().valueOf());
429
450
  if (log) {
430
451
  this.app.logger.addLog({
@@ -436,105 +457,80 @@ var IndexDBManager = /*#__PURE__*/function () {
436
457
  });
437
458
  }
438
459
  if (this.useIndexDB) {
439
- _context4.next = 6;
460
+ _context8.next = 6;
440
461
  break;
441
462
  }
442
463
  // 使用内存存储
443
464
  memStore = this.getMemoryStore(storeName);
444
- return _context4.abrupt("return", (_memStore$get = memStore.get(key)) !== null && _memStore$get !== void 0 ? _memStore$get : null);
465
+ return _context8.abrupt("return", (_memStore$get = memStore.get(key)) !== null && _memStore$get !== void 0 ? _memStore$get : null);
445
466
  case 6:
446
- return _context4.abrupt("return", this.withTimeout(new Promise(function (resolve, reject) {
447
- if (!_this6.db) {
448
- if (log) {
449
- _this6.app.logger.addLog({
450
- type: 'error',
451
- title: uuid,
452
- metadata: {
453
- msg: '数据库未连接'
467
+ return _context8.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
468
+ var result;
469
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
470
+ while (1) switch (_context7.prev = _context7.next) {
471
+ case 0:
472
+ if (_this6.db) {
473
+ _context7.next = 3;
474
+ break;
475
+ }
476
+ if (log) {
477
+ _this6.app.logger.addLog({
478
+ type: 'error',
479
+ title: uuid,
480
+ metadata: {
481
+ msg: '数据库未连接'
482
+ }
483
+ });
484
+ }
485
+ throw new Error('数据库未连接');
486
+ case 3:
487
+ _context7.prev = 3;
488
+ _context7.next = 6;
489
+ return _this6.db.table(storeName).get(key);
490
+ case 6:
491
+ result = _context7.sent;
492
+ if (log) {
493
+ _this6.app.logger.addLog({
494
+ type: 'info',
495
+ title: uuid,
496
+ metadata: {
497
+ msg: '获取成功'
498
+ }
499
+ });
500
+ _this6.app.logger.addLog({
501
+ type: 'info',
502
+ title: uuid,
503
+ metadata: {
504
+ msg: '事务完成'
505
+ }
506
+ });
507
+ }
508
+ return _context7.abrupt("return", result !== null && result !== void 0 ? result : null);
509
+ case 11:
510
+ _context7.prev = 11;
511
+ _context7.t0 = _context7["catch"](3);
512
+ if (log) {
513
+ _this6.app.logger.addLog({
514
+ type: 'error',
515
+ title: uuid,
516
+ metadata: {
517
+ msg: '获取失败',
518
+ error: _context7.t0.message
519
+ }
520
+ });
454
521
  }
455
- });
522
+ throw new Error('获取数据失败');
523
+ case 15:
524
+ case "end":
525
+ return _context7.stop();
456
526
  }
457
- reject(new Error('数据库未连接'));
458
- return;
459
- }
460
- var resolved = false;
461
- try {
462
- var transaction = _this6.db.transaction(storeName, 'readonly');
463
- var store = transaction.objectStore(storeName);
464
- var request = store.get(key);
465
- request.onsuccess = function () {
466
- var _request$result;
467
- resolved = true;
468
- if (log) {
469
- _this6.app.logger.addLog({
470
- type: 'info',
471
- title: uuid,
472
- metadata: {
473
- msg: '获取成功'
474
- }
475
- });
476
- }
477
- resolve((_request$result = request.result) !== null && _request$result !== void 0 ? _request$result : null);
478
- };
479
- request.onerror = function () {
480
- var _request$error;
481
- resolved = true;
482
- if (log) {
483
- _this6.app.logger.addLog({
484
- type: 'error',
485
- title: uuid,
486
- metadata: {
487
- msg: '获取失败'
488
- }
489
- });
490
- }
491
- reject((_request$error = request.error) !== null && _request$error !== void 0 ? _request$error : new Error('获取数据失败'));
492
- };
493
- transaction.onabort = function () {
494
- if (log) {
495
- _this6.app.logger.addLog({
496
- type: 'info',
497
- title: uuid,
498
- metadata: {
499
- msg: '事务被中止'
500
- }
501
- });
502
- }
503
- if (!resolved) reject(new Error('事务被中止'));
504
- };
505
- transaction.onerror = function (event) {
506
- if (log) {
507
- _this6.app.logger.addLog({
508
- type: 'error',
509
- title: uuid,
510
- metadata: {
511
- msg: "\u4E8B\u52A1\u9519\u8BEF: ".concat(event.target.error)
512
- }
513
- });
514
- }
515
- if (!resolved) reject(new Error("\u4E8B\u52A1\u9519\u8BEF: ".concat(event.target.error)));
516
- };
517
- transaction.oncomplete = function () {
518
- if (log) {
519
- _this6.app.logger.addLog({
520
- type: 'info',
521
- title: uuid,
522
- metadata: {
523
- msg: '事务完成'
524
- }
525
- });
526
- }
527
- // ✅ 事务顺利结束
528
- };
529
- } catch (e) {
530
- reject(e);
531
- }
532
- }), "get(".concat(storeName, ")")));
527
+ }, _callee7, null, [[3, 11]]);
528
+ }))(), "get(".concat(storeName, ")")));
533
529
  case 7:
534
530
  case "end":
535
- return _context4.stop();
531
+ return _context8.stop();
536
532
  }
537
- }, _callee4, this);
533
+ }, _callee8, this);
538
534
  }));
539
535
  function get(_x5, _x6) {
540
536
  return _get.apply(this, arguments);
@@ -553,21 +549,21 @@ var IndexDBManager = /*#__PURE__*/function () {
553
549
  }, {
554
550
  key: "update",
555
551
  value: (function () {
556
- var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(storeName, data) {
552
+ var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(storeName, data) {
557
553
  var _this7 = this;
558
554
  var log,
559
555
  storeConfig,
560
556
  keyPath,
561
- key,
557
+ _key2,
562
558
  memStore,
563
559
  uuid,
564
- _args5 = arguments;
565
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
566
- while (1) switch (_context5.prev = _context5.next) {
560
+ _args10 = arguments;
561
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
562
+ while (1) switch (_context10.prev = _context10.next) {
567
563
  case 0:
568
- log = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : false;
564
+ log = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : false;
569
565
  if (this.useIndexDB) {
570
- _context5.next = 8;
566
+ _context10.next = 8;
571
567
  break;
572
568
  }
573
569
  // 使用内存存储
@@ -575,10 +571,10 @@ var IndexDBManager = /*#__PURE__*/function () {
575
571
  return s.name === storeName;
576
572
  });
577
573
  keyPath = (storeConfig === null || storeConfig === void 0 ? void 0 : storeConfig.keyPath) || 'id';
578
- key = data[keyPath];
574
+ _key2 = data[keyPath];
579
575
  memStore = this.getMemoryStore(storeName);
580
- memStore.set(key, data);
581
- return _context5.abrupt("return", data);
576
+ memStore.set(_key2, data);
577
+ return _context10.abrupt("return", data);
582
578
  case 8:
583
579
  uuid = "[ IndexDB ] UPDATE: - ".concat(storeName, " - ").concat(dayjs().valueOf());
584
580
  if (log) {
@@ -591,95 +587,72 @@ var IndexDBManager = /*#__PURE__*/function () {
591
587
  }
592
588
  });
593
589
  }
594
- return _context5.abrupt("return", this.withTimeout(new Promise(function (resolve, reject) {
595
- if (!_this7.db) {
596
- if (log) {
597
- _this7.app.logger.addLog({
598
- type: 'error',
599
- title: uuid,
600
- metadata: {
601
- msg: '数据库未连接'
590
+ return _context10.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
591
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
592
+ while (1) switch (_context9.prev = _context9.next) {
593
+ case 0:
594
+ if (_this7.db) {
595
+ _context9.next = 3;
596
+ break;
597
+ }
598
+ if (log) {
599
+ _this7.app.logger.addLog({
600
+ type: 'error',
601
+ title: uuid,
602
+ metadata: {
603
+ msg: '数据库未连接'
604
+ }
605
+ });
606
+ }
607
+ throw new Error('数据库未连接');
608
+ case 3:
609
+ _context9.prev = 3;
610
+ _context9.next = 6;
611
+ return _this7.db.table(storeName).put(data);
612
+ case 6:
613
+ if (log) {
614
+ _this7.app.logger.addLog({
615
+ type: 'info',
616
+ title: uuid,
617
+ metadata: {
618
+ msg: '数据更新完成'
619
+ }
620
+ });
621
+ console.log('✅ 事务完成');
622
+ _this7.app.logger.addLog({
623
+ type: 'info',
624
+ title: uuid,
625
+ metadata: {
626
+ msg: '事务完成'
627
+ }
628
+ });
629
+ }
630
+ return _context9.abrupt("return", data);
631
+ case 10:
632
+ _context9.prev = 10;
633
+ _context9.t0 = _context9["catch"](3);
634
+ if (log) {
635
+ _this7.app.logger.addLog({
636
+ type: 'error',
637
+ title: uuid,
638
+ metadata: {
639
+ msg: '数据更新失败',
640
+ error: _context9.t0.message
641
+ }
642
+ });
602
643
  }
603
- });
644
+ throw new Error('更新数据失败');
645
+ case 14:
646
+ case "end":
647
+ return _context9.stop();
604
648
  }
605
- reject(new Error('数据库未连接'));
606
- return;
607
- }
608
- try {
609
- var transaction = _this7.db.transaction(storeName, 'readwrite');
610
- var store = transaction.objectStore(storeName);
611
- var request = store.put(data);
612
- request.onsuccess = function () {
613
- if (log) {
614
- _this7.app.logger.addLog({
615
- type: 'info',
616
- title: uuid,
617
- metadata: {
618
- msg: '数据更新完成'
619
- }
620
- });
621
- }
622
- return resolve(data);
623
- };
624
- request.onerror = function () {
625
- var _request$error2;
626
- if (log) {
627
- _this7.app.logger.addLog({
628
- type: 'error',
629
- title: uuid,
630
- metadata: {
631
- msg: '数据更新失败'
632
- }
633
- });
634
- }
635
- return reject((_request$error2 = request.error) !== null && _request$error2 !== void 0 ? _request$error2 : new Error('更新数据失败'));
636
- };
637
- transaction.oncomplete = function () {
638
- if (log) {
639
- _this7.app.logger.addLog({
640
- type: 'info',
641
- title: uuid,
642
- metadata: {
643
- msg: '事务完成'
644
- }
645
- });
646
- }
647
- return console.log('✅ 事务完成');
648
- };
649
- transaction.onabort = function (e) {
650
- if (log) {
651
- _this7.app.logger.addLog({
652
- type: 'error',
653
- title: uuid,
654
- metadata: {
655
- msg: '事务被中止'
656
- }
657
- });
658
- }
659
- return reject(new Error('事务被中止'));
660
- };
661
- transaction.onerror = function (e) {
662
- var _transaction$error2;
663
- if (log) {
664
- _this7.app.logger.addLog({
665
- type: 'error',
666
- title: uuid,
667
- metadata: {
668
- msg: '事务错误'
669
- }
670
- });
671
- }
672
- return reject((_transaction$error2 = transaction.error) !== null && _transaction$error2 !== void 0 ? _transaction$error2 : new Error('事务错误'));
673
- };
674
- } catch (e) {
675
- reject(e);
676
- }
677
- }), "update(".concat(storeName, ")")));
649
+ }, _callee9, null, [[3, 10]]);
650
+ }))(), "update(".concat(storeName, ")")));
678
651
  case 11:
679
652
  case "end":
680
- return _context5.stop();
653
+ return _context10.stop();
681
654
  }
682
- }, _callee5, this);
655
+ }, _callee10, this);
683
656
  }));
684
657
  function update(_x7, _x8) {
685
658
  return _update.apply(this, arguments);
@@ -696,40 +669,50 @@ var IndexDBManager = /*#__PURE__*/function () {
696
669
  }, {
697
670
  key: "delete",
698
671
  value: (function () {
699
- var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(storeName, key) {
672
+ var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(storeName, key) {
700
673
  var _this8 = this;
701
674
  var memStore;
702
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
703
- while (1) switch (_context6.prev = _context6.next) {
675
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
676
+ while (1) switch (_context12.prev = _context12.next) {
704
677
  case 0:
705
678
  if (this.useIndexDB) {
706
- _context6.next = 3;
679
+ _context12.next = 3;
707
680
  break;
708
681
  }
709
682
  // 使用内存存储
710
683
  memStore = this.getMemoryStore(storeName);
711
- return _context6.abrupt("return", memStore.delete(key));
684
+ return _context12.abrupt("return", memStore.delete(key));
712
685
  case 3:
713
- return _context6.abrupt("return", this.withTimeout(new Promise(function (resolve, reject) {
714
- if (!_this8.db) {
715
- reject(new Error('数据库未连接'));
716
- return;
717
- }
718
- var transaction = _this8.db.transaction(storeName, 'readwrite');
719
- var store = transaction.objectStore(storeName);
720
- var request = store.delete(key);
721
- request.onsuccess = function () {
722
- return resolve(true);
723
- };
724
- request.onerror = function () {
725
- return reject(new Error('删除数据失败'));
726
- };
727
- }), "delete(".concat(storeName, ")")));
686
+ return _context12.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
687
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
688
+ while (1) switch (_context11.prev = _context11.next) {
689
+ case 0:
690
+ if (_this8.db) {
691
+ _context11.next = 2;
692
+ break;
693
+ }
694
+ throw new Error('数据库未连接');
695
+ case 2:
696
+ _context11.prev = 2;
697
+ _context11.next = 5;
698
+ return _this8.db.table(storeName).delete(key);
699
+ case 5:
700
+ return _context11.abrupt("return", true);
701
+ case 8:
702
+ _context11.prev = 8;
703
+ _context11.t0 = _context11["catch"](2);
704
+ throw new Error('删除数据失败');
705
+ case 11:
706
+ case "end":
707
+ return _context11.stop();
708
+ }
709
+ }, _callee11, null, [[2, 8]]);
710
+ }))(), "delete(".concat(storeName, ")")));
728
711
  case 4:
729
712
  case "end":
730
- return _context6.stop();
713
+ return _context12.stop();
731
714
  }
732
- }, _callee6, this);
715
+ }, _callee12, this);
733
716
  }));
734
717
  function _delete(_x9, _x10) {
735
718
  return _delete2.apply(this, arguments);
@@ -748,20 +731,20 @@ var IndexDBManager = /*#__PURE__*/function () {
748
731
  }, {
749
732
  key: "getByIndex",
750
733
  value: (function () {
751
- var _getByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(storeName, indexName, indexValue) {
734
+ var _getByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(storeName, indexName, indexValue) {
752
735
  var _this9 = this;
753
736
  var _storeConfig$indexes, allData, storeConfig, index;
754
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
755
- while (1) switch (_context7.prev = _context7.next) {
737
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
738
+ while (1) switch (_context14.prev = _context14.next) {
756
739
  case 0:
757
740
  if (this.useIndexDB) {
758
- _context7.next = 9;
741
+ _context14.next = 9;
759
742
  break;
760
743
  }
761
- _context7.next = 3;
744
+ _context14.next = 3;
762
745
  return this.getAll(storeName);
763
746
  case 3:
764
- allData = _context7.sent;
747
+ allData = _context14.sent;
765
748
  storeConfig = this.stores.find(function (s) {
766
749
  return s.name === storeName;
767
750
  });
@@ -769,36 +752,47 @@ var IndexDBManager = /*#__PURE__*/function () {
769
752
  return i.name === indexName;
770
753
  });
771
754
  if (index) {
772
- _context7.next = 8;
755
+ _context14.next = 8;
773
756
  break;
774
757
  }
775
- return _context7.abrupt("return", null);
758
+ return _context14.abrupt("return", null);
776
759
  case 8:
777
- return _context7.abrupt("return", allData.find(function (item) {
760
+ return _context14.abrupt("return", allData.find(function (item) {
778
761
  return item[index.keyPath] === indexValue;
779
762
  }) || null);
780
763
  case 9:
781
- return _context7.abrupt("return", this.withTimeout(new Promise(function (resolve, reject) {
782
- if (!_this9.db) {
783
- reject(new Error('数据库未连接'));
784
- return;
785
- }
786
- var transaction = _this9.db.transaction(storeName, 'readonly');
787
- var store = transaction.objectStore(storeName);
788
- var index = store.index(indexName);
789
- var request = index.get(indexValue);
790
- request.onsuccess = function () {
791
- return resolve(request.result || null);
792
- };
793
- request.onerror = function () {
794
- return reject(new Error('通过索引获取数据失败'));
795
- };
796
- }), "getByIndex(".concat(storeName, ", ").concat(indexName, ")")));
764
+ return _context14.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
765
+ var result;
766
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
767
+ while (1) switch (_context13.prev = _context13.next) {
768
+ case 0:
769
+ if (_this9.db) {
770
+ _context13.next = 2;
771
+ break;
772
+ }
773
+ throw new Error('数据库未连接');
774
+ case 2:
775
+ _context13.prev = 2;
776
+ _context13.next = 5;
777
+ return _this9.db.table(storeName).where(indexName).equals(indexValue).first();
778
+ case 5:
779
+ result = _context13.sent;
780
+ return _context13.abrupt("return", result || null);
781
+ case 9:
782
+ _context13.prev = 9;
783
+ _context13.t0 = _context13["catch"](2);
784
+ throw new Error('通过索引获取数据失败');
785
+ case 12:
786
+ case "end":
787
+ return _context13.stop();
788
+ }
789
+ }, _callee13, null, [[2, 9]]);
790
+ }))(), "getByIndex(".concat(storeName, ", ").concat(indexName, ")")));
797
791
  case 10:
798
792
  case "end":
799
- return _context7.stop();
793
+ return _context14.stop();
800
794
  }
801
- }, _callee7, this);
795
+ }, _callee14, this);
802
796
  }));
803
797
  function getByIndex(_x11, _x12, _x13) {
804
798
  return _getByIndex.apply(this, arguments);
@@ -816,20 +810,20 @@ var IndexDBManager = /*#__PURE__*/function () {
816
810
  }, {
817
811
  key: "existsByIndex",
818
812
  value: (function () {
819
- var _existsByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(storeName, indexName, indexValue) {
813
+ var _existsByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(storeName, indexName, indexValue) {
820
814
  var _this10 = this;
821
815
  var _storeConfig$indexes2, allData, storeConfig, index;
822
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
823
- while (1) switch (_context8.prev = _context8.next) {
816
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
817
+ while (1) switch (_context16.prev = _context16.next) {
824
818
  case 0:
825
819
  if (this.useIndexDB) {
826
- _context8.next = 9;
820
+ _context16.next = 9;
827
821
  break;
828
822
  }
829
- _context8.next = 3;
823
+ _context16.next = 3;
830
824
  return this.getAll(storeName);
831
825
  case 3:
832
- allData = _context8.sent;
826
+ allData = _context16.sent;
833
827
  storeConfig = this.stores.find(function (s) {
834
828
  return s.name === storeName;
835
829
  });
@@ -837,36 +831,47 @@ var IndexDBManager = /*#__PURE__*/function () {
837
831
  return i.name === indexName;
838
832
  });
839
833
  if (index) {
840
- _context8.next = 8;
834
+ _context16.next = 8;
841
835
  break;
842
836
  }
843
- return _context8.abrupt("return", false);
837
+ return _context16.abrupt("return", false);
844
838
  case 8:
845
- return _context8.abrupt("return", allData.some(function (item) {
839
+ return _context16.abrupt("return", allData.some(function (item) {
846
840
  return item[index.keyPath] === indexValue;
847
841
  }));
848
842
  case 9:
849
- return _context8.abrupt("return", this.withTimeout(new Promise(function (resolve, reject) {
850
- if (!_this10.db) {
851
- reject(new Error('数据库未连接'));
852
- return;
853
- }
854
- var transaction = _this10.db.transaction(storeName, 'readonly');
855
- var store = transaction.objectStore(storeName);
856
- var index = store.index(indexName);
857
- var request = index.count(indexValue);
858
- request.onsuccess = function () {
859
- return resolve(request.result > 0);
860
- };
861
- request.onerror = function () {
862
- return reject(new Error('通过索引检查数据存在性失败'));
863
- };
864
- }), "existsByIndex(".concat(storeName, ", ").concat(indexName, ")")));
843
+ return _context16.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
844
+ var count;
845
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
846
+ while (1) switch (_context15.prev = _context15.next) {
847
+ case 0:
848
+ if (_this10.db) {
849
+ _context15.next = 2;
850
+ break;
851
+ }
852
+ throw new Error('数据库未连接');
853
+ case 2:
854
+ _context15.prev = 2;
855
+ _context15.next = 5;
856
+ return _this10.db.table(storeName).where(indexName).equals(indexValue).count();
857
+ case 5:
858
+ count = _context15.sent;
859
+ return _context15.abrupt("return", count > 0);
860
+ case 9:
861
+ _context15.prev = 9;
862
+ _context15.t0 = _context15["catch"](2);
863
+ throw new Error('通过索引检查数据存在性失败');
864
+ case 12:
865
+ case "end":
866
+ return _context15.stop();
867
+ }
868
+ }, _callee15, null, [[2, 9]]);
869
+ }))(), "existsByIndex(".concat(storeName, ", ").concat(indexName, ")")));
865
870
  case 10:
866
871
  case "end":
867
- return _context8.stop();
872
+ return _context16.stop();
868
873
  }
869
- }, _callee8, this);
874
+ }, _callee16, this);
870
875
  }));
871
876
  function existsByIndex(_x14, _x15, _x16) {
872
877
  return _existsByIndex.apply(this, arguments);
@@ -885,20 +890,20 @@ var IndexDBManager = /*#__PURE__*/function () {
885
890
  }, {
886
891
  key: "getAllByIndex",
887
892
  value: (function () {
888
- var _getAllByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(storeName, indexName, indexValue) {
893
+ var _getAllByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(storeName, indexName, indexValue) {
889
894
  var _this11 = this;
890
895
  var _storeConfig$indexes3, allData, storeConfig, index;
891
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
892
- while (1) switch (_context9.prev = _context9.next) {
896
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
897
+ while (1) switch (_context18.prev = _context18.next) {
893
898
  case 0:
894
899
  if (this.useIndexDB) {
895
- _context9.next = 9;
900
+ _context18.next = 9;
896
901
  break;
897
902
  }
898
- _context9.next = 3;
903
+ _context18.next = 3;
899
904
  return this.getAll(storeName);
900
905
  case 3:
901
- allData = _context9.sent;
906
+ allData = _context18.sent;
902
907
  storeConfig = this.stores.find(function (s) {
903
908
  return s.name === storeName;
904
909
  });
@@ -906,36 +911,47 @@ var IndexDBManager = /*#__PURE__*/function () {
906
911
  return i.name === indexName;
907
912
  });
908
913
  if (index) {
909
- _context9.next = 8;
914
+ _context18.next = 8;
910
915
  break;
911
916
  }
912
- return _context9.abrupt("return", []);
917
+ return _context18.abrupt("return", []);
913
918
  case 8:
914
- return _context9.abrupt("return", allData.filter(function (item) {
919
+ return _context18.abrupt("return", allData.filter(function (item) {
915
920
  return item[index.keyPath] === indexValue;
916
921
  }));
917
922
  case 9:
918
- return _context9.abrupt("return", this.withTimeout(new Promise(function (resolve, reject) {
919
- if (!_this11.db) {
920
- reject(new Error('数据库未连接'));
921
- return;
922
- }
923
- var transaction = _this11.db.transaction(storeName, 'readonly');
924
- var store = transaction.objectStore(storeName);
925
- var index = store.index(indexName);
926
- var request = index.getAll(indexValue);
927
- request.onsuccess = function () {
928
- return resolve(request.result);
929
- };
930
- request.onerror = function () {
931
- return reject(new Error('通过索引获取多条数据失败'));
932
- };
933
- }), "getAllByIndex(".concat(storeName, ", ").concat(indexName, ")")));
923
+ return _context18.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
924
+ var results;
925
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
926
+ while (1) switch (_context17.prev = _context17.next) {
927
+ case 0:
928
+ if (_this11.db) {
929
+ _context17.next = 2;
930
+ break;
931
+ }
932
+ throw new Error('数据库未连接');
933
+ case 2:
934
+ _context17.prev = 2;
935
+ _context17.next = 5;
936
+ return _this11.db.table(storeName).where(indexName).equals(indexValue).toArray();
937
+ case 5:
938
+ results = _context17.sent;
939
+ return _context17.abrupt("return", results);
940
+ case 9:
941
+ _context17.prev = 9;
942
+ _context17.t0 = _context17["catch"](2);
943
+ throw new Error('通过索引获取多条数据失败');
944
+ case 12:
945
+ case "end":
946
+ return _context17.stop();
947
+ }
948
+ }, _callee17, null, [[2, 9]]);
949
+ }))(), "getAllByIndex(".concat(storeName, ", ").concat(indexName, ")")));
934
950
  case 10:
935
951
  case "end":
936
- return _context9.stop();
952
+ return _context18.stop();
937
953
  }
938
- }, _callee9, this);
954
+ }, _callee18, this);
939
955
  }));
940
956
  function getAllByIndex(_x17, _x18, _x19) {
941
957
  return _getAllByIndex.apply(this, arguments);
@@ -951,42 +967,54 @@ var IndexDBManager = /*#__PURE__*/function () {
951
967
  }, {
952
968
  key: "count",
953
969
  value: (function () {
954
- var _count = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(storeName) {
970
+ var _count = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(storeName) {
955
971
  var _this12 = this;
956
972
  var allData;
957
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
958
- while (1) switch (_context10.prev = _context10.next) {
973
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
974
+ while (1) switch (_context20.prev = _context20.next) {
959
975
  case 0:
960
976
  if (this.useIndexDB) {
961
- _context10.next = 5;
977
+ _context20.next = 5;
962
978
  break;
963
979
  }
964
- _context10.next = 3;
980
+ _context20.next = 3;
965
981
  return this.getAll(storeName);
966
982
  case 3:
967
- allData = _context10.sent;
968
- return _context10.abrupt("return", allData.length);
983
+ allData = _context20.sent;
984
+ return _context20.abrupt("return", allData.length);
969
985
  case 5:
970
- return _context10.abrupt("return", this.withTimeout(new Promise(function (resolve, reject) {
971
- if (!_this12.db) {
972
- reject(new Error('数据库未连接'));
973
- return;
974
- }
975
- var transaction = _this12.db.transaction(storeName, 'readonly');
976
- var store = transaction.objectStore(storeName);
977
- var request = store.count();
978
- request.onsuccess = function () {
979
- return resolve(request.result);
980
- };
981
- request.onerror = function () {
982
- return reject(new Error('统计数据数量失败'));
983
- };
984
- }), "count(".concat(storeName, ")")));
986
+ return _context20.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
987
+ var _count2;
988
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
989
+ while (1) switch (_context19.prev = _context19.next) {
990
+ case 0:
991
+ if (_this12.db) {
992
+ _context19.next = 2;
993
+ break;
994
+ }
995
+ throw new Error('数据库未连接');
996
+ case 2:
997
+ _context19.prev = 2;
998
+ _context19.next = 5;
999
+ return _this12.db.table(storeName).count();
1000
+ case 5:
1001
+ _count2 = _context19.sent;
1002
+ return _context19.abrupt("return", _count2);
1003
+ case 9:
1004
+ _context19.prev = 9;
1005
+ _context19.t0 = _context19["catch"](2);
1006
+ throw new Error('统计数据数量失败');
1007
+ case 12:
1008
+ case "end":
1009
+ return _context19.stop();
1010
+ }
1011
+ }, _callee19, null, [[2, 9]]);
1012
+ }))(), "count(".concat(storeName, ")")));
985
1013
  case 6:
986
1014
  case "end":
987
- return _context10.stop();
1015
+ return _context20.stop();
988
1016
  }
989
- }, _callee10, this);
1017
+ }, _callee20, this);
990
1018
  }));
991
1019
  function count(_x20) {
992
1020
  return _count.apply(this, arguments);
@@ -1004,43 +1032,54 @@ var IndexDBManager = /*#__PURE__*/function () {
1004
1032
  }, {
1005
1033
  key: "countByIndex",
1006
1034
  value: (function () {
1007
- var _countByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(storeName, indexName, indexValue) {
1035
+ var _countByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(storeName, indexName, indexValue) {
1008
1036
  var _this13 = this;
1009
1037
  var matchingData;
1010
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1011
- while (1) switch (_context11.prev = _context11.next) {
1038
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1039
+ while (1) switch (_context22.prev = _context22.next) {
1012
1040
  case 0:
1013
1041
  if (this.useIndexDB) {
1014
- _context11.next = 5;
1042
+ _context22.next = 5;
1015
1043
  break;
1016
1044
  }
1017
- _context11.next = 3;
1045
+ _context22.next = 3;
1018
1046
  return this.getAllByIndex(storeName, indexName, indexValue);
1019
1047
  case 3:
1020
- matchingData = _context11.sent;
1021
- return _context11.abrupt("return", matchingData.length);
1048
+ matchingData = _context22.sent;
1049
+ return _context22.abrupt("return", matchingData.length);
1022
1050
  case 5:
1023
- return _context11.abrupt("return", this.withTimeout(new Promise(function (resolve, reject) {
1024
- if (!_this13.db) {
1025
- reject(new Error('数据库未连接'));
1026
- return;
1027
- }
1028
- var transaction = _this13.db.transaction(storeName, 'readonly');
1029
- var store = transaction.objectStore(storeName);
1030
- var index = store.index(indexName);
1031
- var request = index.count(indexValue);
1032
- request.onsuccess = function () {
1033
- return resolve(request.result);
1034
- };
1035
- request.onerror = function () {
1036
- return reject(new Error('通过索引统计数据数量失败'));
1037
- };
1038
- }), "countByIndex(".concat(storeName, ", ").concat(indexName, ")")));
1051
+ return _context22.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1052
+ var count;
1053
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1054
+ while (1) switch (_context21.prev = _context21.next) {
1055
+ case 0:
1056
+ if (_this13.db) {
1057
+ _context21.next = 2;
1058
+ break;
1059
+ }
1060
+ throw new Error('数据库未连接');
1061
+ case 2:
1062
+ _context21.prev = 2;
1063
+ _context21.next = 5;
1064
+ return _this13.db.table(storeName).where(indexName).equals(indexValue).count();
1065
+ case 5:
1066
+ count = _context21.sent;
1067
+ return _context21.abrupt("return", count);
1068
+ case 9:
1069
+ _context21.prev = 9;
1070
+ _context21.t0 = _context21["catch"](2);
1071
+ throw new Error('通过索引统计数据数量失败');
1072
+ case 12:
1073
+ case "end":
1074
+ return _context21.stop();
1075
+ }
1076
+ }, _callee21, null, [[2, 9]]);
1077
+ }))(), "countByIndex(".concat(storeName, ", ").concat(indexName, ")")));
1039
1078
  case 6:
1040
1079
  case "end":
1041
- return _context11.stop();
1080
+ return _context22.stop();
1042
1081
  }
1043
- }, _callee11, this);
1082
+ }, _callee22, this);
1044
1083
  }));
1045
1084
  function countByIndex(_x21, _x22, _x23) {
1046
1085
  return _countByIndex.apply(this, arguments);
@@ -1057,40 +1096,52 @@ var IndexDBManager = /*#__PURE__*/function () {
1057
1096
  }, {
1058
1097
  key: "getAll",
1059
1098
  value: (function () {
1060
- var _getAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(storeName) {
1099
+ var _getAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(storeName) {
1061
1100
  var _this14 = this;
1062
1101
  var memStore;
1063
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1064
- while (1) switch (_context12.prev = _context12.next) {
1102
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1103
+ while (1) switch (_context24.prev = _context24.next) {
1065
1104
  case 0:
1066
1105
  if (this.useIndexDB) {
1067
- _context12.next = 3;
1106
+ _context24.next = 3;
1068
1107
  break;
1069
1108
  }
1070
1109
  // 使用内存存储
1071
1110
  memStore = this.getMemoryStore(storeName);
1072
- return _context12.abrupt("return", Array.from(memStore.values()));
1111
+ return _context24.abrupt("return", Array.from(memStore.values()));
1073
1112
  case 3:
1074
- return _context12.abrupt("return", this.withTimeout(new Promise(function (resolve, reject) {
1075
- if (!_this14.db) {
1076
- reject(new Error('数据库未连接'));
1077
- return;
1078
- }
1079
- var transaction = _this14.db.transaction(storeName, 'readonly');
1080
- var store = transaction.objectStore(storeName);
1081
- var request = store.getAll();
1082
- request.onsuccess = function () {
1083
- return resolve(request.result);
1084
- };
1085
- request.onerror = function () {
1086
- return reject(new Error('获取所有数据失败'));
1087
- };
1088
- }), "getAll(".concat(storeName, ")")));
1113
+ return _context24.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1114
+ var results;
1115
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1116
+ while (1) switch (_context23.prev = _context23.next) {
1117
+ case 0:
1118
+ if (_this14.db) {
1119
+ _context23.next = 2;
1120
+ break;
1121
+ }
1122
+ throw new Error('数据库未连接');
1123
+ case 2:
1124
+ _context23.prev = 2;
1125
+ _context23.next = 5;
1126
+ return _this14.db.table(storeName).toArray();
1127
+ case 5:
1128
+ results = _context23.sent;
1129
+ return _context23.abrupt("return", results);
1130
+ case 9:
1131
+ _context23.prev = 9;
1132
+ _context23.t0 = _context23["catch"](2);
1133
+ throw new Error('获取所有数据失败');
1134
+ case 12:
1135
+ case "end":
1136
+ return _context23.stop();
1137
+ }
1138
+ }, _callee23, null, [[2, 9]]);
1139
+ }))(), "getAll(".concat(storeName, ")")));
1089
1140
  case 4:
1090
1141
  case "end":
1091
- return _context12.stop();
1142
+ return _context24.stop();
1092
1143
  }
1093
- }, _callee12, this);
1144
+ }, _callee24, this);
1094
1145
  }));
1095
1146
  function getAll(_x24) {
1096
1147
  return _getAll.apply(this, arguments);
@@ -1106,41 +1157,51 @@ var IndexDBManager = /*#__PURE__*/function () {
1106
1157
  }, {
1107
1158
  key: "clear",
1108
1159
  value: (function () {
1109
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(storeName) {
1160
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(storeName) {
1110
1161
  var _this15 = this;
1111
1162
  var memStore;
1112
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1113
- while (1) switch (_context13.prev = _context13.next) {
1163
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
1164
+ while (1) switch (_context26.prev = _context26.next) {
1114
1165
  case 0:
1115
1166
  if (this.useIndexDB) {
1116
- _context13.next = 4;
1167
+ _context26.next = 4;
1117
1168
  break;
1118
1169
  }
1119
1170
  // 使用内存存储
1120
1171
  memStore = this.getMemoryStore(storeName);
1121
1172
  memStore.clear();
1122
- return _context13.abrupt("return", true);
1173
+ return _context26.abrupt("return", true);
1123
1174
  case 4:
1124
- return _context13.abrupt("return", this.withTimeout(new Promise(function (resolve, reject) {
1125
- if (!_this15.db) {
1126
- reject(new Error('数据库未连接'));
1127
- return;
1128
- }
1129
- var transaction = _this15.db.transaction(storeName, 'readwrite');
1130
- var store = transaction.objectStore(storeName);
1131
- var request = store.clear();
1132
- request.onsuccess = function () {
1133
- return resolve(true);
1134
- };
1135
- request.onerror = function () {
1136
- return reject(new Error('清空数据失败'));
1137
- };
1138
- }), "clear(".concat(storeName, ")")));
1175
+ return _context26.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
1176
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1177
+ while (1) switch (_context25.prev = _context25.next) {
1178
+ case 0:
1179
+ if (_this15.db) {
1180
+ _context25.next = 2;
1181
+ break;
1182
+ }
1183
+ throw new Error('数据库未连接');
1184
+ case 2:
1185
+ _context25.prev = 2;
1186
+ _context25.next = 5;
1187
+ return _this15.db.table(storeName).clear();
1188
+ case 5:
1189
+ return _context25.abrupt("return", true);
1190
+ case 8:
1191
+ _context25.prev = 8;
1192
+ _context25.t0 = _context25["catch"](2);
1193
+ throw new Error('清空数据失败');
1194
+ case 11:
1195
+ case "end":
1196
+ return _context25.stop();
1197
+ }
1198
+ }, _callee25, null, [[2, 8]]);
1199
+ }))(), "clear(".concat(storeName, ")")));
1139
1200
  case 5:
1140
1201
  case "end":
1141
- return _context13.stop();
1202
+ return _context26.stop();
1142
1203
  }
1143
- }, _callee13, this);
1204
+ }, _callee26, this);
1144
1205
  }));
1145
1206
  function clear(_x25) {
1146
1207
  return _clear.apply(this, arguments);
@@ -1179,7 +1240,7 @@ var IndexDBManager = /*#__PURE__*/function () {
1179
1240
  * @private
1180
1241
  */
1181
1242
  function isSupported() {
1182
- return window && 'indexedDB' in window;
1243
+ return typeof window !== 'undefined' && 'indexedDB' in window;
1183
1244
  }
1184
1245
  }]);
1185
1246
  return IndexDBManager;