@antglobal/rlog-sdk 0.0.1755855517-dev.8 → 1.0.0
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/README.md +192 -432
- package/dist/esm/index.d.ts +14 -41
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +92 -76
- package/dist/esm/lib/api.d.ts +10 -0
- package/dist/esm/lib/api.d.ts.map +1 -1
- package/dist/esm/lib/api.js +58 -35
- package/dist/esm/lib/config.d.ts +14 -16
- package/dist/esm/lib/config.d.ts.map +1 -1
- package/dist/esm/lib/config.js +61 -33
- package/dist/esm/lib/constants.d.ts +89 -0
- package/dist/esm/lib/constants.d.ts.map +1 -0
- package/dist/esm/lib/constants.js +145 -0
- package/dist/esm/lib/drive/indexeddb-adapt.d.ts +12 -0
- package/dist/esm/lib/drive/indexeddb-adapt.d.ts.map +1 -1
- package/dist/esm/lib/drive/indexeddb-adapt.js +190 -20
- package/dist/esm/lib/drive/localstorage-adapt.d.ts +12 -0
- package/dist/esm/lib/drive/localstorage-adapt.d.ts.map +1 -1
- package/dist/esm/lib/drive/localstorage-adapt.js +179 -36
- package/dist/esm/lib/drive/memory-adapt.d.ts +10 -2
- package/dist/esm/lib/drive/memory-adapt.d.ts.map +1 -1
- package/dist/esm/lib/drive/memory-adapt.js +118 -26
- package/dist/esm/lib/drive/safe-storage.d.ts +24 -0
- package/dist/esm/lib/drive/safe-storage.d.ts.map +1 -0
- package/dist/esm/lib/drive/safe-storage.js +96 -0
- package/dist/esm/lib/drive/storage-interface.d.ts +20 -0
- package/dist/esm/lib/drive/storage-interface.d.ts.map +1 -1
- package/dist/esm/lib/error-trigger.d.ts +73 -0
- package/dist/esm/lib/error-trigger.d.ts.map +1 -0
- package/dist/esm/lib/error-trigger.js +162 -0
- package/dist/esm/lib/error.d.ts +9 -0
- package/dist/esm/lib/error.d.ts.map +1 -1
- package/dist/esm/lib/error.js +70 -118
- package/dist/esm/lib/init.d.ts +0 -4
- package/dist/esm/lib/init.d.ts.map +1 -1
- package/dist/esm/lib/init.js +148 -47
- package/dist/esm/lib/logger.d.ts +27 -0
- package/dist/esm/lib/logger.d.ts.map +1 -0
- package/dist/esm/lib/logger.js +79 -0
- package/dist/esm/lib/net.d.ts +11 -0
- package/dist/esm/lib/net.d.ts.map +1 -1
- package/dist/esm/lib/net.js +264 -116
- package/dist/esm/lib/request.d.ts.map +1 -1
- package/dist/esm/lib/request.js +2 -2
- package/dist/esm/lib/router-monitor.d.ts.map +1 -1
- package/dist/esm/lib/router-monitor.js +135 -49
- package/dist/esm/lib/rrweb.d.ts.map +1 -1
- package/dist/esm/lib/rrweb.js +31 -24
- package/dist/esm/lib/storage-manager.d.ts +12 -0
- package/dist/esm/lib/storage-manager.d.ts.map +1 -1
- package/dist/esm/lib/storage-manager.js +129 -46
- package/dist/esm/lib/upload-worker-manager.d.ts +47 -0
- package/dist/esm/lib/upload-worker-manager.d.ts.map +1 -0
- package/dist/esm/lib/upload-worker-manager.js +559 -0
- package/dist/esm/lib/upload-worker.d.ts +58 -0
- package/dist/esm/lib/upload-worker.d.ts.map +1 -0
- package/dist/esm/lib/upload-worker.js +28 -0
- package/dist/esm/lib/uploader.d.ts +43 -0
- package/dist/esm/lib/uploader.d.ts.map +1 -1
- package/dist/esm/lib/uploader.js +464 -102
- package/dist/esm/lib/utils.d.ts +75 -0
- package/dist/esm/lib/utils.d.ts.map +1 -1
- package/dist/esm/lib/utils.js +268 -5
- package/dist/lib/index.d.ts +14 -41
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +81 -63
- package/dist/lib/lib/api.d.ts +10 -0
- package/dist/lib/lib/api.d.ts.map +1 -1
- package/dist/lib/lib/api.js +59 -35
- package/dist/lib/lib/config.d.ts +14 -16
- package/dist/lib/lib/config.d.ts.map +1 -1
- package/dist/lib/lib/config.js +63 -33
- package/dist/lib/lib/constants.d.ts +89 -0
- package/dist/lib/lib/constants.d.ts.map +1 -0
- package/dist/lib/lib/constants.js +151 -0
- package/dist/lib/lib/drive/indexeddb-adapt.d.ts +12 -0
- package/dist/lib/lib/drive/indexeddb-adapt.d.ts.map +1 -1
- package/dist/lib/lib/drive/indexeddb-adapt.js +191 -19
- package/dist/lib/lib/drive/localstorage-adapt.d.ts +12 -0
- package/dist/lib/lib/drive/localstorage-adapt.d.ts.map +1 -1
- package/dist/lib/lib/drive/localstorage-adapt.js +179 -36
- package/dist/lib/lib/drive/memory-adapt.d.ts +10 -2
- package/dist/lib/lib/drive/memory-adapt.d.ts.map +1 -1
- package/dist/lib/lib/drive/memory-adapt.js +117 -26
- package/dist/lib/lib/drive/safe-storage.d.ts +24 -0
- package/dist/lib/lib/drive/safe-storage.d.ts.map +1 -0
- package/dist/lib/lib/drive/safe-storage.js +102 -0
- package/dist/lib/lib/drive/storage-interface.d.ts +20 -0
- package/dist/lib/lib/drive/storage-interface.d.ts.map +1 -1
- package/dist/lib/lib/error-trigger.d.ts +73 -0
- package/dist/lib/lib/error-trigger.d.ts.map +1 -0
- package/dist/lib/lib/error-trigger.js +167 -0
- package/dist/lib/lib/error.d.ts +9 -0
- package/dist/lib/lib/error.d.ts.map +1 -1
- package/dist/lib/lib/error.js +73 -118
- package/dist/lib/lib/init.d.ts +0 -4
- package/dist/lib/lib/init.d.ts.map +1 -1
- package/dist/lib/lib/init.js +144 -43
- package/dist/lib/lib/logger.d.ts +27 -0
- package/dist/lib/lib/logger.d.ts.map +1 -0
- package/dist/lib/lib/logger.js +84 -0
- package/dist/lib/lib/net.d.ts +11 -0
- package/dist/lib/lib/net.d.ts.map +1 -1
- package/dist/lib/lib/net.js +268 -117
- package/dist/lib/lib/request.d.ts.map +1 -1
- package/dist/lib/lib/request.js +3 -3
- package/dist/lib/lib/router-monitor.d.ts.map +1 -1
- package/dist/lib/lib/router-monitor.js +136 -49
- package/dist/lib/lib/rrweb.d.ts.map +1 -1
- package/dist/lib/lib/rrweb.js +31 -23
- package/dist/lib/lib/storage-manager.d.ts +12 -0
- package/dist/lib/lib/storage-manager.d.ts.map +1 -1
- package/dist/lib/lib/storage-manager.js +130 -46
- package/dist/lib/lib/upload-worker-manager.d.ts +47 -0
- package/dist/lib/lib/upload-worker-manager.d.ts.map +1 -0
- package/dist/lib/lib/upload-worker-manager.js +570 -0
- package/dist/lib/lib/upload-worker.d.ts +58 -0
- package/dist/lib/lib/upload-worker.d.ts.map +1 -0
- package/dist/lib/lib/upload-worker.js +33 -0
- package/dist/lib/lib/uploader.d.ts +43 -0
- package/dist/lib/lib/uploader.d.ts.map +1 -1
- package/dist/lib/lib/uploader.js +468 -101
- package/dist/lib/lib/utils.d.ts +75 -0
- package/dist/lib/lib/utils.d.ts.map +1 -1
- package/dist/lib/lib/utils.js +276 -6
- package/dist/rlog-sdk.min.js +1 -1
- package/package.json +3 -2
|
@@ -4,13 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.IndexedDBAdapter = void 0;
|
|
7
|
+
var _logger = _interopRequireDefault(require("../logger"));
|
|
8
|
+
var _constants = require("../constants");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7
10
|
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); }
|
|
8
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
-
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."); }
|
|
10
|
-
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); }
|
|
11
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
12
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
13
|
-
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; }
|
|
14
11
|
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; }
|
|
15
12
|
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); } }
|
|
16
13
|
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); }); }; }
|
|
@@ -20,16 +17,16 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
20
17
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
18
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
22
19
|
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); }
|
|
23
|
-
var DB_NAME =
|
|
24
|
-
var STORE_NAME =
|
|
25
|
-
var VERSION =
|
|
20
|
+
var DB_NAME = _constants.IDB_DB_NAME;
|
|
21
|
+
var STORE_NAME = _constants.IDB_STORE_NAME;
|
|
22
|
+
var VERSION = _constants.IDB_VERSION;
|
|
26
23
|
var IndexedDBAdapter = exports.IndexedDBAdapter = /*#__PURE__*/function () {
|
|
27
24
|
function IndexedDBAdapter() {
|
|
28
25
|
_classCallCheck(this, IndexedDBAdapter);
|
|
29
26
|
_defineProperty(this, "db", null);
|
|
30
27
|
_defineProperty(this, "isOpening", false);
|
|
31
28
|
_defineProperty(this, "openPromise", null);
|
|
32
|
-
this.openDB().catch(
|
|
29
|
+
this.openDB().catch(_logger.default.error);
|
|
33
30
|
}
|
|
34
31
|
_createClass(IndexedDBAdapter, [{
|
|
35
32
|
key: "openDB",
|
|
@@ -88,7 +85,7 @@ var IndexedDBAdapter = exports.IndexedDBAdapter = /*#__PURE__*/function () {
|
|
|
88
85
|
reject(event.target.error);
|
|
89
86
|
};
|
|
90
87
|
request.onblocked = function () {
|
|
91
|
-
|
|
88
|
+
_logger.default.warn('IndexedDB is blocked, trying to close existing connections');
|
|
92
89
|
_this.isOpening = false;
|
|
93
90
|
reject(new Error('IndexedDB blocked'));
|
|
94
91
|
};
|
|
@@ -203,8 +200,8 @@ var IndexedDBAdapter = exports.IndexedDBAdapter = /*#__PURE__*/function () {
|
|
|
203
200
|
record.version = (record.version || 1) + 1;
|
|
204
201
|
|
|
205
202
|
// 限制最大存储量
|
|
206
|
-
if (record.data.length >
|
|
207
|
-
record.data.splice(0, record.data.length -
|
|
203
|
+
if (record.data.length > _constants.MAX_STORAGE_EVENTS) {
|
|
204
|
+
record.data.splice(0, record.data.length - _constants.MAX_STORAGE_EVENTS);
|
|
208
205
|
}
|
|
209
206
|
var putRequest = store.put(record);
|
|
210
207
|
putRequest.onsuccess = function () {
|
|
@@ -265,8 +262,8 @@ var IndexedDBAdapter = exports.IndexedDBAdapter = /*#__PURE__*/function () {
|
|
|
265
262
|
record.version = (record.version || 1) + 1;
|
|
266
263
|
|
|
267
264
|
// 限制最大存储量
|
|
268
|
-
if (record.data.length >
|
|
269
|
-
record.data.splice(0, record.data.length -
|
|
265
|
+
if (record.data.length > _constants.MAX_STORAGE_EVENTS) {
|
|
266
|
+
record.data.splice(0, record.data.length - _constants.MAX_STORAGE_EVENTS);
|
|
270
267
|
}
|
|
271
268
|
var putRequest = store.put(record);
|
|
272
269
|
putRequest.onsuccess = function () {
|
|
@@ -316,20 +313,19 @@ var IndexedDBAdapter = exports.IndexedDBAdapter = /*#__PURE__*/function () {
|
|
|
316
313
|
return _context8.abrupt("return", new Promise(function (resolve, reject) {
|
|
317
314
|
var getRequest = store.get(deviceId);
|
|
318
315
|
getRequest.onsuccess = function () {
|
|
319
|
-
var _record$data;
|
|
320
316
|
var record = getRequest.result || {
|
|
321
317
|
deviceId: deviceId,
|
|
322
318
|
data: [],
|
|
323
319
|
lastModified: Date.now(),
|
|
324
320
|
version: 1
|
|
325
321
|
};
|
|
326
|
-
|
|
322
|
+
record.data = data.concat(record.data);
|
|
327
323
|
record.lastModified = Date.now();
|
|
328
324
|
record.version = (record.version || 1) + 1;
|
|
329
325
|
|
|
330
326
|
// 限制最大存储量
|
|
331
|
-
if (record.data.length >
|
|
332
|
-
record.data.splice(0, record.data.length -
|
|
327
|
+
if (record.data.length > _constants.MAX_STORAGE_EVENTS) {
|
|
328
|
+
record.data.splice(0, record.data.length - _constants.MAX_STORAGE_EVENTS);
|
|
333
329
|
}
|
|
334
330
|
var putRequest = store.put(record);
|
|
335
331
|
putRequest.onsuccess = function () {
|
|
@@ -483,6 +479,182 @@ var IndexedDBAdapter = exports.IndexedDBAdapter = /*#__PURE__*/function () {
|
|
|
483
479
|
}
|
|
484
480
|
return clear;
|
|
485
481
|
}()
|
|
482
|
+
/**
|
|
483
|
+
* 按时间范围提取事件(不移除)
|
|
484
|
+
*/
|
|
485
|
+
}, {
|
|
486
|
+
key: "pullByTimeRange",
|
|
487
|
+
value: (function () {
|
|
488
|
+
var _pullByTimeRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(deviceId, startTime, endTime) {
|
|
489
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
490
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
491
|
+
case 0:
|
|
492
|
+
return _context15.abrupt("return", this.withTransaction('readonly', /*#__PURE__*/function () {
|
|
493
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(store) {
|
|
494
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
495
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
496
|
+
case 0:
|
|
497
|
+
return _context14.abrupt("return", new Promise(function (resolve, reject) {
|
|
498
|
+
var getRequest = store.get(deviceId);
|
|
499
|
+
getRequest.onsuccess = function () {
|
|
500
|
+
var record = getRequest.result || {
|
|
501
|
+
deviceId: deviceId,
|
|
502
|
+
data: [],
|
|
503
|
+
lastModified: Date.now(),
|
|
504
|
+
version: 1
|
|
505
|
+
};
|
|
506
|
+
var filtered = record.data.filter(function (event) {
|
|
507
|
+
return event.timestamp >= startTime && event.timestamp <= endTime;
|
|
508
|
+
});
|
|
509
|
+
resolve(filtered);
|
|
510
|
+
};
|
|
511
|
+
getRequest.onerror = function () {
|
|
512
|
+
return reject(getRequest.error);
|
|
513
|
+
};
|
|
514
|
+
}));
|
|
515
|
+
case 1:
|
|
516
|
+
case "end":
|
|
517
|
+
return _context14.stop();
|
|
518
|
+
}
|
|
519
|
+
}, _callee14);
|
|
520
|
+
}));
|
|
521
|
+
return function (_x20) {
|
|
522
|
+
return _ref6.apply(this, arguments);
|
|
523
|
+
};
|
|
524
|
+
}()));
|
|
525
|
+
case 1:
|
|
526
|
+
case "end":
|
|
527
|
+
return _context15.stop();
|
|
528
|
+
}
|
|
529
|
+
}, _callee15, this);
|
|
530
|
+
}));
|
|
531
|
+
function pullByTimeRange(_x17, _x18, _x19) {
|
|
532
|
+
return _pullByTimeRange.apply(this, arguments);
|
|
533
|
+
}
|
|
534
|
+
return pullByTimeRange;
|
|
535
|
+
}()
|
|
536
|
+
/**
|
|
537
|
+
* 按时间范围移除事件(移除 sinceTime 及之后的所有事件)
|
|
538
|
+
*/
|
|
539
|
+
)
|
|
540
|
+
}, {
|
|
541
|
+
key: "removeByTimeRange",
|
|
542
|
+
value: (function () {
|
|
543
|
+
var _removeByTimeRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(deviceId, sinceTime) {
|
|
544
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
545
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
546
|
+
case 0:
|
|
547
|
+
return _context17.abrupt("return", this.withTransaction('readwrite', /*#__PURE__*/function () {
|
|
548
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(store) {
|
|
549
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
550
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
551
|
+
case 0:
|
|
552
|
+
return _context16.abrupt("return", new Promise(function (resolve, reject) {
|
|
553
|
+
var getRequest = store.get(deviceId);
|
|
554
|
+
getRequest.onsuccess = function () {
|
|
555
|
+
var record = getRequest.result || {
|
|
556
|
+
deviceId: deviceId,
|
|
557
|
+
data: [],
|
|
558
|
+
lastModified: Date.now(),
|
|
559
|
+
version: 1
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
// 保留 sinceTime 之前的事件
|
|
563
|
+
record.data = record.data.filter(function (e) {
|
|
564
|
+
return e.timestamp < sinceTime;
|
|
565
|
+
});
|
|
566
|
+
record.lastModified = Date.now();
|
|
567
|
+
record.version = (record.version || 1) + 1;
|
|
568
|
+
if (record.data.length > 0) {
|
|
569
|
+
var putRequest = store.put(record);
|
|
570
|
+
putRequest.onsuccess = function () {
|
|
571
|
+
return resolve();
|
|
572
|
+
};
|
|
573
|
+
putRequest.onerror = function () {
|
|
574
|
+
return reject(putRequest.error);
|
|
575
|
+
};
|
|
576
|
+
} else {
|
|
577
|
+
var deleteRequest = store.delete(deviceId);
|
|
578
|
+
deleteRequest.onsuccess = function () {
|
|
579
|
+
return resolve();
|
|
580
|
+
};
|
|
581
|
+
deleteRequest.onerror = function () {
|
|
582
|
+
return reject(deleteRequest.error);
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
getRequest.onerror = function () {
|
|
587
|
+
return reject(getRequest.error);
|
|
588
|
+
};
|
|
589
|
+
}));
|
|
590
|
+
case 1:
|
|
591
|
+
case "end":
|
|
592
|
+
return _context16.stop();
|
|
593
|
+
}
|
|
594
|
+
}, _callee16);
|
|
595
|
+
}));
|
|
596
|
+
return function (_x23) {
|
|
597
|
+
return _ref7.apply(this, arguments);
|
|
598
|
+
};
|
|
599
|
+
}()));
|
|
600
|
+
case 1:
|
|
601
|
+
case "end":
|
|
602
|
+
return _context17.stop();
|
|
603
|
+
}
|
|
604
|
+
}, _callee17, this);
|
|
605
|
+
}));
|
|
606
|
+
function removeByTimeRange(_x21, _x22) {
|
|
607
|
+
return _removeByTimeRange.apply(this, arguments);
|
|
608
|
+
}
|
|
609
|
+
return removeByTimeRange;
|
|
610
|
+
}()
|
|
611
|
+
/**
|
|
612
|
+
* 获取存储的事件数量(非破坏性只读操作)
|
|
613
|
+
*/
|
|
614
|
+
)
|
|
615
|
+
}, {
|
|
616
|
+
key: "count",
|
|
617
|
+
value: (function () {
|
|
618
|
+
var _count = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(deviceId) {
|
|
619
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
620
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
621
|
+
case 0:
|
|
622
|
+
return _context19.abrupt("return", this.withTransaction('readonly', /*#__PURE__*/function () {
|
|
623
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(store) {
|
|
624
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
625
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
626
|
+
case 0:
|
|
627
|
+
return _context18.abrupt("return", new Promise(function (resolve, reject) {
|
|
628
|
+
var getRequest = store.get(deviceId);
|
|
629
|
+
getRequest.onsuccess = function () {
|
|
630
|
+
var record = getRequest.result;
|
|
631
|
+
resolve(record ? record.data.length : 0);
|
|
632
|
+
};
|
|
633
|
+
getRequest.onerror = function () {
|
|
634
|
+
return reject(getRequest.error);
|
|
635
|
+
};
|
|
636
|
+
}));
|
|
637
|
+
case 1:
|
|
638
|
+
case "end":
|
|
639
|
+
return _context18.stop();
|
|
640
|
+
}
|
|
641
|
+
}, _callee18);
|
|
642
|
+
}));
|
|
643
|
+
return function (_x25) {
|
|
644
|
+
return _ref8.apply(this, arguments);
|
|
645
|
+
};
|
|
646
|
+
}()));
|
|
647
|
+
case 1:
|
|
648
|
+
case "end":
|
|
649
|
+
return _context19.stop();
|
|
650
|
+
}
|
|
651
|
+
}, _callee19, this);
|
|
652
|
+
}));
|
|
653
|
+
function count(_x24) {
|
|
654
|
+
return _count.apply(this, arguments);
|
|
655
|
+
}
|
|
656
|
+
return count;
|
|
657
|
+
}())
|
|
486
658
|
}]);
|
|
487
659
|
return IndexedDBAdapter;
|
|
488
660
|
}();
|
|
@@ -29,5 +29,17 @@ export declare class LocalStorageAdapter implements StorageAdapter {
|
|
|
29
29
|
unshiftBatch(deviceId: string, data: any[]): Promise<void>;
|
|
30
30
|
pull(deviceId: string, length: number): Promise<any[]>;
|
|
31
31
|
clear(deviceId: string): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* 按时间范围提取事件(不移除)
|
|
34
|
+
*/
|
|
35
|
+
pullByTimeRange(deviceId: string, startTime: number, endTime: number): Promise<any[]>;
|
|
36
|
+
/**
|
|
37
|
+
* 按时间范围移除事件(移除 sinceTime 及之后的所有事件)
|
|
38
|
+
*/
|
|
39
|
+
removeByTimeRange(deviceId: string, sinceTime: number): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* 获取存储的事件数量(非破坏性只读操作)
|
|
42
|
+
*/
|
|
43
|
+
count(deviceId: string): Promise<number>;
|
|
32
44
|
}
|
|
33
45
|
//# sourceMappingURL=localstorage-adapt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localstorage-adapt.d.ts","sourceRoot":"","sources":["../../../../src/lib/drive/localstorage-adapt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"localstorage-adapt.d.ts","sourceRoot":"","sources":["../../../../src/lib/drive/localstorage-adapt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAWrD;;GAEG;AACH,qBAAa,mBAAoB,YAAW,cAAc;IACxD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAA2B;IAClE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAA2B;IACrE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAgB;IACpD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAoB;IACvD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAEvD;;OAEG;YACW,WAAW;IA+BzB;;OAEG;IACH,OAAO,CAAC,WAAW;IASnB;;OAEG;YACW,QAAQ;IAuBtB;;OAEG;IACH,OAAO,CAAC,aAAa;IAIf,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBhD,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBnD,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAsB1D,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IA8BtD,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW5C;;OAEG;IACG,eAAe,CACnB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,GAAG,EAAE,CAAC;IAgBjB;;OAEG;IACG,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB3E;;OAEG;IACG,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAY/C"}
|
|
@@ -5,11 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.LocalStorageAdapter = void 0;
|
|
7
7
|
var _memoryAdapt = require("./memory-adapt");
|
|
8
|
+
var _logger = _interopRequireDefault(require("../logger"));
|
|
9
|
+
var _constants = require("../constants");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
11
|
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); }
|
|
9
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
10
|
-
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."); }
|
|
11
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
12
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
13
12
|
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; }
|
|
14
13
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
15
14
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -34,7 +33,7 @@ var LocalStorageAdapter = exports.LocalStorageAdapter = /*#__PURE__*/function ()
|
|
|
34
33
|
}
|
|
35
34
|
_createClass(LocalStorageAdapter, [{
|
|
36
35
|
key: "acquireLock",
|
|
37
|
-
value:
|
|
36
|
+
value: (
|
|
38
37
|
/**
|
|
39
38
|
* 获取分布式锁
|
|
40
39
|
*/
|
|
@@ -62,19 +61,19 @@ var LocalStorageAdapter = exports.LocalStorageAdapter = /*#__PURE__*/function ()
|
|
|
62
61
|
case 8:
|
|
63
62
|
localStorage.setItem(lockKey, lockValue);
|
|
64
63
|
|
|
65
|
-
//
|
|
64
|
+
// 随机短暂延迟,让并发的 setItem 有机会完成
|
|
65
|
+
_context.next = 11;
|
|
66
|
+
return new Promise(function (resolve) {
|
|
67
|
+
return setTimeout(resolve, Math.floor(Math.random() * 3) + 1);
|
|
68
|
+
});
|
|
69
|
+
case 11:
|
|
70
|
+
// 二次验证:延迟后仍是自己的值,说明没有被覆盖
|
|
66
71
|
verifyLock = localStorage.getItem(lockKey);
|
|
67
|
-
|
|
68
|
-
_context.next = 12;
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
return _context.abrupt("return", true);
|
|
72
|
-
case 12:
|
|
73
|
-
return _context.abrupt("return", false);
|
|
72
|
+
return _context.abrupt("return", verifyLock === lockValue);
|
|
74
73
|
case 15:
|
|
75
74
|
_context.prev = 15;
|
|
76
75
|
_context.t0 = _context["catch"](2);
|
|
77
|
-
|
|
76
|
+
_logger.default.warn('Failed to acquire lock', _context.t0);
|
|
78
77
|
return _context.abrupt("return", false);
|
|
79
78
|
case 19:
|
|
80
79
|
case "end":
|
|
@@ -90,6 +89,7 @@ var LocalStorageAdapter = exports.LocalStorageAdapter = /*#__PURE__*/function ()
|
|
|
90
89
|
/**
|
|
91
90
|
* 释放分布式锁
|
|
92
91
|
*/
|
|
92
|
+
)
|
|
93
93
|
}, {
|
|
94
94
|
key: "releaseLock",
|
|
95
95
|
value: function releaseLock(deviceId) {
|
|
@@ -97,7 +97,7 @@ var LocalStorageAdapter = exports.LocalStorageAdapter = /*#__PURE__*/function ()
|
|
|
97
97
|
try {
|
|
98
98
|
localStorage.removeItem(lockKey);
|
|
99
99
|
} catch (e) {
|
|
100
|
-
|
|
100
|
+
_logger.default.warn('Failed to release lock', e);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -187,8 +187,8 @@ var LocalStorageAdapter = exports.LocalStorageAdapter = /*#__PURE__*/function ()
|
|
|
187
187
|
list.push(data);
|
|
188
188
|
|
|
189
189
|
// 限制最大存储量,防止内存溢出
|
|
190
|
-
if (list.length >
|
|
191
|
-
list.splice(0, list.length -
|
|
190
|
+
if (list.length > _constants.MAX_STORAGE_EVENTS) {
|
|
191
|
+
list.splice(0, list.length - _constants.MAX_STORAGE_EVENTS);
|
|
192
192
|
}
|
|
193
193
|
localStorage.setItem(key, JSON.stringify(list));
|
|
194
194
|
case 6:
|
|
@@ -203,7 +203,7 @@ var LocalStorageAdapter = exports.LocalStorageAdapter = /*#__PURE__*/function ()
|
|
|
203
203
|
case 5:
|
|
204
204
|
_context4.prev = 5;
|
|
205
205
|
_context4.t0 = _context4["catch"](0);
|
|
206
|
-
|
|
206
|
+
_logger.default.warn('LocalStorage不可用,将使用内存缓存');
|
|
207
207
|
return _context4.abrupt("return", _memoryAdapt.MemoryAdapter.getInstance().push(deviceId, data));
|
|
208
208
|
case 9:
|
|
209
209
|
case "end":
|
|
@@ -237,8 +237,8 @@ var LocalStorageAdapter = exports.LocalStorageAdapter = /*#__PURE__*/function ()
|
|
|
237
237
|
list.unshift(data);
|
|
238
238
|
|
|
239
239
|
// 限制最大存储量
|
|
240
|
-
if (list.length >
|
|
241
|
-
list.splice(0, list.length -
|
|
240
|
+
if (list.length > _constants.MAX_STORAGE_EVENTS) {
|
|
241
|
+
list.splice(0, list.length - _constants.MAX_STORAGE_EVENTS);
|
|
242
242
|
}
|
|
243
243
|
localStorage.setItem(key, JSON.stringify(list));
|
|
244
244
|
case 6:
|
|
@@ -253,7 +253,7 @@ var LocalStorageAdapter = exports.LocalStorageAdapter = /*#__PURE__*/function ()
|
|
|
253
253
|
case 5:
|
|
254
254
|
_context6.prev = 5;
|
|
255
255
|
_context6.t0 = _context6["catch"](0);
|
|
256
|
-
|
|
256
|
+
_logger.default.warn('LocalStorage不可用,将使用内存缓存');
|
|
257
257
|
return _context6.abrupt("return", _memoryAdapt.MemoryAdapter.getInstance().unshift(deviceId, data));
|
|
258
258
|
case 9:
|
|
259
259
|
case "end":
|
|
@@ -277,20 +277,18 @@ var LocalStorageAdapter = exports.LocalStorageAdapter = /*#__PURE__*/function ()
|
|
|
277
277
|
_context8.prev = 0;
|
|
278
278
|
_context8.next = 3;
|
|
279
279
|
return this.withLock(deviceId, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
280
|
-
var key, stored, list;
|
|
280
|
+
var key, stored, list, merged;
|
|
281
281
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
282
282
|
while (1) switch (_context7.prev = _context7.next) {
|
|
283
283
|
case 0:
|
|
284
284
|
key = _this3.getStorageKey(deviceId);
|
|
285
285
|
stored = localStorage.getItem(key);
|
|
286
286
|
list = stored ? JSON.parse(stored) : [];
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
if (list.length > 10000) {
|
|
291
|
-
list.splice(0, list.length - 10000);
|
|
287
|
+
merged = data.concat(list); // 限制最大存储量
|
|
288
|
+
if (merged.length > _constants.MAX_STORAGE_EVENTS) {
|
|
289
|
+
merged.splice(0, merged.length - _constants.MAX_STORAGE_EVENTS);
|
|
292
290
|
}
|
|
293
|
-
localStorage.setItem(key, JSON.stringify(
|
|
291
|
+
localStorage.setItem(key, JSON.stringify(merged));
|
|
294
292
|
case 6:
|
|
295
293
|
case "end":
|
|
296
294
|
return _context7.stop();
|
|
@@ -303,7 +301,7 @@ var LocalStorageAdapter = exports.LocalStorageAdapter = /*#__PURE__*/function ()
|
|
|
303
301
|
case 5:
|
|
304
302
|
_context8.prev = 5;
|
|
305
303
|
_context8.t0 = _context8["catch"](0);
|
|
306
|
-
|
|
304
|
+
_logger.default.warn('LocalStorage不可用,将使用内存缓存');
|
|
307
305
|
return _context8.abrupt("return", _memoryAdapt.MemoryAdapter.getInstance().unshiftBatch(deviceId, data));
|
|
308
306
|
case 9:
|
|
309
307
|
case "end":
|
|
@@ -414,13 +412,158 @@ var LocalStorageAdapter = exports.LocalStorageAdapter = /*#__PURE__*/function ()
|
|
|
414
412
|
}
|
|
415
413
|
return clear;
|
|
416
414
|
}()
|
|
415
|
+
/**
|
|
416
|
+
* 按时间范围提取事件(不移除)
|
|
417
|
+
*/
|
|
418
|
+
}, {
|
|
419
|
+
key: "pullByTimeRange",
|
|
420
|
+
value: (function () {
|
|
421
|
+
var _pullByTimeRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(deviceId, startTime, endTime) {
|
|
422
|
+
var _this6 = this;
|
|
423
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
424
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
425
|
+
case 0:
|
|
426
|
+
_context14.prev = 0;
|
|
427
|
+
_context14.next = 3;
|
|
428
|
+
return this.withLock(deviceId, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
|
|
429
|
+
var key, stored, list;
|
|
430
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
431
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
432
|
+
case 0:
|
|
433
|
+
key = _this6.getStorageKey(deviceId);
|
|
434
|
+
stored = localStorage.getItem(key);
|
|
435
|
+
list = stored ? JSON.parse(stored) : [];
|
|
436
|
+
return _context13.abrupt("return", list.filter(function (event) {
|
|
437
|
+
return event.timestamp >= startTime && event.timestamp <= endTime;
|
|
438
|
+
}));
|
|
439
|
+
case 4:
|
|
440
|
+
case "end":
|
|
441
|
+
return _context13.stop();
|
|
442
|
+
}
|
|
443
|
+
}, _callee13);
|
|
444
|
+
})));
|
|
445
|
+
case 3:
|
|
446
|
+
return _context14.abrupt("return", _context14.sent);
|
|
447
|
+
case 6:
|
|
448
|
+
_context14.prev = 6;
|
|
449
|
+
_context14.t0 = _context14["catch"](0);
|
|
450
|
+
return _context14.abrupt("return", _memoryAdapt.MemoryAdapter.getInstance().pullByTimeRange(deviceId, startTime, endTime));
|
|
451
|
+
case 9:
|
|
452
|
+
case "end":
|
|
453
|
+
return _context14.stop();
|
|
454
|
+
}
|
|
455
|
+
}, _callee14, this, [[0, 6]]);
|
|
456
|
+
}));
|
|
457
|
+
function pullByTimeRange(_x13, _x14, _x15) {
|
|
458
|
+
return _pullByTimeRange.apply(this, arguments);
|
|
459
|
+
}
|
|
460
|
+
return pullByTimeRange;
|
|
461
|
+
}()
|
|
462
|
+
/**
|
|
463
|
+
* 按时间范围移除事件(移除 sinceTime 及之后的所有事件)
|
|
464
|
+
*/
|
|
465
|
+
)
|
|
466
|
+
}, {
|
|
467
|
+
key: "removeByTimeRange",
|
|
468
|
+
value: (function () {
|
|
469
|
+
var _removeByTimeRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(deviceId, sinceTime) {
|
|
470
|
+
var _this7 = this;
|
|
471
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
472
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
473
|
+
case 0:
|
|
474
|
+
_context16.prev = 0;
|
|
475
|
+
_context16.next = 3;
|
|
476
|
+
return this.withLock(deviceId, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
|
|
477
|
+
var key, stored, list, remaining;
|
|
478
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
479
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
480
|
+
case 0:
|
|
481
|
+
key = _this7.getStorageKey(deviceId);
|
|
482
|
+
stored = localStorage.getItem(key);
|
|
483
|
+
list = stored ? JSON.parse(stored) : []; // 保留 sinceTime 之前的事件
|
|
484
|
+
remaining = list.filter(function (e) {
|
|
485
|
+
return e.timestamp < sinceTime;
|
|
486
|
+
});
|
|
487
|
+
if (remaining.length > 0) {
|
|
488
|
+
localStorage.setItem(key, JSON.stringify(remaining));
|
|
489
|
+
} else {
|
|
490
|
+
localStorage.removeItem(key);
|
|
491
|
+
}
|
|
492
|
+
case 5:
|
|
493
|
+
case "end":
|
|
494
|
+
return _context15.stop();
|
|
495
|
+
}
|
|
496
|
+
}, _callee15);
|
|
497
|
+
})));
|
|
498
|
+
case 3:
|
|
499
|
+
_context16.next = 8;
|
|
500
|
+
break;
|
|
501
|
+
case 5:
|
|
502
|
+
_context16.prev = 5;
|
|
503
|
+
_context16.t0 = _context16["catch"](0);
|
|
504
|
+
return _context16.abrupt("return", _memoryAdapt.MemoryAdapter.getInstance().removeByTimeRange(deviceId, sinceTime));
|
|
505
|
+
case 8:
|
|
506
|
+
case "end":
|
|
507
|
+
return _context16.stop();
|
|
508
|
+
}
|
|
509
|
+
}, _callee16, this, [[0, 5]]);
|
|
510
|
+
}));
|
|
511
|
+
function removeByTimeRange(_x16, _x17) {
|
|
512
|
+
return _removeByTimeRange.apply(this, arguments);
|
|
513
|
+
}
|
|
514
|
+
return removeByTimeRange;
|
|
515
|
+
}()
|
|
516
|
+
/**
|
|
517
|
+
* 获取存储的事件数量(非破坏性只读操作)
|
|
518
|
+
*/
|
|
519
|
+
)
|
|
520
|
+
}, {
|
|
521
|
+
key: "count",
|
|
522
|
+
value: (function () {
|
|
523
|
+
var _count = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(deviceId) {
|
|
524
|
+
var _this8 = this;
|
|
525
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
526
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
527
|
+
case 0:
|
|
528
|
+
_context18.prev = 0;
|
|
529
|
+
_context18.next = 3;
|
|
530
|
+
return this.withLock(deviceId, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
|
|
531
|
+
var key, stored, list;
|
|
532
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
533
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
534
|
+
case 0:
|
|
535
|
+
key = _this8.getStorageKey(deviceId);
|
|
536
|
+
stored = localStorage.getItem(key);
|
|
537
|
+
list = stored ? JSON.parse(stored) : [];
|
|
538
|
+
return _context17.abrupt("return", list.length);
|
|
539
|
+
case 4:
|
|
540
|
+
case "end":
|
|
541
|
+
return _context17.stop();
|
|
542
|
+
}
|
|
543
|
+
}, _callee17);
|
|
544
|
+
})));
|
|
545
|
+
case 3:
|
|
546
|
+
return _context18.abrupt("return", _context18.sent);
|
|
547
|
+
case 6:
|
|
548
|
+
_context18.prev = 6;
|
|
549
|
+
_context18.t0 = _context18["catch"](0);
|
|
550
|
+
return _context18.abrupt("return", _memoryAdapt.MemoryAdapter.getInstance().count(deviceId));
|
|
551
|
+
case 9:
|
|
552
|
+
case "end":
|
|
553
|
+
return _context18.stop();
|
|
554
|
+
}
|
|
555
|
+
}, _callee18, this, [[0, 6]]);
|
|
556
|
+
}));
|
|
557
|
+
function count(_x18) {
|
|
558
|
+
return _count.apply(this, arguments);
|
|
559
|
+
}
|
|
560
|
+
return count;
|
|
561
|
+
}())
|
|
417
562
|
}]);
|
|
418
563
|
return LocalStorageAdapter;
|
|
419
564
|
}();
|
|
420
|
-
_defineProperty(LocalStorageAdapter, "LOCK_KEY_PREFIX",
|
|
421
|
-
_defineProperty(LocalStorageAdapter, "STORAGE_KEY_PREFIX",
|
|
422
|
-
_defineProperty(LocalStorageAdapter, "LOCK_TIMEOUT",
|
|
423
|
-
|
|
424
|
-
_defineProperty(LocalStorageAdapter, "
|
|
425
|
-
// 10ms重试间隔
|
|
426
|
-
_defineProperty(LocalStorageAdapter, "MAX_RETRIES", 50);
|
|
565
|
+
_defineProperty(LocalStorageAdapter, "LOCK_KEY_PREFIX", _constants.STORAGE_KEY_LOCK_PREFIX);
|
|
566
|
+
_defineProperty(LocalStorageAdapter, "STORAGE_KEY_PREFIX", _constants.STORAGE_KEY_DATA_PREFIX);
|
|
567
|
+
_defineProperty(LocalStorageAdapter, "LOCK_TIMEOUT", _constants.LOCK_TIMEOUT);
|
|
568
|
+
_defineProperty(LocalStorageAdapter, "RETRY_DELAY", _constants.LOCK_RETRY_DELAY);
|
|
569
|
+
_defineProperty(LocalStorageAdapter, "MAX_RETRIES", _constants.LOCK_MAX_RETRIES);
|