@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.
- package/es/app/app.d.ts +7 -7
- package/es/app/index.d.ts +1 -1
- package/es/applicationManager/application.d.ts +2 -2
- package/es/cmd/const.d.ts +5 -5
- package/es/hooks/useStore/index.d.ts +1 -1
- package/es/indexDB/index.d.ts +2 -2
- package/es/indexDB/index.js +633 -572
- package/es/locales/type.d.ts +3 -3
- package/es/logger/index.d.ts +1 -1
- package/es/models/index.d.ts +4 -4
- package/es/pubsub/index.d.ts +1 -1
- package/es/request/cache.d.ts +1 -1
- package/es/request/pisell2Request.d.ts +1 -1
- package/es/request/type.d.ts +1 -1
- package/es/routes/index.d.ts +2 -2
- package/es/socket/monitor.js +2 -0
- package/es/socket/types.d.ts +4 -3
- package/es/tasks/index.d.ts +0 -1
- package/es/tasks/index.js +0 -1
- package/es/tasks/type.d.ts +4 -4
- package/es/variables/index.d.ts +3 -3
- package/lib/app/app.d.ts +7 -7
- package/lib/app/app.js +21 -51
- package/lib/app/index.d.ts +1 -1
- package/lib/applicationManager/application.d.ts +2 -2
- package/lib/applicationManager/application.js +6 -12
- package/lib/applicationManager/index.js +4 -2
- package/lib/aws/index.js +0 -3
- package/lib/cmd/const.d.ts +5 -5
- package/lib/cmd/const.js +5 -5
- package/lib/cmd/index.js +0 -2
- package/lib/cookie/index.js +4 -2
- package/lib/data/index.js +0 -3
- package/lib/history/index.js +22 -24
- package/lib/hooks/useStore/index.d.ts +1 -1
- package/lib/indexDB/index.d.ts +2 -2
- package/lib/indexDB/index.js +233 -327
- package/lib/locales/index.js +94 -95
- package/lib/locales/type.d.ts +3 -3
- package/lib/logger/index.d.ts +1 -1
- package/lib/logger/index.js +8 -18
- package/lib/menuManager/index.js +12 -9
- package/lib/models/index.d.ts +4 -4
- package/lib/pubsub/index.d.ts +1 -1
- package/lib/pubsub/index.js +3 -1
- package/lib/request/cache.d.ts +1 -1
- package/lib/request/pisell2Request.d.ts +1 -1
- package/lib/request/type.d.ts +1 -1
- package/lib/routes/index.d.ts +2 -2
- package/lib/routes/index.js +1 -3
- package/lib/socket/components/SocketMonitorPage.js +12 -6
- package/lib/socket/heartbeat.js +5 -10
- package/lib/socket/index.js +3 -1
- package/lib/socket/monitor.js +26 -26
- package/lib/socket/reconnect.js +3 -10
- package/lib/socket/socket.js +10 -12
- package/lib/socket/types.d.ts +4 -3
- package/lib/storage/index.js +24 -25
- package/lib/tasks/index.d.ts +0 -1
- package/lib/tasks/index.js +329 -334
- package/lib/tasks/type.d.ts +4 -4
- package/lib/variables/index.d.ts +3 -3
- package/package.json +3 -2
package/es/indexDB/index.js
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
|
|
83
|
-
|
|
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
|
|
125
|
+
var _connect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
108
126
|
var _this3 = this;
|
|
109
|
-
return _regeneratorRuntime().wrap(function
|
|
110
|
-
while (1) switch (
|
|
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
|
-
|
|
131
|
+
_context2.next = 2;
|
|
114
132
|
break;
|
|
115
133
|
}
|
|
116
|
-
return
|
|
134
|
+
return _context2.abrupt("return", true);
|
|
117
135
|
case 2:
|
|
118
|
-
return
|
|
119
|
-
var
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
179
|
-
|
|
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
|
-
|
|
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
|
|
215
|
+
return _context2.stop();
|
|
188
216
|
}
|
|
189
|
-
},
|
|
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
|
|
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
|
-
|
|
258
|
+
_key,
|
|
231
259
|
memStore,
|
|
232
260
|
uuid,
|
|
233
|
-
|
|
234
|
-
return _regeneratorRuntime().wrap(function
|
|
235
|
-
while (1) switch (
|
|
261
|
+
_args4 = arguments;
|
|
262
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
263
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
236
264
|
case 0:
|
|
237
|
-
log =
|
|
265
|
+
log = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : false;
|
|
238
266
|
if (this.useIndexDB) {
|
|
239
|
-
|
|
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
|
-
|
|
275
|
+
_key = data[keyPath];
|
|
248
276
|
memStore = this.getMemoryStore(storeName);
|
|
249
|
-
memStore.set(
|
|
250
|
-
return
|
|
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
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
-
|
|
342
|
-
|
|
343
|
-
}), "add(".concat(storeName, ")")));
|
|
351
|
+
}, _callee3, null, [[3, 10]]);
|
|
352
|
+
}))(), "add(".concat(storeName, ")")));
|
|
344
353
|
case 11:
|
|
345
354
|
case "end":
|
|
346
|
-
return
|
|
355
|
+
return _context4.stop();
|
|
347
356
|
}
|
|
348
|
-
},
|
|
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
|
|
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
|
|
369
|
-
while (1) switch (
|
|
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
|
-
|
|
381
|
+
_context6.next = 3;
|
|
373
382
|
break;
|
|
374
383
|
}
|
|
375
384
|
// 使用内存存储
|
|
376
385
|
memStore = this.getMemoryStore(storeName);
|
|
377
|
-
return
|
|
386
|
+
return _context6.abrupt("return", memStore.has(key));
|
|
378
387
|
case 3:
|
|
379
|
-
return
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
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
|
|
417
|
+
return _context6.stop();
|
|
397
418
|
}
|
|
398
|
-
},
|
|
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
|
|
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
|
-
|
|
424
|
-
return _regeneratorRuntime().wrap(function
|
|
425
|
-
while (1) switch (
|
|
444
|
+
_args8 = arguments;
|
|
445
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
446
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
426
447
|
case 0:
|
|
427
|
-
log =
|
|
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
|
-
|
|
460
|
+
_context8.next = 6;
|
|
440
461
|
break;
|
|
441
462
|
}
|
|
442
463
|
// 使用内存存储
|
|
443
464
|
memStore = this.getMemoryStore(storeName);
|
|
444
|
-
return
|
|
465
|
+
return _context8.abrupt("return", (_memStore$get = memStore.get(key)) !== null && _memStore$get !== void 0 ? _memStore$get : null);
|
|
445
466
|
case 6:
|
|
446
|
-
return
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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
|
-
|
|
458
|
-
|
|
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
|
|
531
|
+
return _context8.stop();
|
|
536
532
|
}
|
|
537
|
-
},
|
|
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
|
|
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
|
-
|
|
557
|
+
_key2,
|
|
562
558
|
memStore,
|
|
563
559
|
uuid,
|
|
564
|
-
|
|
565
|
-
return _regeneratorRuntime().wrap(function
|
|
566
|
-
while (1) switch (
|
|
560
|
+
_args10 = arguments;
|
|
561
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
562
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
567
563
|
case 0:
|
|
568
|
-
log =
|
|
564
|
+
log = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : false;
|
|
569
565
|
if (this.useIndexDB) {
|
|
570
|
-
|
|
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
|
-
|
|
574
|
+
_key2 = data[keyPath];
|
|
579
575
|
memStore = this.getMemoryStore(storeName);
|
|
580
|
-
memStore.set(
|
|
581
|
-
return
|
|
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
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
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
|
-
|
|
606
|
-
|
|
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
|
|
653
|
+
return _context10.stop();
|
|
681
654
|
}
|
|
682
|
-
},
|
|
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
|
|
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
|
|
703
|
-
while (1) switch (
|
|
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
|
-
|
|
679
|
+
_context12.next = 3;
|
|
707
680
|
break;
|
|
708
681
|
}
|
|
709
682
|
// 使用内存存储
|
|
710
683
|
memStore = this.getMemoryStore(storeName);
|
|
711
|
-
return
|
|
684
|
+
return _context12.abrupt("return", memStore.delete(key));
|
|
712
685
|
case 3:
|
|
713
|
-
return
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
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
|
|
713
|
+
return _context12.stop();
|
|
731
714
|
}
|
|
732
|
-
},
|
|
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
|
|
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
|
|
755
|
-
while (1) switch (
|
|
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
|
-
|
|
741
|
+
_context14.next = 9;
|
|
759
742
|
break;
|
|
760
743
|
}
|
|
761
|
-
|
|
744
|
+
_context14.next = 3;
|
|
762
745
|
return this.getAll(storeName);
|
|
763
746
|
case 3:
|
|
764
|
-
allData =
|
|
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
|
-
|
|
755
|
+
_context14.next = 8;
|
|
773
756
|
break;
|
|
774
757
|
}
|
|
775
|
-
return
|
|
758
|
+
return _context14.abrupt("return", null);
|
|
776
759
|
case 8:
|
|
777
|
-
return
|
|
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
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
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
|
|
793
|
+
return _context14.stop();
|
|
800
794
|
}
|
|
801
|
-
},
|
|
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
|
|
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
|
|
823
|
-
while (1) switch (
|
|
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
|
-
|
|
820
|
+
_context16.next = 9;
|
|
827
821
|
break;
|
|
828
822
|
}
|
|
829
|
-
|
|
823
|
+
_context16.next = 3;
|
|
830
824
|
return this.getAll(storeName);
|
|
831
825
|
case 3:
|
|
832
|
-
allData =
|
|
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
|
-
|
|
834
|
+
_context16.next = 8;
|
|
841
835
|
break;
|
|
842
836
|
}
|
|
843
|
-
return
|
|
837
|
+
return _context16.abrupt("return", false);
|
|
844
838
|
case 8:
|
|
845
|
-
return
|
|
839
|
+
return _context16.abrupt("return", allData.some(function (item) {
|
|
846
840
|
return item[index.keyPath] === indexValue;
|
|
847
841
|
}));
|
|
848
842
|
case 9:
|
|
849
|
-
return
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
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
|
|
872
|
+
return _context16.stop();
|
|
868
873
|
}
|
|
869
|
-
},
|
|
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
|
|
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
|
|
892
|
-
while (1) switch (
|
|
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
|
-
|
|
900
|
+
_context18.next = 9;
|
|
896
901
|
break;
|
|
897
902
|
}
|
|
898
|
-
|
|
903
|
+
_context18.next = 3;
|
|
899
904
|
return this.getAll(storeName);
|
|
900
905
|
case 3:
|
|
901
|
-
allData =
|
|
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
|
-
|
|
914
|
+
_context18.next = 8;
|
|
910
915
|
break;
|
|
911
916
|
}
|
|
912
|
-
return
|
|
917
|
+
return _context18.abrupt("return", []);
|
|
913
918
|
case 8:
|
|
914
|
-
return
|
|
919
|
+
return _context18.abrupt("return", allData.filter(function (item) {
|
|
915
920
|
return item[index.keyPath] === indexValue;
|
|
916
921
|
}));
|
|
917
922
|
case 9:
|
|
918
|
-
return
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
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
|
|
952
|
+
return _context18.stop();
|
|
937
953
|
}
|
|
938
|
-
},
|
|
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
|
|
970
|
+
var _count = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(storeName) {
|
|
955
971
|
var _this12 = this;
|
|
956
972
|
var allData;
|
|
957
|
-
return _regeneratorRuntime().wrap(function
|
|
958
|
-
while (1) switch (
|
|
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
|
-
|
|
977
|
+
_context20.next = 5;
|
|
962
978
|
break;
|
|
963
979
|
}
|
|
964
|
-
|
|
980
|
+
_context20.next = 3;
|
|
965
981
|
return this.getAll(storeName);
|
|
966
982
|
case 3:
|
|
967
|
-
allData =
|
|
968
|
-
return
|
|
983
|
+
allData = _context20.sent;
|
|
984
|
+
return _context20.abrupt("return", allData.length);
|
|
969
985
|
case 5:
|
|
970
|
-
return
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
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
|
|
1015
|
+
return _context20.stop();
|
|
988
1016
|
}
|
|
989
|
-
},
|
|
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
|
|
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
|
|
1011
|
-
while (1) switch (
|
|
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
|
-
|
|
1042
|
+
_context22.next = 5;
|
|
1015
1043
|
break;
|
|
1016
1044
|
}
|
|
1017
|
-
|
|
1045
|
+
_context22.next = 3;
|
|
1018
1046
|
return this.getAllByIndex(storeName, indexName, indexValue);
|
|
1019
1047
|
case 3:
|
|
1020
|
-
matchingData =
|
|
1021
|
-
return
|
|
1048
|
+
matchingData = _context22.sent;
|
|
1049
|
+
return _context22.abrupt("return", matchingData.length);
|
|
1022
1050
|
case 5:
|
|
1023
|
-
return
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
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
|
|
1080
|
+
return _context22.stop();
|
|
1042
1081
|
}
|
|
1043
|
-
},
|
|
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
|
|
1099
|
+
var _getAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(storeName) {
|
|
1061
1100
|
var _this14 = this;
|
|
1062
1101
|
var memStore;
|
|
1063
|
-
return _regeneratorRuntime().wrap(function
|
|
1064
|
-
while (1) switch (
|
|
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
|
-
|
|
1106
|
+
_context24.next = 3;
|
|
1068
1107
|
break;
|
|
1069
1108
|
}
|
|
1070
1109
|
// 使用内存存储
|
|
1071
1110
|
memStore = this.getMemoryStore(storeName);
|
|
1072
|
-
return
|
|
1111
|
+
return _context24.abrupt("return", Array.from(memStore.values()));
|
|
1073
1112
|
case 3:
|
|
1074
|
-
return
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
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
|
|
1142
|
+
return _context24.stop();
|
|
1092
1143
|
}
|
|
1093
|
-
},
|
|
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
|
|
1160
|
+
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(storeName) {
|
|
1110
1161
|
var _this15 = this;
|
|
1111
1162
|
var memStore;
|
|
1112
|
-
return _regeneratorRuntime().wrap(function
|
|
1113
|
-
while (1) switch (
|
|
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
|
-
|
|
1167
|
+
_context26.next = 4;
|
|
1117
1168
|
break;
|
|
1118
1169
|
}
|
|
1119
1170
|
// 使用内存存储
|
|
1120
1171
|
memStore = this.getMemoryStore(storeName);
|
|
1121
1172
|
memStore.clear();
|
|
1122
|
-
return
|
|
1173
|
+
return _context26.abrupt("return", true);
|
|
1123
1174
|
case 4:
|
|
1124
|
-
return
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
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
|
|
1202
|
+
return _context26.stop();
|
|
1142
1203
|
}
|
|
1143
|
-
},
|
|
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;
|