@pisell/core 1.1.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/indexDB/index.d.ts +2 -2
- package/es/indexDB/index.js +620 -569
- package/es/routes/index.d.ts +1 -1
- package/es/socket/monitor.js +2 -0
- package/es/socket/types.d.ts +3 -2
- package/lib/applicationManager/index.js +3 -1
- package/lib/indexDB/index.d.ts +2 -2
- package/lib/indexDB/index.js +184 -289
- package/lib/routes/index.d.ts +1 -1
- package/lib/socket/monitor.js +2 -0
- package/lib/socket/types.d.ts +3 -2
- package/package.json +9 -8
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 () {
|
|
@@ -114,89 +122,99 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
114
122
|
}, {
|
|
115
123
|
key: "connect",
|
|
116
124
|
value: (function () {
|
|
117
|
-
var _connect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
125
|
+
var _connect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
118
126
|
var _this3 = this;
|
|
119
|
-
return _regeneratorRuntime().wrap(function
|
|
120
|
-
while (1) switch (
|
|
127
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
128
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
121
129
|
case 0:
|
|
122
130
|
if (this.useIndexDB) {
|
|
123
|
-
|
|
131
|
+
_context2.next = 2;
|
|
124
132
|
break;
|
|
125
133
|
}
|
|
126
|
-
return
|
|
134
|
+
return _context2.abrupt("return", true);
|
|
127
135
|
case 2:
|
|
128
|
-
return
|
|
129
|
-
var
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
db.onerror = function (event) {
|
|
159
|
-
var _event$target2;
|
|
160
|
-
_this3.app.logger.addLog({
|
|
161
|
-
type: 'error',
|
|
162
|
-
title: '[ IndexDB ] ERROR',
|
|
163
|
-
metadata: {
|
|
164
|
-
msg: 'DB error',
|
|
165
|
-
data: event,
|
|
166
|
-
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
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
};
|
|
170
|
-
db.onclose = function (event) {
|
|
171
|
-
var _event$target3;
|
|
172
|
-
_this3.app.logger.addLog({
|
|
173
|
-
type: 'error',
|
|
174
|
-
title: '[ IndexDB ] CLOSE',
|
|
175
|
-
metadata: {
|
|
176
|
-
msg: 'DB close',
|
|
177
|
-
data: event,
|
|
178
|
-
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
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
};
|
|
182
|
-
_this3.stores.forEach(function (store) {
|
|
183
|
-
if (!db.objectStoreNames.contains(store.name)) {
|
|
184
|
-
var _store$indexes;
|
|
185
|
-
var objectStore = db.createObjectStore(store.name, {
|
|
186
|
-
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(',');
|
|
187
166
|
});
|
|
188
|
-
|
|
189
|
-
|
|
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
|
+
});
|
|
190
184
|
});
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
+
}
|
|
205
|
+
});
|
|
206
|
+
throw _context.t0;
|
|
207
|
+
case 16:
|
|
208
|
+
case "end":
|
|
209
|
+
return _context.stop();
|
|
210
|
+
}
|
|
211
|
+
}, _callee, null, [[0, 12]]);
|
|
212
|
+
}))(), 'connect'));
|
|
195
213
|
case 3:
|
|
196
214
|
case "end":
|
|
197
|
-
return
|
|
215
|
+
return _context2.stop();
|
|
198
216
|
}
|
|
199
|
-
},
|
|
217
|
+
}, _callee2, this);
|
|
200
218
|
}));
|
|
201
219
|
function connect() {
|
|
202
220
|
return _connect.apply(this, arguments);
|
|
@@ -232,21 +250,21 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
232
250
|
}, {
|
|
233
251
|
key: "add",
|
|
234
252
|
value: (function () {
|
|
235
|
-
var _add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
253
|
+
var _add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(storeName, data) {
|
|
236
254
|
var _this4 = this;
|
|
237
255
|
var log,
|
|
238
256
|
storeConfig,
|
|
239
257
|
keyPath,
|
|
240
|
-
|
|
258
|
+
_key,
|
|
241
259
|
memStore,
|
|
242
260
|
uuid,
|
|
243
|
-
|
|
244
|
-
return _regeneratorRuntime().wrap(function
|
|
245
|
-
while (1) switch (
|
|
261
|
+
_args4 = arguments;
|
|
262
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
263
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
246
264
|
case 0:
|
|
247
|
-
log =
|
|
265
|
+
log = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : false;
|
|
248
266
|
if (this.useIndexDB) {
|
|
249
|
-
|
|
267
|
+
_context4.next = 8;
|
|
250
268
|
break;
|
|
251
269
|
}
|
|
252
270
|
// 使用内存存储
|
|
@@ -254,10 +272,10 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
254
272
|
return s.name === storeName;
|
|
255
273
|
});
|
|
256
274
|
keyPath = (storeConfig === null || storeConfig === void 0 ? void 0 : storeConfig.keyPath) || 'id';
|
|
257
|
-
|
|
275
|
+
_key = data[keyPath];
|
|
258
276
|
memStore = this.getMemoryStore(storeName);
|
|
259
|
-
memStore.set(
|
|
260
|
-
return
|
|
277
|
+
memStore.set(_key, data);
|
|
278
|
+
return _context4.abrupt("return", data);
|
|
261
279
|
case 8:
|
|
262
280
|
uuid = "[ IndexDB ] ADD: - ".concat(storeName, " - ").concat(dayjs().valueOf());
|
|
263
281
|
if (log) {
|
|
@@ -270,92 +288,73 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
270
288
|
}
|
|
271
289
|
});
|
|
272
290
|
}
|
|
273
|
-
return
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
msg: '添加数据前 数据库未连接',
|
|
281
|
-
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;
|
|
282
298
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
if (log) {
|
|
293
|
-
_this4.app.logger.addLog({
|
|
294
|
-
type: 'info',
|
|
295
|
-
title: uuid,
|
|
296
|
-
metadata: {
|
|
297
|
-
msg: '添加数据成功'
|
|
299
|
+
if (log) {
|
|
300
|
+
_this4.app.logger.addLog({
|
|
301
|
+
type: 'error',
|
|
302
|
+
title: uuid,
|
|
303
|
+
metadata: {
|
|
304
|
+
msg: '添加数据前 数据库未连接',
|
|
305
|
+
data: data
|
|
306
|
+
}
|
|
307
|
+
});
|
|
298
308
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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
|
+
});
|
|
310
331
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
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
|
+
});
|
|
323
345
|
}
|
|
324
|
-
|
|
346
|
+
throw new Error('添加数据失败');
|
|
347
|
+
case 14:
|
|
348
|
+
case "end":
|
|
349
|
+
return _context3.stop();
|
|
325
350
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
transaction.onerror = function (e) {
|
|
329
|
-
var _transaction$error;
|
|
330
|
-
if (log) {
|
|
331
|
-
_this4.app.logger.addLog({
|
|
332
|
-
type: 'error',
|
|
333
|
-
title: uuid,
|
|
334
|
-
metadata: {
|
|
335
|
-
msg: '事务错误'
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
return reject((_transaction$error = transaction.error) !== null && _transaction$error !== void 0 ? _transaction$error : new Error('事务错误'));
|
|
340
|
-
};
|
|
341
|
-
transaction.onabort = function (e) {
|
|
342
|
-
if (log) {
|
|
343
|
-
_this4.app.logger.addLog({
|
|
344
|
-
type: 'error',
|
|
345
|
-
title: uuid,
|
|
346
|
-
metadata: {
|
|
347
|
-
msg: '事务被中止'
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
return reject(new Error('事务被中止'));
|
|
352
|
-
};
|
|
353
|
-
}), "add(".concat(storeName, ")")));
|
|
351
|
+
}, _callee3, null, [[3, 10]]);
|
|
352
|
+
}))(), "add(".concat(storeName, ")")));
|
|
354
353
|
case 11:
|
|
355
354
|
case "end":
|
|
356
|
-
return
|
|
355
|
+
return _context4.stop();
|
|
357
356
|
}
|
|
358
|
-
},
|
|
357
|
+
}, _callee4, this);
|
|
359
358
|
}));
|
|
360
359
|
function add(_x, _x2) {
|
|
361
360
|
return _add.apply(this, arguments);
|
|
@@ -372,40 +371,52 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
372
371
|
}, {
|
|
373
372
|
key: "exists",
|
|
374
373
|
value: (function () {
|
|
375
|
-
var _exists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
374
|
+
var _exists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(storeName, key) {
|
|
376
375
|
var _this5 = this;
|
|
377
376
|
var memStore;
|
|
378
|
-
return _regeneratorRuntime().wrap(function
|
|
379
|
-
while (1) switch (
|
|
377
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
378
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
380
379
|
case 0:
|
|
381
380
|
if (this.useIndexDB) {
|
|
382
|
-
|
|
381
|
+
_context6.next = 3;
|
|
383
382
|
break;
|
|
384
383
|
}
|
|
385
384
|
// 使用内存存储
|
|
386
385
|
memStore = this.getMemoryStore(storeName);
|
|
387
|
-
return
|
|
386
|
+
return _context6.abrupt("return", memStore.has(key));
|
|
388
387
|
case 3:
|
|
389
|
-
return
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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, ")")));
|
|
404
415
|
case 4:
|
|
405
416
|
case "end":
|
|
406
|
-
return
|
|
417
|
+
return _context6.stop();
|
|
407
418
|
}
|
|
408
|
-
},
|
|
419
|
+
}, _callee6, this);
|
|
409
420
|
}));
|
|
410
421
|
function exists(_x3, _x4) {
|
|
411
422
|
return _exists.apply(this, arguments);
|
|
@@ -424,17 +435,17 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
424
435
|
}, {
|
|
425
436
|
key: "get",
|
|
426
437
|
value: (function () {
|
|
427
|
-
var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
438
|
+
var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(storeName, key) {
|
|
428
439
|
var _this6 = this;
|
|
429
440
|
var log,
|
|
430
441
|
uuid,
|
|
431
442
|
_memStore$get,
|
|
432
443
|
memStore,
|
|
433
|
-
|
|
434
|
-
return _regeneratorRuntime().wrap(function
|
|
435
|
-
while (1) switch (
|
|
444
|
+
_args8 = arguments;
|
|
445
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
446
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
436
447
|
case 0:
|
|
437
|
-
log =
|
|
448
|
+
log = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : false;
|
|
438
449
|
uuid = "[ IndexDB ] GET: - ".concat(storeName, " - ").concat(key, " - ").concat(dayjs().valueOf());
|
|
439
450
|
if (log) {
|
|
440
451
|
this.app.logger.addLog({
|
|
@@ -446,105 +457,80 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
446
457
|
});
|
|
447
458
|
}
|
|
448
459
|
if (this.useIndexDB) {
|
|
449
|
-
|
|
460
|
+
_context8.next = 6;
|
|
450
461
|
break;
|
|
451
462
|
}
|
|
452
463
|
// 使用内存存储
|
|
453
464
|
memStore = this.getMemoryStore(storeName);
|
|
454
|
-
return
|
|
465
|
+
return _context8.abrupt("return", (_memStore$get = memStore.get(key)) !== null && _memStore$get !== void 0 ? _memStore$get : null);
|
|
455
466
|
case 6:
|
|
456
|
-
return
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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;
|
|
464
475
|
}
|
|
465
|
-
|
|
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
|
+
});
|
|
521
|
+
}
|
|
522
|
+
throw new Error('获取数据失败');
|
|
523
|
+
case 15:
|
|
524
|
+
case "end":
|
|
525
|
+
return _context7.stop();
|
|
466
526
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
var resolved = false;
|
|
471
|
-
try {
|
|
472
|
-
var transaction = _this6.db.transaction(storeName, 'readonly');
|
|
473
|
-
var store = transaction.objectStore(storeName);
|
|
474
|
-
var request = store.get(key);
|
|
475
|
-
request.onsuccess = function () {
|
|
476
|
-
var _request$result;
|
|
477
|
-
resolved = true;
|
|
478
|
-
if (log) {
|
|
479
|
-
_this6.app.logger.addLog({
|
|
480
|
-
type: 'info',
|
|
481
|
-
title: uuid,
|
|
482
|
-
metadata: {
|
|
483
|
-
msg: '获取成功'
|
|
484
|
-
}
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
resolve((_request$result = request.result) !== null && _request$result !== void 0 ? _request$result : null);
|
|
488
|
-
};
|
|
489
|
-
request.onerror = function () {
|
|
490
|
-
var _request$error;
|
|
491
|
-
resolved = true;
|
|
492
|
-
if (log) {
|
|
493
|
-
_this6.app.logger.addLog({
|
|
494
|
-
type: 'error',
|
|
495
|
-
title: uuid,
|
|
496
|
-
metadata: {
|
|
497
|
-
msg: '获取失败'
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
reject((_request$error = request.error) !== null && _request$error !== void 0 ? _request$error : new Error('获取数据失败'));
|
|
502
|
-
};
|
|
503
|
-
transaction.onabort = function () {
|
|
504
|
-
if (log) {
|
|
505
|
-
_this6.app.logger.addLog({
|
|
506
|
-
type: 'info',
|
|
507
|
-
title: uuid,
|
|
508
|
-
metadata: {
|
|
509
|
-
msg: '事务被中止'
|
|
510
|
-
}
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
if (!resolved) reject(new Error('事务被中止'));
|
|
514
|
-
};
|
|
515
|
-
transaction.onerror = function (event) {
|
|
516
|
-
if (log) {
|
|
517
|
-
_this6.app.logger.addLog({
|
|
518
|
-
type: 'error',
|
|
519
|
-
title: uuid,
|
|
520
|
-
metadata: {
|
|
521
|
-
msg: "\u4E8B\u52A1\u9519\u8BEF: ".concat(event.target.error)
|
|
522
|
-
}
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
if (!resolved) reject(new Error("\u4E8B\u52A1\u9519\u8BEF: ".concat(event.target.error)));
|
|
526
|
-
};
|
|
527
|
-
transaction.oncomplete = function () {
|
|
528
|
-
if (log) {
|
|
529
|
-
_this6.app.logger.addLog({
|
|
530
|
-
type: 'info',
|
|
531
|
-
title: uuid,
|
|
532
|
-
metadata: {
|
|
533
|
-
msg: '事务完成'
|
|
534
|
-
}
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
// ✅ 事务顺利结束
|
|
538
|
-
};
|
|
539
|
-
} catch (e) {
|
|
540
|
-
reject(e);
|
|
541
|
-
}
|
|
542
|
-
}), "get(".concat(storeName, ")")));
|
|
527
|
+
}, _callee7, null, [[3, 11]]);
|
|
528
|
+
}))(), "get(".concat(storeName, ")")));
|
|
543
529
|
case 7:
|
|
544
530
|
case "end":
|
|
545
|
-
return
|
|
531
|
+
return _context8.stop();
|
|
546
532
|
}
|
|
547
|
-
},
|
|
533
|
+
}, _callee8, this);
|
|
548
534
|
}));
|
|
549
535
|
function get(_x5, _x6) {
|
|
550
536
|
return _get.apply(this, arguments);
|
|
@@ -563,21 +549,21 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
563
549
|
}, {
|
|
564
550
|
key: "update",
|
|
565
551
|
value: (function () {
|
|
566
|
-
var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
552
|
+
var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(storeName, data) {
|
|
567
553
|
var _this7 = this;
|
|
568
554
|
var log,
|
|
569
555
|
storeConfig,
|
|
570
556
|
keyPath,
|
|
571
|
-
|
|
557
|
+
_key2,
|
|
572
558
|
memStore,
|
|
573
559
|
uuid,
|
|
574
|
-
|
|
575
|
-
return _regeneratorRuntime().wrap(function
|
|
576
|
-
while (1) switch (
|
|
560
|
+
_args10 = arguments;
|
|
561
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
562
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
577
563
|
case 0:
|
|
578
|
-
log =
|
|
564
|
+
log = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : false;
|
|
579
565
|
if (this.useIndexDB) {
|
|
580
|
-
|
|
566
|
+
_context10.next = 8;
|
|
581
567
|
break;
|
|
582
568
|
}
|
|
583
569
|
// 使用内存存储
|
|
@@ -585,10 +571,10 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
585
571
|
return s.name === storeName;
|
|
586
572
|
});
|
|
587
573
|
keyPath = (storeConfig === null || storeConfig === void 0 ? void 0 : storeConfig.keyPath) || 'id';
|
|
588
|
-
|
|
574
|
+
_key2 = data[keyPath];
|
|
589
575
|
memStore = this.getMemoryStore(storeName);
|
|
590
|
-
memStore.set(
|
|
591
|
-
return
|
|
576
|
+
memStore.set(_key2, data);
|
|
577
|
+
return _context10.abrupt("return", data);
|
|
592
578
|
case 8:
|
|
593
579
|
uuid = "[ IndexDB ] UPDATE: - ".concat(storeName, " - ").concat(dayjs().valueOf());
|
|
594
580
|
if (log) {
|
|
@@ -601,95 +587,72 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
601
587
|
}
|
|
602
588
|
});
|
|
603
589
|
}
|
|
604
|
-
return
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
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;
|
|
612
597
|
}
|
|
613
|
-
|
|
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
|
+
});
|
|
643
|
+
}
|
|
644
|
+
throw new Error('更新数据失败');
|
|
645
|
+
case 14:
|
|
646
|
+
case "end":
|
|
647
|
+
return _context9.stop();
|
|
614
648
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
}
|
|
618
|
-
try {
|
|
619
|
-
var transaction = _this7.db.transaction(storeName, 'readwrite');
|
|
620
|
-
var store = transaction.objectStore(storeName);
|
|
621
|
-
var request = store.put(data);
|
|
622
|
-
request.onsuccess = function () {
|
|
623
|
-
if (log) {
|
|
624
|
-
_this7.app.logger.addLog({
|
|
625
|
-
type: 'info',
|
|
626
|
-
title: uuid,
|
|
627
|
-
metadata: {
|
|
628
|
-
msg: '数据更新完成'
|
|
629
|
-
}
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
return resolve(data);
|
|
633
|
-
};
|
|
634
|
-
request.onerror = function () {
|
|
635
|
-
var _request$error2;
|
|
636
|
-
if (log) {
|
|
637
|
-
_this7.app.logger.addLog({
|
|
638
|
-
type: 'error',
|
|
639
|
-
title: uuid,
|
|
640
|
-
metadata: {
|
|
641
|
-
msg: '数据更新失败'
|
|
642
|
-
}
|
|
643
|
-
});
|
|
644
|
-
}
|
|
645
|
-
return reject((_request$error2 = request.error) !== null && _request$error2 !== void 0 ? _request$error2 : new Error('更新数据失败'));
|
|
646
|
-
};
|
|
647
|
-
transaction.oncomplete = function () {
|
|
648
|
-
if (log) {
|
|
649
|
-
_this7.app.logger.addLog({
|
|
650
|
-
type: 'info',
|
|
651
|
-
title: uuid,
|
|
652
|
-
metadata: {
|
|
653
|
-
msg: '事务完成'
|
|
654
|
-
}
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
return console.log('✅ 事务完成');
|
|
658
|
-
};
|
|
659
|
-
transaction.onabort = function (e) {
|
|
660
|
-
if (log) {
|
|
661
|
-
_this7.app.logger.addLog({
|
|
662
|
-
type: 'error',
|
|
663
|
-
title: uuid,
|
|
664
|
-
metadata: {
|
|
665
|
-
msg: '事务被中止'
|
|
666
|
-
}
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
return reject(new Error('事务被中止'));
|
|
670
|
-
};
|
|
671
|
-
transaction.onerror = function (e) {
|
|
672
|
-
var _transaction$error2;
|
|
673
|
-
if (log) {
|
|
674
|
-
_this7.app.logger.addLog({
|
|
675
|
-
type: 'error',
|
|
676
|
-
title: uuid,
|
|
677
|
-
metadata: {
|
|
678
|
-
msg: '事务错误'
|
|
679
|
-
}
|
|
680
|
-
});
|
|
681
|
-
}
|
|
682
|
-
return reject((_transaction$error2 = transaction.error) !== null && _transaction$error2 !== void 0 ? _transaction$error2 : new Error('事务错误'));
|
|
683
|
-
};
|
|
684
|
-
} catch (e) {
|
|
685
|
-
reject(e);
|
|
686
|
-
}
|
|
687
|
-
}), "update(".concat(storeName, ")")));
|
|
649
|
+
}, _callee9, null, [[3, 10]]);
|
|
650
|
+
}))(), "update(".concat(storeName, ")")));
|
|
688
651
|
case 11:
|
|
689
652
|
case "end":
|
|
690
|
-
return
|
|
653
|
+
return _context10.stop();
|
|
691
654
|
}
|
|
692
|
-
},
|
|
655
|
+
}, _callee10, this);
|
|
693
656
|
}));
|
|
694
657
|
function update(_x7, _x8) {
|
|
695
658
|
return _update.apply(this, arguments);
|
|
@@ -706,40 +669,50 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
706
669
|
}, {
|
|
707
670
|
key: "delete",
|
|
708
671
|
value: (function () {
|
|
709
|
-
var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
672
|
+
var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(storeName, key) {
|
|
710
673
|
var _this8 = this;
|
|
711
674
|
var memStore;
|
|
712
|
-
return _regeneratorRuntime().wrap(function
|
|
713
|
-
while (1) switch (
|
|
675
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
676
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
714
677
|
case 0:
|
|
715
678
|
if (this.useIndexDB) {
|
|
716
|
-
|
|
679
|
+
_context12.next = 3;
|
|
717
680
|
break;
|
|
718
681
|
}
|
|
719
682
|
// 使用内存存储
|
|
720
683
|
memStore = this.getMemoryStore(storeName);
|
|
721
|
-
return
|
|
684
|
+
return _context12.abrupt("return", memStore.delete(key));
|
|
722
685
|
case 3:
|
|
723
|
-
return
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
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, ")")));
|
|
738
711
|
case 4:
|
|
739
712
|
case "end":
|
|
740
|
-
return
|
|
713
|
+
return _context12.stop();
|
|
741
714
|
}
|
|
742
|
-
},
|
|
715
|
+
}, _callee12, this);
|
|
743
716
|
}));
|
|
744
717
|
function _delete(_x9, _x10) {
|
|
745
718
|
return _delete2.apply(this, arguments);
|
|
@@ -758,20 +731,20 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
758
731
|
}, {
|
|
759
732
|
key: "getByIndex",
|
|
760
733
|
value: (function () {
|
|
761
|
-
var _getByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
734
|
+
var _getByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(storeName, indexName, indexValue) {
|
|
762
735
|
var _this9 = this;
|
|
763
736
|
var _storeConfig$indexes, allData, storeConfig, index;
|
|
764
|
-
return _regeneratorRuntime().wrap(function
|
|
765
|
-
while (1) switch (
|
|
737
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
738
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
766
739
|
case 0:
|
|
767
740
|
if (this.useIndexDB) {
|
|
768
|
-
|
|
741
|
+
_context14.next = 9;
|
|
769
742
|
break;
|
|
770
743
|
}
|
|
771
|
-
|
|
744
|
+
_context14.next = 3;
|
|
772
745
|
return this.getAll(storeName);
|
|
773
746
|
case 3:
|
|
774
|
-
allData =
|
|
747
|
+
allData = _context14.sent;
|
|
775
748
|
storeConfig = this.stores.find(function (s) {
|
|
776
749
|
return s.name === storeName;
|
|
777
750
|
});
|
|
@@ -779,36 +752,47 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
779
752
|
return i.name === indexName;
|
|
780
753
|
});
|
|
781
754
|
if (index) {
|
|
782
|
-
|
|
755
|
+
_context14.next = 8;
|
|
783
756
|
break;
|
|
784
757
|
}
|
|
785
|
-
return
|
|
758
|
+
return _context14.abrupt("return", null);
|
|
786
759
|
case 8:
|
|
787
|
-
return
|
|
760
|
+
return _context14.abrupt("return", allData.find(function (item) {
|
|
788
761
|
return item[index.keyPath] === indexValue;
|
|
789
762
|
}) || null);
|
|
790
763
|
case 9:
|
|
791
|
-
return
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
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, ")")));
|
|
807
791
|
case 10:
|
|
808
792
|
case "end":
|
|
809
|
-
return
|
|
793
|
+
return _context14.stop();
|
|
810
794
|
}
|
|
811
|
-
},
|
|
795
|
+
}, _callee14, this);
|
|
812
796
|
}));
|
|
813
797
|
function getByIndex(_x11, _x12, _x13) {
|
|
814
798
|
return _getByIndex.apply(this, arguments);
|
|
@@ -826,20 +810,20 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
826
810
|
}, {
|
|
827
811
|
key: "existsByIndex",
|
|
828
812
|
value: (function () {
|
|
829
|
-
var _existsByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
813
|
+
var _existsByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(storeName, indexName, indexValue) {
|
|
830
814
|
var _this10 = this;
|
|
831
815
|
var _storeConfig$indexes2, allData, storeConfig, index;
|
|
832
|
-
return _regeneratorRuntime().wrap(function
|
|
833
|
-
while (1) switch (
|
|
816
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
817
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
834
818
|
case 0:
|
|
835
819
|
if (this.useIndexDB) {
|
|
836
|
-
|
|
820
|
+
_context16.next = 9;
|
|
837
821
|
break;
|
|
838
822
|
}
|
|
839
|
-
|
|
823
|
+
_context16.next = 3;
|
|
840
824
|
return this.getAll(storeName);
|
|
841
825
|
case 3:
|
|
842
|
-
allData =
|
|
826
|
+
allData = _context16.sent;
|
|
843
827
|
storeConfig = this.stores.find(function (s) {
|
|
844
828
|
return s.name === storeName;
|
|
845
829
|
});
|
|
@@ -847,36 +831,47 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
847
831
|
return i.name === indexName;
|
|
848
832
|
});
|
|
849
833
|
if (index) {
|
|
850
|
-
|
|
834
|
+
_context16.next = 8;
|
|
851
835
|
break;
|
|
852
836
|
}
|
|
853
|
-
return
|
|
837
|
+
return _context16.abrupt("return", false);
|
|
854
838
|
case 8:
|
|
855
|
-
return
|
|
839
|
+
return _context16.abrupt("return", allData.some(function (item) {
|
|
856
840
|
return item[index.keyPath] === indexValue;
|
|
857
841
|
}));
|
|
858
842
|
case 9:
|
|
859
|
-
return
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
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, ")")));
|
|
875
870
|
case 10:
|
|
876
871
|
case "end":
|
|
877
|
-
return
|
|
872
|
+
return _context16.stop();
|
|
878
873
|
}
|
|
879
|
-
},
|
|
874
|
+
}, _callee16, this);
|
|
880
875
|
}));
|
|
881
876
|
function existsByIndex(_x14, _x15, _x16) {
|
|
882
877
|
return _existsByIndex.apply(this, arguments);
|
|
@@ -895,20 +890,20 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
895
890
|
}, {
|
|
896
891
|
key: "getAllByIndex",
|
|
897
892
|
value: (function () {
|
|
898
|
-
var _getAllByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
893
|
+
var _getAllByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(storeName, indexName, indexValue) {
|
|
899
894
|
var _this11 = this;
|
|
900
895
|
var _storeConfig$indexes3, allData, storeConfig, index;
|
|
901
|
-
return _regeneratorRuntime().wrap(function
|
|
902
|
-
while (1) switch (
|
|
896
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
897
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
903
898
|
case 0:
|
|
904
899
|
if (this.useIndexDB) {
|
|
905
|
-
|
|
900
|
+
_context18.next = 9;
|
|
906
901
|
break;
|
|
907
902
|
}
|
|
908
|
-
|
|
903
|
+
_context18.next = 3;
|
|
909
904
|
return this.getAll(storeName);
|
|
910
905
|
case 3:
|
|
911
|
-
allData =
|
|
906
|
+
allData = _context18.sent;
|
|
912
907
|
storeConfig = this.stores.find(function (s) {
|
|
913
908
|
return s.name === storeName;
|
|
914
909
|
});
|
|
@@ -916,36 +911,47 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
916
911
|
return i.name === indexName;
|
|
917
912
|
});
|
|
918
913
|
if (index) {
|
|
919
|
-
|
|
914
|
+
_context18.next = 8;
|
|
920
915
|
break;
|
|
921
916
|
}
|
|
922
|
-
return
|
|
917
|
+
return _context18.abrupt("return", []);
|
|
923
918
|
case 8:
|
|
924
|
-
return
|
|
919
|
+
return _context18.abrupt("return", allData.filter(function (item) {
|
|
925
920
|
return item[index.keyPath] === indexValue;
|
|
926
921
|
}));
|
|
927
922
|
case 9:
|
|
928
|
-
return
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
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, ")")));
|
|
944
950
|
case 10:
|
|
945
951
|
case "end":
|
|
946
|
-
return
|
|
952
|
+
return _context18.stop();
|
|
947
953
|
}
|
|
948
|
-
},
|
|
954
|
+
}, _callee18, this);
|
|
949
955
|
}));
|
|
950
956
|
function getAllByIndex(_x17, _x18, _x19) {
|
|
951
957
|
return _getAllByIndex.apply(this, arguments);
|
|
@@ -961,42 +967,54 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
961
967
|
}, {
|
|
962
968
|
key: "count",
|
|
963
969
|
value: (function () {
|
|
964
|
-
var _count = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
970
|
+
var _count = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(storeName) {
|
|
965
971
|
var _this12 = this;
|
|
966
972
|
var allData;
|
|
967
|
-
return _regeneratorRuntime().wrap(function
|
|
968
|
-
while (1) switch (
|
|
973
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
974
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
969
975
|
case 0:
|
|
970
976
|
if (this.useIndexDB) {
|
|
971
|
-
|
|
977
|
+
_context20.next = 5;
|
|
972
978
|
break;
|
|
973
979
|
}
|
|
974
|
-
|
|
980
|
+
_context20.next = 3;
|
|
975
981
|
return this.getAll(storeName);
|
|
976
982
|
case 3:
|
|
977
|
-
allData =
|
|
978
|
-
return
|
|
983
|
+
allData = _context20.sent;
|
|
984
|
+
return _context20.abrupt("return", allData.length);
|
|
979
985
|
case 5:
|
|
980
|
-
return
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
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, ")")));
|
|
995
1013
|
case 6:
|
|
996
1014
|
case "end":
|
|
997
|
-
return
|
|
1015
|
+
return _context20.stop();
|
|
998
1016
|
}
|
|
999
|
-
},
|
|
1017
|
+
}, _callee20, this);
|
|
1000
1018
|
}));
|
|
1001
1019
|
function count(_x20) {
|
|
1002
1020
|
return _count.apply(this, arguments);
|
|
@@ -1014,43 +1032,54 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1014
1032
|
}, {
|
|
1015
1033
|
key: "countByIndex",
|
|
1016
1034
|
value: (function () {
|
|
1017
|
-
var _countByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1035
|
+
var _countByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(storeName, indexName, indexValue) {
|
|
1018
1036
|
var _this13 = this;
|
|
1019
1037
|
var matchingData;
|
|
1020
|
-
return _regeneratorRuntime().wrap(function
|
|
1021
|
-
while (1) switch (
|
|
1038
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
1039
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1022
1040
|
case 0:
|
|
1023
1041
|
if (this.useIndexDB) {
|
|
1024
|
-
|
|
1042
|
+
_context22.next = 5;
|
|
1025
1043
|
break;
|
|
1026
1044
|
}
|
|
1027
|
-
|
|
1045
|
+
_context22.next = 3;
|
|
1028
1046
|
return this.getAllByIndex(storeName, indexName, indexValue);
|
|
1029
1047
|
case 3:
|
|
1030
|
-
matchingData =
|
|
1031
|
-
return
|
|
1048
|
+
matchingData = _context22.sent;
|
|
1049
|
+
return _context22.abrupt("return", matchingData.length);
|
|
1032
1050
|
case 5:
|
|
1033
|
-
return
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
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, ")")));
|
|
1049
1078
|
case 6:
|
|
1050
1079
|
case "end":
|
|
1051
|
-
return
|
|
1080
|
+
return _context22.stop();
|
|
1052
1081
|
}
|
|
1053
|
-
},
|
|
1082
|
+
}, _callee22, this);
|
|
1054
1083
|
}));
|
|
1055
1084
|
function countByIndex(_x21, _x22, _x23) {
|
|
1056
1085
|
return _countByIndex.apply(this, arguments);
|
|
@@ -1067,40 +1096,52 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1067
1096
|
}, {
|
|
1068
1097
|
key: "getAll",
|
|
1069
1098
|
value: (function () {
|
|
1070
|
-
var _getAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1099
|
+
var _getAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(storeName) {
|
|
1071
1100
|
var _this14 = this;
|
|
1072
1101
|
var memStore;
|
|
1073
|
-
return _regeneratorRuntime().wrap(function
|
|
1074
|
-
while (1) switch (
|
|
1102
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
1103
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
1075
1104
|
case 0:
|
|
1076
1105
|
if (this.useIndexDB) {
|
|
1077
|
-
|
|
1106
|
+
_context24.next = 3;
|
|
1078
1107
|
break;
|
|
1079
1108
|
}
|
|
1080
1109
|
// 使用内存存储
|
|
1081
1110
|
memStore = this.getMemoryStore(storeName);
|
|
1082
|
-
return
|
|
1111
|
+
return _context24.abrupt("return", Array.from(memStore.values()));
|
|
1083
1112
|
case 3:
|
|
1084
|
-
return
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
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, ")")));
|
|
1099
1140
|
case 4:
|
|
1100
1141
|
case "end":
|
|
1101
|
-
return
|
|
1142
|
+
return _context24.stop();
|
|
1102
1143
|
}
|
|
1103
|
-
},
|
|
1144
|
+
}, _callee24, this);
|
|
1104
1145
|
}));
|
|
1105
1146
|
function getAll(_x24) {
|
|
1106
1147
|
return _getAll.apply(this, arguments);
|
|
@@ -1116,41 +1157,51 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1116
1157
|
}, {
|
|
1117
1158
|
key: "clear",
|
|
1118
1159
|
value: (function () {
|
|
1119
|
-
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1160
|
+
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(storeName) {
|
|
1120
1161
|
var _this15 = this;
|
|
1121
1162
|
var memStore;
|
|
1122
|
-
return _regeneratorRuntime().wrap(function
|
|
1123
|
-
while (1) switch (
|
|
1163
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
1164
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
1124
1165
|
case 0:
|
|
1125
1166
|
if (this.useIndexDB) {
|
|
1126
|
-
|
|
1167
|
+
_context26.next = 4;
|
|
1127
1168
|
break;
|
|
1128
1169
|
}
|
|
1129
1170
|
// 使用内存存储
|
|
1130
1171
|
memStore = this.getMemoryStore(storeName);
|
|
1131
1172
|
memStore.clear();
|
|
1132
|
-
return
|
|
1173
|
+
return _context26.abrupt("return", true);
|
|
1133
1174
|
case 4:
|
|
1134
|
-
return
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
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, ")")));
|
|
1149
1200
|
case 5:
|
|
1150
1201
|
case "end":
|
|
1151
|
-
return
|
|
1202
|
+
return _context26.stop();
|
|
1152
1203
|
}
|
|
1153
|
-
},
|
|
1204
|
+
}, _callee26, this);
|
|
1154
1205
|
}));
|
|
1155
1206
|
function clear(_x25) {
|
|
1156
1207
|
return _clear.apply(this, arguments);
|
|
@@ -1189,7 +1240,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1189
1240
|
* @private
|
|
1190
1241
|
*/
|
|
1191
1242
|
function isSupported() {
|
|
1192
|
-
return window && 'indexedDB' in window;
|
|
1243
|
+
return typeof window !== 'undefined' && 'indexedDB' in window;
|
|
1193
1244
|
}
|
|
1194
1245
|
}]);
|
|
1195
1246
|
return IndexDBManager;
|