@antglobal/rlog-sdk 0.0.1755855517-dev.8 → 0.0.1779194445-dev.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 +15 -41
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +101 -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 +15 -41
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +89 -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
|
@@ -1,10 +1,4 @@
|
|
|
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
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
-
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."); }
|
|
4
|
-
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); }
|
|
5
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
-
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; }
|
|
8
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; }
|
|
9
3
|
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); } }
|
|
10
4
|
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); }); }; }
|
|
@@ -14,17 +8,18 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
14
8
|
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; }
|
|
15
9
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
16
10
|
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); }
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var
|
|
20
|
-
|
|
11
|
+
import logger from "../logger";
|
|
12
|
+
import { IDB_DB_NAME, IDB_STORE_NAME, IDB_VERSION, MAX_STORAGE_EVENTS } from "../constants";
|
|
13
|
+
var DB_NAME = IDB_DB_NAME;
|
|
14
|
+
var STORE_NAME = IDB_STORE_NAME;
|
|
15
|
+
var VERSION = IDB_VERSION;
|
|
21
16
|
export var IndexedDBAdapter = /*#__PURE__*/function () {
|
|
22
17
|
function IndexedDBAdapter() {
|
|
23
18
|
_classCallCheck(this, IndexedDBAdapter);
|
|
24
19
|
_defineProperty(this, "db", null);
|
|
25
20
|
_defineProperty(this, "isOpening", false);
|
|
26
21
|
_defineProperty(this, "openPromise", null);
|
|
27
|
-
this.openDB().catch(
|
|
22
|
+
this.openDB().catch(logger.error);
|
|
28
23
|
}
|
|
29
24
|
_createClass(IndexedDBAdapter, [{
|
|
30
25
|
key: "openDB",
|
|
@@ -83,7 +78,7 @@ export var IndexedDBAdapter = /*#__PURE__*/function () {
|
|
|
83
78
|
reject(event.target.error);
|
|
84
79
|
};
|
|
85
80
|
request.onblocked = function () {
|
|
86
|
-
|
|
81
|
+
logger.warn('IndexedDB is blocked, trying to close existing connections');
|
|
87
82
|
_this.isOpening = false;
|
|
88
83
|
reject(new Error('IndexedDB blocked'));
|
|
89
84
|
};
|
|
@@ -198,8 +193,8 @@ export var IndexedDBAdapter = /*#__PURE__*/function () {
|
|
|
198
193
|
record.version = (record.version || 1) + 1;
|
|
199
194
|
|
|
200
195
|
// 限制最大存储量
|
|
201
|
-
if (record.data.length >
|
|
202
|
-
record.data.splice(0, record.data.length -
|
|
196
|
+
if (record.data.length > MAX_STORAGE_EVENTS) {
|
|
197
|
+
record.data.splice(0, record.data.length - MAX_STORAGE_EVENTS);
|
|
203
198
|
}
|
|
204
199
|
var putRequest = store.put(record);
|
|
205
200
|
putRequest.onsuccess = function () {
|
|
@@ -260,8 +255,8 @@ export var IndexedDBAdapter = /*#__PURE__*/function () {
|
|
|
260
255
|
record.version = (record.version || 1) + 1;
|
|
261
256
|
|
|
262
257
|
// 限制最大存储量
|
|
263
|
-
if (record.data.length >
|
|
264
|
-
record.data.splice(0, record.data.length -
|
|
258
|
+
if (record.data.length > MAX_STORAGE_EVENTS) {
|
|
259
|
+
record.data.splice(0, record.data.length - MAX_STORAGE_EVENTS);
|
|
265
260
|
}
|
|
266
261
|
var putRequest = store.put(record);
|
|
267
262
|
putRequest.onsuccess = function () {
|
|
@@ -311,20 +306,19 @@ export var IndexedDBAdapter = /*#__PURE__*/function () {
|
|
|
311
306
|
return _context8.abrupt("return", new Promise(function (resolve, reject) {
|
|
312
307
|
var getRequest = store.get(deviceId);
|
|
313
308
|
getRequest.onsuccess = function () {
|
|
314
|
-
var _record$data;
|
|
315
309
|
var record = getRequest.result || {
|
|
316
310
|
deviceId: deviceId,
|
|
317
311
|
data: [],
|
|
318
312
|
lastModified: Date.now(),
|
|
319
313
|
version: 1
|
|
320
314
|
};
|
|
321
|
-
|
|
315
|
+
record.data = data.concat(record.data);
|
|
322
316
|
record.lastModified = Date.now();
|
|
323
317
|
record.version = (record.version || 1) + 1;
|
|
324
318
|
|
|
325
319
|
// 限制最大存储量
|
|
326
|
-
if (record.data.length >
|
|
327
|
-
record.data.splice(0, record.data.length -
|
|
320
|
+
if (record.data.length > MAX_STORAGE_EVENTS) {
|
|
321
|
+
record.data.splice(0, record.data.length - MAX_STORAGE_EVENTS);
|
|
328
322
|
}
|
|
329
323
|
var putRequest = store.put(record);
|
|
330
324
|
putRequest.onsuccess = function () {
|
|
@@ -478,6 +472,182 @@ export var IndexedDBAdapter = /*#__PURE__*/function () {
|
|
|
478
472
|
}
|
|
479
473
|
return clear;
|
|
480
474
|
}()
|
|
475
|
+
/**
|
|
476
|
+
* 按时间范围提取事件(不移除)
|
|
477
|
+
*/
|
|
478
|
+
}, {
|
|
479
|
+
key: "pullByTimeRange",
|
|
480
|
+
value: (function () {
|
|
481
|
+
var _pullByTimeRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(deviceId, startTime, endTime) {
|
|
482
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
483
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
484
|
+
case 0:
|
|
485
|
+
return _context15.abrupt("return", this.withTransaction('readonly', /*#__PURE__*/function () {
|
|
486
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(store) {
|
|
487
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
488
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
489
|
+
case 0:
|
|
490
|
+
return _context14.abrupt("return", new Promise(function (resolve, reject) {
|
|
491
|
+
var getRequest = store.get(deviceId);
|
|
492
|
+
getRequest.onsuccess = function () {
|
|
493
|
+
var record = getRequest.result || {
|
|
494
|
+
deviceId: deviceId,
|
|
495
|
+
data: [],
|
|
496
|
+
lastModified: Date.now(),
|
|
497
|
+
version: 1
|
|
498
|
+
};
|
|
499
|
+
var filtered = record.data.filter(function (event) {
|
|
500
|
+
return event.timestamp >= startTime && event.timestamp <= endTime;
|
|
501
|
+
});
|
|
502
|
+
resolve(filtered);
|
|
503
|
+
};
|
|
504
|
+
getRequest.onerror = function () {
|
|
505
|
+
return reject(getRequest.error);
|
|
506
|
+
};
|
|
507
|
+
}));
|
|
508
|
+
case 1:
|
|
509
|
+
case "end":
|
|
510
|
+
return _context14.stop();
|
|
511
|
+
}
|
|
512
|
+
}, _callee14);
|
|
513
|
+
}));
|
|
514
|
+
return function (_x20) {
|
|
515
|
+
return _ref6.apply(this, arguments);
|
|
516
|
+
};
|
|
517
|
+
}()));
|
|
518
|
+
case 1:
|
|
519
|
+
case "end":
|
|
520
|
+
return _context15.stop();
|
|
521
|
+
}
|
|
522
|
+
}, _callee15, this);
|
|
523
|
+
}));
|
|
524
|
+
function pullByTimeRange(_x17, _x18, _x19) {
|
|
525
|
+
return _pullByTimeRange.apply(this, arguments);
|
|
526
|
+
}
|
|
527
|
+
return pullByTimeRange;
|
|
528
|
+
}()
|
|
529
|
+
/**
|
|
530
|
+
* 按时间范围移除事件(移除 sinceTime 及之后的所有事件)
|
|
531
|
+
*/
|
|
532
|
+
)
|
|
533
|
+
}, {
|
|
534
|
+
key: "removeByTimeRange",
|
|
535
|
+
value: (function () {
|
|
536
|
+
var _removeByTimeRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(deviceId, sinceTime) {
|
|
537
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
538
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
539
|
+
case 0:
|
|
540
|
+
return _context17.abrupt("return", this.withTransaction('readwrite', /*#__PURE__*/function () {
|
|
541
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(store) {
|
|
542
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
543
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
544
|
+
case 0:
|
|
545
|
+
return _context16.abrupt("return", new Promise(function (resolve, reject) {
|
|
546
|
+
var getRequest = store.get(deviceId);
|
|
547
|
+
getRequest.onsuccess = function () {
|
|
548
|
+
var record = getRequest.result || {
|
|
549
|
+
deviceId: deviceId,
|
|
550
|
+
data: [],
|
|
551
|
+
lastModified: Date.now(),
|
|
552
|
+
version: 1
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
// 保留 sinceTime 之前的事件
|
|
556
|
+
record.data = record.data.filter(function (e) {
|
|
557
|
+
return e.timestamp < sinceTime;
|
|
558
|
+
});
|
|
559
|
+
record.lastModified = Date.now();
|
|
560
|
+
record.version = (record.version || 1) + 1;
|
|
561
|
+
if (record.data.length > 0) {
|
|
562
|
+
var putRequest = store.put(record);
|
|
563
|
+
putRequest.onsuccess = function () {
|
|
564
|
+
return resolve();
|
|
565
|
+
};
|
|
566
|
+
putRequest.onerror = function () {
|
|
567
|
+
return reject(putRequest.error);
|
|
568
|
+
};
|
|
569
|
+
} else {
|
|
570
|
+
var deleteRequest = store.delete(deviceId);
|
|
571
|
+
deleteRequest.onsuccess = function () {
|
|
572
|
+
return resolve();
|
|
573
|
+
};
|
|
574
|
+
deleteRequest.onerror = function () {
|
|
575
|
+
return reject(deleteRequest.error);
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
getRequest.onerror = function () {
|
|
580
|
+
return reject(getRequest.error);
|
|
581
|
+
};
|
|
582
|
+
}));
|
|
583
|
+
case 1:
|
|
584
|
+
case "end":
|
|
585
|
+
return _context16.stop();
|
|
586
|
+
}
|
|
587
|
+
}, _callee16);
|
|
588
|
+
}));
|
|
589
|
+
return function (_x23) {
|
|
590
|
+
return _ref7.apply(this, arguments);
|
|
591
|
+
};
|
|
592
|
+
}()));
|
|
593
|
+
case 1:
|
|
594
|
+
case "end":
|
|
595
|
+
return _context17.stop();
|
|
596
|
+
}
|
|
597
|
+
}, _callee17, this);
|
|
598
|
+
}));
|
|
599
|
+
function removeByTimeRange(_x21, _x22) {
|
|
600
|
+
return _removeByTimeRange.apply(this, arguments);
|
|
601
|
+
}
|
|
602
|
+
return removeByTimeRange;
|
|
603
|
+
}()
|
|
604
|
+
/**
|
|
605
|
+
* 获取存储的事件数量(非破坏性只读操作)
|
|
606
|
+
*/
|
|
607
|
+
)
|
|
608
|
+
}, {
|
|
609
|
+
key: "count",
|
|
610
|
+
value: (function () {
|
|
611
|
+
var _count = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(deviceId) {
|
|
612
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
613
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
614
|
+
case 0:
|
|
615
|
+
return _context19.abrupt("return", this.withTransaction('readonly', /*#__PURE__*/function () {
|
|
616
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(store) {
|
|
617
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
618
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
619
|
+
case 0:
|
|
620
|
+
return _context18.abrupt("return", new Promise(function (resolve, reject) {
|
|
621
|
+
var getRequest = store.get(deviceId);
|
|
622
|
+
getRequest.onsuccess = function () {
|
|
623
|
+
var record = getRequest.result;
|
|
624
|
+
resolve(record ? record.data.length : 0);
|
|
625
|
+
};
|
|
626
|
+
getRequest.onerror = function () {
|
|
627
|
+
return reject(getRequest.error);
|
|
628
|
+
};
|
|
629
|
+
}));
|
|
630
|
+
case 1:
|
|
631
|
+
case "end":
|
|
632
|
+
return _context18.stop();
|
|
633
|
+
}
|
|
634
|
+
}, _callee18);
|
|
635
|
+
}));
|
|
636
|
+
return function (_x25) {
|
|
637
|
+
return _ref8.apply(this, arguments);
|
|
638
|
+
};
|
|
639
|
+
}()));
|
|
640
|
+
case 1:
|
|
641
|
+
case "end":
|
|
642
|
+
return _context19.stop();
|
|
643
|
+
}
|
|
644
|
+
}, _callee19, this);
|
|
645
|
+
}));
|
|
646
|
+
function count(_x24) {
|
|
647
|
+
return _count.apply(this, arguments);
|
|
648
|
+
}
|
|
649
|
+
return count;
|
|
650
|
+
}())
|
|
481
651
|
}]);
|
|
482
652
|
return IndexedDBAdapter;
|
|
483
653
|
}();
|
|
@@ -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"}
|
|
@@ -1,8 +1,4 @@
|
|
|
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
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
-
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."); }
|
|
4
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6
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; }
|
|
7
3
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
4
|
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."); }
|
|
@@ -19,6 +15,9 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
19
15
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
20
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); }
|
|
21
17
|
import { MemoryAdapter } from "./memory-adapt";
|
|
18
|
+
import logger from "../logger";
|
|
19
|
+
import { STORAGE_KEY_LOCK_PREFIX, STORAGE_KEY_DATA_PREFIX, LOCK_TIMEOUT, LOCK_RETRY_DELAY, LOCK_MAX_RETRIES, MAX_STORAGE_EVENTS } from "../constants";
|
|
20
|
+
|
|
22
21
|
/**
|
|
23
22
|
* 使用锁机制解决localStorage多标签并发问题
|
|
24
23
|
*/
|
|
@@ -28,7 +27,7 @@ export var LocalStorageAdapter = /*#__PURE__*/function () {
|
|
|
28
27
|
}
|
|
29
28
|
_createClass(LocalStorageAdapter, [{
|
|
30
29
|
key: "acquireLock",
|
|
31
|
-
value:
|
|
30
|
+
value: (
|
|
32
31
|
/**
|
|
33
32
|
* 获取分布式锁
|
|
34
33
|
*/
|
|
@@ -56,19 +55,19 @@ export var LocalStorageAdapter = /*#__PURE__*/function () {
|
|
|
56
55
|
case 8:
|
|
57
56
|
localStorage.setItem(lockKey, lockValue);
|
|
58
57
|
|
|
59
|
-
//
|
|
58
|
+
// 随机短暂延迟,让并发的 setItem 有机会完成
|
|
59
|
+
_context.next = 11;
|
|
60
|
+
return new Promise(function (resolve) {
|
|
61
|
+
return setTimeout(resolve, Math.floor(Math.random() * 3) + 1);
|
|
62
|
+
});
|
|
63
|
+
case 11:
|
|
64
|
+
// 二次验证:延迟后仍是自己的值,说明没有被覆盖
|
|
60
65
|
verifyLock = localStorage.getItem(lockKey);
|
|
61
|
-
|
|
62
|
-
_context.next = 12;
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
return _context.abrupt("return", true);
|
|
66
|
-
case 12:
|
|
67
|
-
return _context.abrupt("return", false);
|
|
66
|
+
return _context.abrupt("return", verifyLock === lockValue);
|
|
68
67
|
case 15:
|
|
69
68
|
_context.prev = 15;
|
|
70
69
|
_context.t0 = _context["catch"](2);
|
|
71
|
-
|
|
70
|
+
logger.warn('Failed to acquire lock', _context.t0);
|
|
72
71
|
return _context.abrupt("return", false);
|
|
73
72
|
case 19:
|
|
74
73
|
case "end":
|
|
@@ -84,6 +83,7 @@ export var LocalStorageAdapter = /*#__PURE__*/function () {
|
|
|
84
83
|
/**
|
|
85
84
|
* 释放分布式锁
|
|
86
85
|
*/
|
|
86
|
+
)
|
|
87
87
|
}, {
|
|
88
88
|
key: "releaseLock",
|
|
89
89
|
value: function releaseLock(deviceId) {
|
|
@@ -91,7 +91,7 @@ export var LocalStorageAdapter = /*#__PURE__*/function () {
|
|
|
91
91
|
try {
|
|
92
92
|
localStorage.removeItem(lockKey);
|
|
93
93
|
} catch (e) {
|
|
94
|
-
|
|
94
|
+
logger.warn('Failed to release lock', e);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
@@ -181,8 +181,8 @@ export var LocalStorageAdapter = /*#__PURE__*/function () {
|
|
|
181
181
|
list.push(data);
|
|
182
182
|
|
|
183
183
|
// 限制最大存储量,防止内存溢出
|
|
184
|
-
if (list.length >
|
|
185
|
-
list.splice(0, list.length -
|
|
184
|
+
if (list.length > MAX_STORAGE_EVENTS) {
|
|
185
|
+
list.splice(0, list.length - MAX_STORAGE_EVENTS);
|
|
186
186
|
}
|
|
187
187
|
localStorage.setItem(key, JSON.stringify(list));
|
|
188
188
|
case 6:
|
|
@@ -197,7 +197,7 @@ export var LocalStorageAdapter = /*#__PURE__*/function () {
|
|
|
197
197
|
case 5:
|
|
198
198
|
_context4.prev = 5;
|
|
199
199
|
_context4.t0 = _context4["catch"](0);
|
|
200
|
-
|
|
200
|
+
logger.warn('LocalStorage不可用,将使用内存缓存');
|
|
201
201
|
return _context4.abrupt("return", MemoryAdapter.getInstance().push(deviceId, data));
|
|
202
202
|
case 9:
|
|
203
203
|
case "end":
|
|
@@ -231,8 +231,8 @@ export var LocalStorageAdapter = /*#__PURE__*/function () {
|
|
|
231
231
|
list.unshift(data);
|
|
232
232
|
|
|
233
233
|
// 限制最大存储量
|
|
234
|
-
if (list.length >
|
|
235
|
-
list.splice(0, list.length -
|
|
234
|
+
if (list.length > MAX_STORAGE_EVENTS) {
|
|
235
|
+
list.splice(0, list.length - MAX_STORAGE_EVENTS);
|
|
236
236
|
}
|
|
237
237
|
localStorage.setItem(key, JSON.stringify(list));
|
|
238
238
|
case 6:
|
|
@@ -247,7 +247,7 @@ export var LocalStorageAdapter = /*#__PURE__*/function () {
|
|
|
247
247
|
case 5:
|
|
248
248
|
_context6.prev = 5;
|
|
249
249
|
_context6.t0 = _context6["catch"](0);
|
|
250
|
-
|
|
250
|
+
logger.warn('LocalStorage不可用,将使用内存缓存');
|
|
251
251
|
return _context6.abrupt("return", MemoryAdapter.getInstance().unshift(deviceId, data));
|
|
252
252
|
case 9:
|
|
253
253
|
case "end":
|
|
@@ -271,20 +271,18 @@ export var LocalStorageAdapter = /*#__PURE__*/function () {
|
|
|
271
271
|
_context8.prev = 0;
|
|
272
272
|
_context8.next = 3;
|
|
273
273
|
return this.withLock(deviceId, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
274
|
-
var key, stored, list;
|
|
274
|
+
var key, stored, list, merged;
|
|
275
275
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
276
276
|
while (1) switch (_context7.prev = _context7.next) {
|
|
277
277
|
case 0:
|
|
278
278
|
key = _this3.getStorageKey(deviceId);
|
|
279
279
|
stored = localStorage.getItem(key);
|
|
280
280
|
list = stored ? JSON.parse(stored) : [];
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
if (list.length > 10000) {
|
|
285
|
-
list.splice(0, list.length - 10000);
|
|
281
|
+
merged = data.concat(list); // 限制最大存储量
|
|
282
|
+
if (merged.length > MAX_STORAGE_EVENTS) {
|
|
283
|
+
merged.splice(0, merged.length - MAX_STORAGE_EVENTS);
|
|
286
284
|
}
|
|
287
|
-
localStorage.setItem(key, JSON.stringify(
|
|
285
|
+
localStorage.setItem(key, JSON.stringify(merged));
|
|
288
286
|
case 6:
|
|
289
287
|
case "end":
|
|
290
288
|
return _context7.stop();
|
|
@@ -297,7 +295,7 @@ export var LocalStorageAdapter = /*#__PURE__*/function () {
|
|
|
297
295
|
case 5:
|
|
298
296
|
_context8.prev = 5;
|
|
299
297
|
_context8.t0 = _context8["catch"](0);
|
|
300
|
-
|
|
298
|
+
logger.warn('LocalStorage不可用,将使用内存缓存');
|
|
301
299
|
return _context8.abrupt("return", MemoryAdapter.getInstance().unshiftBatch(deviceId, data));
|
|
302
300
|
case 9:
|
|
303
301
|
case "end":
|
|
@@ -408,13 +406,158 @@ export var LocalStorageAdapter = /*#__PURE__*/function () {
|
|
|
408
406
|
}
|
|
409
407
|
return clear;
|
|
410
408
|
}()
|
|
409
|
+
/**
|
|
410
|
+
* 按时间范围提取事件(不移除)
|
|
411
|
+
*/
|
|
412
|
+
}, {
|
|
413
|
+
key: "pullByTimeRange",
|
|
414
|
+
value: (function () {
|
|
415
|
+
var _pullByTimeRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(deviceId, startTime, endTime) {
|
|
416
|
+
var _this6 = this;
|
|
417
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
418
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
419
|
+
case 0:
|
|
420
|
+
_context14.prev = 0;
|
|
421
|
+
_context14.next = 3;
|
|
422
|
+
return this.withLock(deviceId, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
|
|
423
|
+
var key, stored, list;
|
|
424
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
425
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
426
|
+
case 0:
|
|
427
|
+
key = _this6.getStorageKey(deviceId);
|
|
428
|
+
stored = localStorage.getItem(key);
|
|
429
|
+
list = stored ? JSON.parse(stored) : [];
|
|
430
|
+
return _context13.abrupt("return", list.filter(function (event) {
|
|
431
|
+
return event.timestamp >= startTime && event.timestamp <= endTime;
|
|
432
|
+
}));
|
|
433
|
+
case 4:
|
|
434
|
+
case "end":
|
|
435
|
+
return _context13.stop();
|
|
436
|
+
}
|
|
437
|
+
}, _callee13);
|
|
438
|
+
})));
|
|
439
|
+
case 3:
|
|
440
|
+
return _context14.abrupt("return", _context14.sent);
|
|
441
|
+
case 6:
|
|
442
|
+
_context14.prev = 6;
|
|
443
|
+
_context14.t0 = _context14["catch"](0);
|
|
444
|
+
return _context14.abrupt("return", MemoryAdapter.getInstance().pullByTimeRange(deviceId, startTime, endTime));
|
|
445
|
+
case 9:
|
|
446
|
+
case "end":
|
|
447
|
+
return _context14.stop();
|
|
448
|
+
}
|
|
449
|
+
}, _callee14, this, [[0, 6]]);
|
|
450
|
+
}));
|
|
451
|
+
function pullByTimeRange(_x13, _x14, _x15) {
|
|
452
|
+
return _pullByTimeRange.apply(this, arguments);
|
|
453
|
+
}
|
|
454
|
+
return pullByTimeRange;
|
|
455
|
+
}()
|
|
456
|
+
/**
|
|
457
|
+
* 按时间范围移除事件(移除 sinceTime 及之后的所有事件)
|
|
458
|
+
*/
|
|
459
|
+
)
|
|
460
|
+
}, {
|
|
461
|
+
key: "removeByTimeRange",
|
|
462
|
+
value: (function () {
|
|
463
|
+
var _removeByTimeRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(deviceId, sinceTime) {
|
|
464
|
+
var _this7 = this;
|
|
465
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
466
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
467
|
+
case 0:
|
|
468
|
+
_context16.prev = 0;
|
|
469
|
+
_context16.next = 3;
|
|
470
|
+
return this.withLock(deviceId, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
|
|
471
|
+
var key, stored, list, remaining;
|
|
472
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
473
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
474
|
+
case 0:
|
|
475
|
+
key = _this7.getStorageKey(deviceId);
|
|
476
|
+
stored = localStorage.getItem(key);
|
|
477
|
+
list = stored ? JSON.parse(stored) : []; // 保留 sinceTime 之前的事件
|
|
478
|
+
remaining = list.filter(function (e) {
|
|
479
|
+
return e.timestamp < sinceTime;
|
|
480
|
+
});
|
|
481
|
+
if (remaining.length > 0) {
|
|
482
|
+
localStorage.setItem(key, JSON.stringify(remaining));
|
|
483
|
+
} else {
|
|
484
|
+
localStorage.removeItem(key);
|
|
485
|
+
}
|
|
486
|
+
case 5:
|
|
487
|
+
case "end":
|
|
488
|
+
return _context15.stop();
|
|
489
|
+
}
|
|
490
|
+
}, _callee15);
|
|
491
|
+
})));
|
|
492
|
+
case 3:
|
|
493
|
+
_context16.next = 8;
|
|
494
|
+
break;
|
|
495
|
+
case 5:
|
|
496
|
+
_context16.prev = 5;
|
|
497
|
+
_context16.t0 = _context16["catch"](0);
|
|
498
|
+
return _context16.abrupt("return", MemoryAdapter.getInstance().removeByTimeRange(deviceId, sinceTime));
|
|
499
|
+
case 8:
|
|
500
|
+
case "end":
|
|
501
|
+
return _context16.stop();
|
|
502
|
+
}
|
|
503
|
+
}, _callee16, this, [[0, 5]]);
|
|
504
|
+
}));
|
|
505
|
+
function removeByTimeRange(_x16, _x17) {
|
|
506
|
+
return _removeByTimeRange.apply(this, arguments);
|
|
507
|
+
}
|
|
508
|
+
return removeByTimeRange;
|
|
509
|
+
}()
|
|
510
|
+
/**
|
|
511
|
+
* 获取存储的事件数量(非破坏性只读操作)
|
|
512
|
+
*/
|
|
513
|
+
)
|
|
514
|
+
}, {
|
|
515
|
+
key: "count",
|
|
516
|
+
value: (function () {
|
|
517
|
+
var _count = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(deviceId) {
|
|
518
|
+
var _this8 = this;
|
|
519
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
520
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
521
|
+
case 0:
|
|
522
|
+
_context18.prev = 0;
|
|
523
|
+
_context18.next = 3;
|
|
524
|
+
return this.withLock(deviceId, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
|
|
525
|
+
var key, stored, list;
|
|
526
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
527
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
528
|
+
case 0:
|
|
529
|
+
key = _this8.getStorageKey(deviceId);
|
|
530
|
+
stored = localStorage.getItem(key);
|
|
531
|
+
list = stored ? JSON.parse(stored) : [];
|
|
532
|
+
return _context17.abrupt("return", list.length);
|
|
533
|
+
case 4:
|
|
534
|
+
case "end":
|
|
535
|
+
return _context17.stop();
|
|
536
|
+
}
|
|
537
|
+
}, _callee17);
|
|
538
|
+
})));
|
|
539
|
+
case 3:
|
|
540
|
+
return _context18.abrupt("return", _context18.sent);
|
|
541
|
+
case 6:
|
|
542
|
+
_context18.prev = 6;
|
|
543
|
+
_context18.t0 = _context18["catch"](0);
|
|
544
|
+
return _context18.abrupt("return", MemoryAdapter.getInstance().count(deviceId));
|
|
545
|
+
case 9:
|
|
546
|
+
case "end":
|
|
547
|
+
return _context18.stop();
|
|
548
|
+
}
|
|
549
|
+
}, _callee18, this, [[0, 6]]);
|
|
550
|
+
}));
|
|
551
|
+
function count(_x18) {
|
|
552
|
+
return _count.apply(this, arguments);
|
|
553
|
+
}
|
|
554
|
+
return count;
|
|
555
|
+
}())
|
|
411
556
|
}]);
|
|
412
557
|
return LocalStorageAdapter;
|
|
413
558
|
}();
|
|
414
|
-
_defineProperty(LocalStorageAdapter, "LOCK_KEY_PREFIX",
|
|
415
|
-
_defineProperty(LocalStorageAdapter, "STORAGE_KEY_PREFIX",
|
|
416
|
-
_defineProperty(LocalStorageAdapter, "LOCK_TIMEOUT",
|
|
417
|
-
|
|
418
|
-
_defineProperty(LocalStorageAdapter, "
|
|
419
|
-
// 10ms重试间隔
|
|
420
|
-
_defineProperty(LocalStorageAdapter, "MAX_RETRIES", 50);
|
|
559
|
+
_defineProperty(LocalStorageAdapter, "LOCK_KEY_PREFIX", STORAGE_KEY_LOCK_PREFIX);
|
|
560
|
+
_defineProperty(LocalStorageAdapter, "STORAGE_KEY_PREFIX", STORAGE_KEY_DATA_PREFIX);
|
|
561
|
+
_defineProperty(LocalStorageAdapter, "LOCK_TIMEOUT", LOCK_TIMEOUT);
|
|
562
|
+
_defineProperty(LocalStorageAdapter, "RETRY_DELAY", LOCK_RETRY_DELAY);
|
|
563
|
+
_defineProperty(LocalStorageAdapter, "MAX_RETRIES", LOCK_MAX_RETRIES);
|