UNPKG

idb-logger

Version:

A high-performance, high-capacity, and highly scalable web-side logging system based on WebWorker and indexedDB

2 lines (1 loc) 46.8 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).IDBLogger=e()}(this,function(){"use strict";function E(){E=function(){return a};var a={},t=Object.prototype,c=t.hasOwnProperty,s=Object.defineProperty||function(t,e,n){t[e]=n.value},e="function"==typeof Symbol?Symbol:{},r=e.iterator||"@@iterator",n=e.asyncIterator||"@@asyncIterator",o=e.toStringTag||"@@toStringTag";function i(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{i({},"")}catch(t){i=function(t,e,n){return t[e]=n}}function u(t,e,n,r){var o,i,a,u,e=e&&e.prototype instanceof d?e:d,e=Object.create(e.prototype),r=new _(r||[]);return s(e,"_invoke",{value:(o=t,i=n,a=r,u="suspendedStart",function(t,e){if("executing"===u)throw new Error("Generator is already running");if("completed"===u){if("throw"===t)throw e;return x()}for(a.method=t,a.arg=e;;){var n=a.delegate;if(n){n=function t(e,n){var r=n.method,o=e.iterator[r];if(void 0===o)return n.delegate=null,"throw"===r&&e.iterator.return&&(n.method="return",n.arg=void 0,t(e,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),l;r=f(o,e.iterator,n.arg);if("throw"===r.type)return n.method="throw",n.arg=r.arg,n.delegate=null,l;o=r.arg;return o?o.done?(n[e.resultName]=o.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=void 0),n.delegate=null,l):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,l)}(n,a);if(n){if(n===l)continue;return n}}if("next"===a.method)a.sent=a._sent=a.arg;else if("throw"===a.method){if("suspendedStart"===u)throw u="completed",a.arg;a.dispatchException(a.arg)}else"return"===a.method&&a.abrupt("return",a.arg);u="executing";n=f(o,i,a);if("normal"===n.type){if(u=a.done?"completed":"suspendedYield",n.arg===l)continue;return{value:n.arg,done:a.done}}"throw"===n.type&&(u="completed",a.method="throw",a.arg=n.arg)}})}),e}function f(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}a.wrap=u;var l={};function d(){}function h(){}function v(){}var e={},y=(i(e,r,function(){return this}),Object.getPrototypeOf),y=y&&y(y(k([]))),p=(y&&y!==t&&c.call(y,r)&&(e=y),v.prototype=d.prototype=Object.create(e));function g(t){["next","throw","return"].forEach(function(e){i(t,e,function(t){return this._invoke(e,t)})})}function m(a,u){var e;s(this,"_invoke",{value:function(n,r){function t(){return new u(function(t,e){!function e(t,n,r,o){var i,t=f(a[t],a,n);if("throw"!==t.type)return(n=(i=t.arg).value)&&"object"==typeof n&&c.call(n,"__await")?u.resolve(n.__await).then(function(t){e("next",t,r,o)},function(t){e("throw",t,r,o)}):u.resolve(n).then(function(t){i.value=t,r(i)},function(t){return e("throw",t,r,o)});o(t.arg)}(n,r,t,e)})}return e=e?e.then(t,t):t()}})}function w(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 b(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(w,this),this.reset(!0)}function k(e){if(e){var n,t=e[r];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return n=-1,(t=function t(){for(;++n<e.length;)if(c.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t}).next=t}return{next:x}}function x(){return{value:void 0,done:!0}}return s(p,"constructor",{value:h.prototype=v,configurable:!0}),s(v,"constructor",{value:h,configurable:!0}),h.displayName=i(v,o,"GeneratorFunction"),a.isGeneratorFunction=function(t){t="function"==typeof t&&t.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},a.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,i(t,o,"GeneratorFunction")),t.prototype=Object.create(p),t},a.awrap=function(t){return{__await:t}},g(m.prototype),i(m.prototype,n,function(){return this}),a.AsyncIterator=m,a.async=function(t,e,n,r,o){void 0===o&&(o=Promise);var i=new m(u(t,e,n,r),o);return a.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},g(p),i(p,o,"Generator"),i(p,r,function(){return this}),i(p,"toString",function(){return"[object Generator]"}),a.keys=function(t){var e,n=Object(t),r=[];for(e in n)r.push(e);return r.reverse(),function t(){for(;r.length;){var e=r.pop();if(e in n)return t.value=e,t.done=!1,t}return t.done=!0,t}},a.values=k,_.prototype={constructor:_,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(b),!t)for(var e in this)"t"===e.charAt(0)&&c.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(n){if(this.done)throw n;var r=this;function t(t,e){return i.type="throw",i.arg=n,r.next=t,e&&(r.method="next",r.arg=void 0),!!e}for(var e=this.tryEntries.length-1;0<=e;--e){var o=this.tryEntries[e],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var a=c.call(o,"catchLoc"),u=c.call(o,"finallyLoc");if(a&&u){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;0<=n;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&c.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var o=r;break}}var i=(o=o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc?null:o)?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,l):this.complete(i)},complete:function(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),l},finish:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),b(n),l}},catch:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var n,r,o=this.tryEntries[e];if(o.tryLoc===t)return"throw"===(n=o.completion).type&&(r=n.arg,b(o)),r}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:k(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),l}},a}function f(t){return(f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,function(t){t=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0===n)return("string"===e?String:Number)(t);n=n.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}(t,"string");return"symbol"==typeof t?t:String(t)}(r.key),r)}}function t(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function e(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&n(t,e)}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function n(t,e){return(n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function i(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");e=t;if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function a(n){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}();return function(){var t,e=o(n);return i(this,r?(t=o(this).constructor,Reflect.construct(e,arguments,t)):e.apply(this,arguments))}}function u(t){return function(t){if(Array.isArray(t))return l(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||c(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(t,e){var n;if(t)return"string"==typeof t?l(t,e):"Map"===(n="Object"===(n=Object.prototype.toString.call(t).slice(8,-1))&&t.constructor?t.constructor.name:n)||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?l(t,e):void 0}function l(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function d(t,e){var n,r,o,i,a="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(a)return r=!(n=!0),{s:function(){a=a.call(t)},n:function(){var t=a.next();return n=t.done,t},e:function(t){r=!0,o=t},f:function(){try{n||null==a.return||a.return()}finally{if(r)throw o}}};if(Array.isArray(t)||(a=c(t))||e&&t&&"number"==typeof t.length)return a&&(t=a),i=0,{s:e=function(){},n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:e};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function h(t,a,u,c){return new(u=u||Promise)(function(n,e){function r(t){try{i(c.next(t))}catch(t){e(t)}}function o(t){try{i(c.throw(t))}catch(t){e(t)}}function i(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(r,o)}i((c=c.apply(t,a||[])).next())})}function v(){for(var t=[],e="0123456789abcdef",n=0;n<36;n++)t[n]=e.substr(Math.floor(16*Math.random()),1);return t[14]="4",t[19]=e.substr(3&t[19]|8,1),t[8]="-",t[13]="-",t[18]="-",t[23]="-",t.join("")}function y(t,e){var e=1<arguments.length&&void 0!==e?e:":",n="".concat(t.getFullYear(),"-").concat(p(t.getMonth()+1),"-").concat(p(t.getDate())),r=t.getMilliseconds(),r=r<100?"0".concat(p(r)):r;return"".concat(n," ").concat(p(t.getHours())).concat(e).concat(p(t.getMinutes())).concat(e).concat(p(t.getSeconds())).concat(e).concat(r)}function p(t){return t<10?"0".concat(t):t}function g(t){t=new window.Blob([t],{type:"text/javascript"});return window.URL.createObjectURL(t)}var m=["type","msg","payload","uid","traceid","logid","duration","network","url","ua"];function w(n,t){function e(t){var e=n[t];void 0!==e&&""!==e&&(i+=" ".concat(t,"=").concat("object"===f(t=e)?JSON.stringify(t):t.toString(),";"))}var r,o=1<arguments.length&&void 0!==t?t:[],i="[".concat(n.time,"]"),a=d(o);try{for(a.s();!(r=a.n()).done;)e(r.value)}catch(t){a.e(t)}finally{a.f()}var u,c=d(m);try{for(c.s();!(u=c.n()).done;){var s=u.value;o.includes(s)||e(s)}}catch(t){c.e(t)}finally{c.f()}return i}var b="[TCLogger]:";function _(t,e){var n=t[0];"string"==typeof n?t[0]=b+n:t.unshift(b),(n=console)[e].apply(n,u(t))}var k,x={log:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];_(e,"log")},warn:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];_(e,"warn")},info:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];_(e,"info")},error:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];_(e,"error")}},S=function(){function r(t){var e=t.id,n=t.useConsole,t=t.maxRecords;s(this,r),this.data={clientid:"",uid:"",traceid:"",network:"",url:"",ua:""},this.config={useConsole:!0,maxRecords:-1},this.injectConfig({useConsole:n,maxRecords:t}),this.name="".concat(r.DEFAULT_DB_NAME_PREFIX,"_").concat(e),this.refreshTraceId()}return t(r,[{key:"refreshTraceId",value:function(){this.data.traceid=v(),this.refreshDurationStart()}},{key:"refreshDurationStart",value:function(){this.durationStart=Date.now()}},{key:"injectBaseInfo",value:function(t){Object.assign(this.data,t)}},{key:"injectConfig",value:function(t){Object.assign(this.config,t)}},{key:"appendBaseInfo",value:function(t){var e=new Date,n=e.getTime(),e=y(e),r=n-this.durationStart,o=t.extend||{},t=(delete t.extend,Object.assign(t,this.data,{timestamp:n,time:e,logid:v(),duration:r},o));return this.config.useConsole&&(n=w(t),(x[t.type]||console.log)(n)),t}}]),r}(),R=(S.DEFAULT_DB_NAME_PREFIX="tc_logger",t(function t(e){s(this,t),this.type="idb"})),j=function(){e(r,R);var n=a(r);function r(t){var e;return s(this,r),(e=n.call(this,t)).baseInfo=new S(t),e}return t(r,[{key:"name",get:function(){return this.baseInfo.name}},{key:"injectBaseInfo",value:function(t){return this.baseInfo.injectBaseInfo(t),Promise.resolve()}},{key:"refreshTraceId",value:function(){return this.baseInfo.refreshTraceId(),Promise.resolve()}},{key:"refreshDurationStart",value:function(){return this.baseInfo.refreshDurationStart(),Promise.resolve()}}]),r}(),O='var module = {}; !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).IDBLogger=e()}(this,function(){"use strict";function R(){R=function(){return a};var a={},t=Object.prototype,u=t.hasOwnProperty,s=Object.defineProperty||function(t,e,n){t[e]=n.value},e="function"==typeof Symbol?Symbol:{},r=e.iterator||"@@iterator",n=e.asyncIterator||"@@asyncIterator",o=e.toStringTag||"@@toStringTag";function i(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{i({},"")}catch(t){i=function(t,e,n){return t[e]=n}}function c(t,e,n,r){var o,i,a,c,e=e&&e.prototype instanceof d?e:d,e=Object.create(e.prototype),r=new _(r||[]);return s(e,"_invoke",{value:(o=t,i=n,a=r,c="suspendedStart",function(t,e){if("executing"===c)throw new Error("Generator is already running");if("completed"===c){if("throw"===t)throw e;return k()}for(a.method=t,a.arg=e;;){var n=a.delegate;if(n){n=function t(e,n){var r=n.method,o=e.iterator[r];if(void 0===o)return n.delegate=null,"throw"===r&&e.iterator.return&&(n.method="return",n.arg=void 0,t(e,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a \'"+r+"\' method")),l;r=f(o,e.iterator,n.arg);if("throw"===r.type)return n.method="throw",n.arg=r.arg,n.delegate=null,l;o=r.arg;return o?o.done?(n[e.resultName]=o.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=void 0),n.delegate=null,l):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,l)}(n,a);if(n){if(n===l)continue;return n}}if("next"===a.method)a.sent=a._sent=a.arg;else if("throw"===a.method){if("suspendedStart"===c)throw c="completed",a.arg;a.dispatchException(a.arg)}else"return"===a.method&&a.abrupt("return",a.arg);c="executing";n=f(o,i,a);if("normal"===n.type){if(c=a.done?"completed":"suspendedYield",n.arg===l)continue;return{value:n.arg,done:a.done}}"throw"===n.type&&(c="completed",a.method="throw",a.arg=n.arg)}})}),e}function f(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}a.wrap=c;var l={};function d(){}function h(){}function v(){}var e={},y=(i(e,r,function(){return this}),Object.getPrototypeOf),y=y&&y(y(E([]))),p=(y&&y!==t&&u.call(y,r)&&(e=y),v.prototype=d.prototype=Object.create(e));function g(t){["next","throw","return"].forEach(function(e){i(t,e,function(t){return this._invoke(e,t)})})}function m(a,c){var e;s(this,"_invoke",{value:function(n,r){function t(){return new c(function(t,e){!function e(t,n,r,o){var i,t=f(a[t],a,n);if("throw"!==t.type)return(n=(i=t.arg).value)&&"object"==typeof n&&u.call(n,"__await")?c.resolve(n.__await).then(function(t){e("next",t,r,o)},function(t){e("throw",t,r,o)}):c.resolve(n).then(function(t){i.value=t,r(i)},function(t){return e("throw",t,r,o)});o(t.arg)}(n,r,t,e)})}return e=e?e.then(t,t):t()}})}function b(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 w(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function E(e){if(e){var n,t=e[r];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return n=-1,(t=function t(){for(;++n<e.length;)if(u.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t}).next=t}return{next:k}}function k(){return{value:void 0,done:!0}}return s(p,"constructor",{value:h.prototype=v,configurable:!0}),s(v,"constructor",{value:h,configurable:!0}),h.displayName=i(v,o,"GeneratorFunction"),a.isGeneratorFunction=function(t){t="function"==typeof t&&t.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},a.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,i(t,o,"GeneratorFunction")),t.prototype=Object.create(p),t},a.awrap=function(t){return{__await:t}},g(m.prototype),i(m.prototype,n,function(){return this}),a.AsyncIterator=m,a.async=function(t,e,n,r,o){void 0===o&&(o=Promise);var i=new m(c(t,e,n,r),o);return a.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},g(p),i(p,o,"Generator"),i(p,r,function(){return this}),i(p,"toString",function(){return"[object Generator]"}),a.keys=function(t){var e,n=Object(t),r=[];for(e in n)r.push(e);return r.reverse(),function t(){for(;r.length;){var e=r.pop();if(e in n)return t.value=e,t.done=!1,t}return t.done=!0,t}},a.values=E,_.prototype={constructor:_,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(w),!t)for(var e in this)"t"===e.charAt(0)&&u.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(n){if(this.done)throw n;var r=this;function t(t,e){return i.type="throw",i.arg=n,r.next=t,e&&(r.method="next",r.arg=void 0),!!e}for(var e=this.tryEntries.length-1;0<=e;--e){var o=this.tryEntries[e],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var a=u.call(o,"catchLoc"),c=u.call(o,"finallyLoc");if(a&&c){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;0<=n;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&u.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var o=r;break}}var i=(o=o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc?null:o)?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,l):this.complete(i)},complete:function(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),l},finish:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),w(n),l}},catch:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var n,r,o=this.tryEntries[e];if(o.tryLoc===t)return"throw"===(n=o.completion).type&&(r=n.arg,w(o)),r}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:E(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),l}},a}function f(t){return(f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,function(t){t=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0===n)return("string"===e?String:Number)(t);n=n.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}(t,"string");return"symbol"==typeof t?t:String(t)}(r.key),r)}}function t(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function e(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&n(t,e)}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function n(t,e){return(n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function a(t){if(void 0===t)throw new ReferenceError("this hasn\'t been initialised - super() hasn\'t been called");return t}function c(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return a(t)}function u(n){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}();return function(){var t,e=o(n);return c(this,r?(t=o(this).constructor,Reflect.construct(e,arguments,t)):e.apply(this,arguments))}}function s(t){return function(t){if(Array.isArray(t))return d(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||l(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.In order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(t,e){var n;if(t)return"string"==typeof t?d(t,e):"Map"===(n="Object"===(n=Object.prototype.toString.call(t).slice(8,-1))&&t.constructor?t.constructor.name:n)||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(t,e):void 0}function d(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function h(t,e){var n,r,o,i,a="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(a)return r=!(n=!0),{s:function(){a=a.call(t)},n:function(){var t=a.next();return n=t.done,t},e:function(t){r=!0,o=t},f:function(){try{n||null==a.return||a.return()}finally{if(r)throw o}}};if(Array.isArray(t)||(a=l(t))||e&&t&&"number"==typeof t.length)return a&&(t=a),i=0,{s:e=function(){},n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:e};throw new TypeError("Invalid attempt to iterate non-iterable instance.In order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function v(t,a,c,u){return new(c=c||Promise)(function(n,e){function r(t){try{i(u.next(t))}catch(t){e(t)}}function o(t){try{i(u.throw(t))}catch(t){e(t)}}function i(t){var e;t.done?n(t.value):((e=t.value)instanceof c?e:new c(function(t){t(e)})).then(r,o)}i((u=u.apply(t,a||[])).next())})}var y="[TCLogger]:";function p(t,e){var n=t[0];"string"==typeof n?t[0]=y+n:t.unshift(y),(n=console)[e].apply(n,s(t))}var g={log:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];p(e,"log")},warn:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];p(e,"warn")},info:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];p(e,"info")},error:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];p(e,"error")}};function m(){for(var t=[],e="0123456789abcdef",n=0;n<36;n++)t[n]=e.substr(Math.floor(16*Math.random()),1);return t[14]="4",t[19]=e.substr(3&t[19]|8,1),t[8]="-",t[13]="-",t[18]="-",t[23]="-",t.join("")}function b(t){return t<10?"0".concat(t):t}var w=["type","msg","payload","uid","traceid","logid","duration","network","url","ua"];function _(n,t){function e(t){var e=n[t];void 0!==e&&""!==e&&(i+=" ".concat(t,"=").concat("object"===f(t=e)?JSON.stringify(t):t.toString(),";"))}var r,o=1<arguments.length&&void 0!==t?t:[],i="[".concat(n.time,"]"),a=h(o);try{for(a.s();!(r=a.n()).done;)e(r.value)}catch(t){a.e(t)}finally{a.f()}var c,u=h(w);try{for(u.s();!(c=u.n()).done;){var s=c.value;o.includes(s)||e(s)}}catch(t){u.e(t)}finally{u.f()}return i}var E=function(){function r(t){var e=t.id,n=t.useConsole,t=t.maxRecords;i(this,r),this.data={clientid:"",uid:"",traceid:"",network:"",url:"",ua:""},this.config={useConsole:!0,maxRecords:-1},this.injectConfig({useConsole:n,maxRecords:t}),this.name="".concat(r.DEFAULT_DB_NAME_PREFIX,"_").concat(e),this.refreshTraceId()}return t(r,[{key:"refreshTraceId",value:function(){this.data.traceid=m(),this.refreshDurationStart()}},{key:"refreshDurationStart",value:function(){this.durationStart=Date.now()}},{key:"injectBaseInfo",value:function(t){Object.assign(this.data,t)}},{key:"injectConfig",value:function(t){Object.assign(this.config,t)}},{key:"appendBaseInfo",value:function(t){var e=new Date,n=e.getTime(),e=function(t,e){var e=1<arguments.length&&void 0!==e?e:":",n="".concat(t.getFullYear(),"-").concat(b(t.getMonth()+1),"-").concat(b(t.getDate())),r=(r=t.getMilliseconds())<100?"0".concat(b(r)):r;return"".concat(n," ").concat(b(t.getHours())).concat(e).concat(b(t.getMinutes())).concat(e).concat(b(t.getSeconds())).concat(e).concat(r)}(e),r=n-this.durationStart,o=t.extend||{},t=(delete t.extend,Object.assign(t,this.data,{timestamp:n,time:e,logid:m(),duration:r},o));return this.config.useConsole&&(n=_(t),(g[t.type]||console.log)(n)),t}}]),r}(),k=(E.DEFAULT_DB_NAME_PREFIX="tc_logger",t(function t(e){i(this,t),this.type="idb"})),x=function(){e(r,k);var n=u(r);function r(t){var e;return i(this,r),(e=n.call(this,t)).baseInfo=new E(t),e}return t(r,[{key:"name",get:function(){return this.baseInfo.name}},{key:"injectBaseInfo",value:function(t){return this.baseInfo.injectBaseInfo(t),Promise.resolve()}},{key:"refreshTraceId",value:function(){return this.baseInfo.refreshTraceId(),Promise.resolve()}},{key:"refreshDurationStart",value:function(){return this.baseInfo.refreshDurationStart(),Promise.resolve()}}]),r}();function S(t,e){if("function"==typeof e)return e(t);if("object"!==f(t))return e instanceof RegExp?e.test(t):t===e;if("Object"!==t.constructor.name)return t.toString()===e.toString();if(!(e instanceof Array)){for(var n in e)if(!S(t[n],e[n]))return;return 1}for(var r=0;r<e.length;r++)if(S(t,e[r]))return 1}var O={transFunc:function(t){return"function"==typeof t?"/*fn*/"+t.toString():t},transBack:function(t){return"string"==typeof t?new Function("return (".concat(t,")"))():t},isFuncString:function(t){return 0===t.indexOf("/*fn*/")}},j="logid",D={};var L=function(){e(o,x);var r=u(o);function o(){var t,e,n=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"default";return i(this,o),(t=r.call(this,{id:n,useConsole:!0,maxRecords:0})).STORE_NAME="records",t.loadCallbacks=[],t.recordsChecking=!1,t.continueChecking=!1,t.discardResolveList=[],t.id=n,D[t.name]?c(t,D[t.name]):(t.db||t._initDB(),D[t.name]=a(t),t.msgMap=(e=a(t),{add:function(t){return e.add(t)},injectConfig:function(t){return e.baseInfo.injectConfig(t)},closeDB:function(){return e.close()},destory:function(){return e.destory()},refreshTraceId:function(){return e.refreshTraceId()},injectBaseInfo:function(t){return e.baseInfo.injectBaseInfo(t)},get:function(t){return e.get(t)},getAll:function(){return e.getAll()},refreshDurationStart:function(){return e.refreshDurationStart()},filter:function(t){return e.filter(t)},download:function(t){return e.download(t)},count:function(){return e.count()},delete:function(t){return e.delete(t)},clear:function(){return e.clear()}}),t)}return t(o,[{key:"resolveDiscard",value:function(t){var e;null!=(e=this.discardResolveList.shift())&&e(t)}},{key:"batchResolveDiscardNull",value:function(t){"number"==typeof t?this.discardResolveList.splice(0,this.discardResolveList.length-t).forEach(function(t){t(null)}):(this.discardResolveList.forEach(function(t){t(null)}),this.discardResolveList=[])}},{key:"add",value:function(o){var t=this;return new Promise(function(r){return v(t,void 0,void 0,R().mark(function t(){var e,n=this;return R().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(o){t.next=3;break}return g.warn("add: data is required"),t.abrupt("return",null);case 3:e=this.baseInfo.appendBaseInfo(o),this.db?t.next=8:(this.loadCallbacks.push(function(){return v(n,void 0,void 0,R().mark(function t(){return R().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=r,t.next=3,this._addDBData(e);case 3:t.t1=t.sent,(0,t.t0)(t.t1);case 5:case"end":return t.stop()}},t,this)}))}),t.next=13);break;case 8:return t.t0=r,t.next=11,this._addDBData(e);case 11:t.t1=t.sent,(0,t.t0)(t.t1);case 13:case"end":return t.stop()}},t,this)}))})}},{key:"_addDBData",value:function(o){var t=this;return new Promise(function(r){return v(t,void 0,void 0,R().mark(function t(){var e,n=this;return R().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:(e=this._getStore("readwrite").add(o)).onsuccess=function(){return v(n,void 0,void 0,R().mark(function t(){return R().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:this._checkMaxRecords(),this.discardResolveList.push(function(t){r({discard:t,add:o})});case 2:case"end":return t.stop()}},t,this)}))},e.onerror=function(t){n._sendError("ADD_LOG_ERROR",t),g.error("数据写入失败",t),r(null)};case 3:case"end":return t.stop()}},t,this)}))})}},{key:"_getStore",value:function(){return this.db.transaction([this.STORE_NAME],0<arguments.length&&void 0!==arguments[0]?arguments[0]:"readonly").objectStore(this.STORE_NAME)}},{key:"clear",value:function(){var n=this;return new Promise(function(e){var t=n._getStore("readwrite").clear();t.onsuccess=function(){g.log("清除数据成功"),e(!0)},t.onerror=function(t){n._sendError("CLEAR_ERROR",t),g.warn("清除数据失败"),e(!1)}})}},{key:"close",value:function(){return this.db.close(),this.db=void 0,delete D[this.name],Promise.resolve(!0)}},{key:"destory",value:function(){var n=this;return new Promise(function(e){n.close();var t=globalThis.indexedDB.deleteDatabase(n.baseInfo.name);t.onsuccess=function(){g.info("数据库已销毁"),e(!0)},t.onerror=function(t){n._sendError("DESTORY_ERROR",t),g.warn("数据库销毁失败:",t),e(!1)}})}},{key:"get",value:function(n){var r=this;return new Promise(function(e){var t=r._getStore("readonly").index(j).get(n);t.onerror=function(t){r._sendError("GET_ERROR",t),g.error("数据查询失败",n),e(null)},t.onsuccess=function(){t.result?e(t.result):(g.warn("未查询到记录",n),e(null))}})}},{key:"getAll",value:function(){var n=this;return new Promise(function(t){var e=[];n._cursorBase({onvalue:function(t){e.push(t)},onend:function(){t(e)},onerror:function(){t([])}})})}},{key:"download",value:function(t){var r=this,o=t.filter,t=t.keys,i=void 0===t?[]:t,o=O.transBack(o);return new Promise(function(t){var e="",n=0;r._cursorBase({onvalue:function(t){S(t,o)&&(n++,e+="".concat(_(t,i),"\\n"))},onend:function(){t({content:e,count:n})},onerror:function(){t({content:e,count:n})}})})}},{key:"filter",value:function(n){var r=this;return n=O.transBack(n),new Promise(function(t){var e=[];r._cursorBase({onvalue:function(t){S(t,n)&&e.push(t)},onend:function(){t(e)},onerror:function(){t([])}})})}},{key:"count",value:function(){var n=this;return new Promise(function(e){var t=n._getStore().index(j).count();t.onsuccess=function(){e(t.result)},t.onerror=function(t){n._sendError("COUNT_ERROR",t),g.warn("count error",t),e(-1)}})}},{key:"_getKey",value:function(o){var t=this;return new Promise(function(r){return v(t,void 0,void 0,R().mark(function t(){var e,n=this;return R().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:e=this._getStore("readonly"),(e=e.index(j).getKey(o)).onsuccess=function(t){r((null==(t=null==t?void 0:t.target)?void 0:t.result)||-1)},e.onerror=function(t){n._sendError("GET_KEY_ERROR",t),g.warn("getKey error",t),r(-1)};case 4:case"end":return t.stop()}},t,this)}))})}},{key:"delete",value:function(i){var t=this;return new Promise(function(o){return v(t,void 0,void 0,R().mark(function t(){var e,n,r=this;return R().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._getKey(i);case 2:if(-1===(e=t.sent))return g.warn("删除失败, 记录不存在:",i),o(!1),t.abrupt("return");t.next=7;break;case 7:n=this._getStore("readwrite"),(n=n.delete(e)).onsuccess=function(){o(!0)},n.onerror=function(t){r._sendError("DELETE_ERROR",t),g.warn("删除日志失败",t),o(!1)};case 11:case"end":return t.stop()}},t,this)}))})}},{key:"_sendError",value:function(t){I({id:this.id,msgid:"",type:"error",result:{message:t,error:1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,code:2<arguments.length&&void 0!==arguments[2]?arguments[2]:-1}})}},{key:"_removeTop",value:function(){var n=this,r=0<arguments.length&&void 0!==arguments[0]?arguments[0]:1,o=this._getStore("readwrite"),t=o.openKeyCursor();t.onsuccess=function(t){var e=(null==t?void 0:t.target).result;e?(o.get(e.primaryKey).onsuccess=function(t){t=t.target.result;n.resolveDiscard(t)},o.delete(e.primaryKey).onerror=function(t){n._sendError("DISCARD_ERROR",t),g.warn("移除最早记录错误",t)},1<r&&(e.continue(),r--)):(n._sendError("DISCARD_NOT_FOUND",null),g.warn("移除最早记录失败, cursor = null",t))},t.onerror=function(t){n._sendError("DISCARD_OPEN_CURSOR_ERROR",t),g.warn("移除最早记录失败",t)}}},{key:"_checkMaxRecords",value:function(){return v(this,void 0,void 0,R().mark(function t(){var e;return R().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.recordsChecking)return this.continueChecking=!0,t.abrupt("return");t.next=3;break;case 3:return this.continueChecking=!1,this.recordsChecking=!0,t.next=7,this.count();case 7:e=t.sent,0<(e=e-this.baseInfo.config.maxRecords)?(this._removeTop(e),this.batchResolveDiscardNull(e)):this.batchResolveDiscardNull(),this.recordsChecking=!1,this.continueChecking&&this._checkMaxRecords();case 12:case"end":return t.stop()}},t,this)}))}},{key:"_cursorBase",value:function(t){var e=this,n=t.onend,r=t.onvalue,o=t.onerror,t=this._getStore().openCursor();t.onsuccess=function(t){t=(null==t?void 0:t.target).result;t?(r(t.value),t.continue()):n()},t.onerror=function(t){e._sendError("QUERY_ERROR",t),g.error("查询失败"),o()}}},{key:"_initDB",value:function(){var e=this,t=globalThis.indexedDB.open(this.name,1);t.onerror=function(t){e._sendError("INIT_DB_ERROR",t),g.error("数据库打开失败",t)},t.onsuccess=function(){e.db=t.result,e.loadCallbacks.forEach(function(t){return t()})},t.onupgradeneeded=function(t){t=null==(t=t.target)?void 0:t.result;e._checkCreateStore(t,e.STORE_NAME)}}},{key:"_checkCreateStore",value:function(t,e){t.objectStoreNames.contains(e)||t.createObjectStore(e,{autoIncrement:!0}).createIndex(j,j,{unique:!0})}}]),o}();function I(t){globalThis.postMessage(t)}globalThis.addEventListener("message",function(a){return v(this,void 0,void 0,R().mark(function t(){var e,n,r,o,i;return R().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(o=a.data,e=o.msgid,n=o.type,r=o.data,o=o.id,i=new L(o=void 0===o?"":o),(i=i.msgMap[n](r))instanceof Promise)return t.next=6,i;t.next=7;break;case 6:i=t.sent;case 7:I({msgid:e,id:o,type:n,result:i});case 8:case"end":return t.stop()}},t)}))},!1);return""});\n',I={transFunc:function(t){return"function"==typeof t?"/*fn*/"+t.toString():t},transBack:function(t){return"string"==typeof t?new Function("return (".concat(t,")"))():t},isFuncString:function(t){return 0===t.indexOf("/*fn*/")}},L=0,D=("undefined"!=typeof window&&window.Worker&&(k=new window.Worker(g(O))),function(){e(c,R);var u=a(c);function c(t){var e,n=t.id,r=t.useConsole,o=t.maxRecords,i=t.onReport,a=t.onDiscard,t=t.onError;return s(this,c),(e=u.call(this,{id:n,useConsole:r,maxRecords:o})).resolveMap={},e.onDiscard=a,e.onReport=i,e.onError=t,e.id=n,(k=k||new window.Worker(g(O))).onmessage=function(t){t=t.data;t.id===n&&e._onMessage(t)},e._postMessage("injectConfig",{useConsole:r,maxRecords:o}),e}return t(c,[{key:"_onMessage",value:function(t){var e;"add"===t.type?(e=t.result)&&(this.onReport&&this.onReport(e.add),e.discard)&&this.onDiscard&&this.onDiscard(e.discard):"error"===t.type&&this.onError&&this.onError(t.result),t.msgid&&(e=this.resolveMap[t.msgid])&&(e(t),delete this.resolveMap[t.msgid])}},{key:"injectBaseInfo",value:function(t){return this._postMessage("injectBaseInfo",t)}},{key:"add",value:function(e){return h(this,void 0,void 0,E().mark(function t(){return E().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._postMessage("add",this._transformPayload(e));case 2:return t.abrupt("return",t.sent.result);case 3:case"end":return t.stop()}},t,this)}))}},{key:"close",value:function(){return this._postMessage("closeDB")}},{key:"destory",value:function(){return this._postMessage("destory")}},{key:"count",value:function(){return h(this,void 0,void 0,E().mark(function t(){return E().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._postMessage("count");case 2:return t.abrupt("return",t.sent.result);case 3:case"end":return t.stop()}},t,this)}))}},{key:"clear",value:function(){return this._postMessage("clear")}},{key:"delete",value:function(t){return this._postMessage("delete",t)}},{key:"refreshTraceId",value:function(){return this._postMessage("refreshTraceId")}},{key:"refreshDurationStart",value:function(){return this._postMessage("refreshDurationStart")}},{key:"get",value:function(e){return h(this,void 0,void 0,E().mark(function t(){return E().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._postMessage("get",e);case 2:return t.abrupt("return",t.sent.result);case 3:case"end":return t.stop()}},t,this)}))}},{key:"getAll",value:function(){return h(this,void 0,void 0,E().mark(function t(){return E().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._postMessage("getAll");case 2:return t.abrupt("return",t.sent.result);case 3:case"end":return t.stop()}},t,this)}))}},{key:"download",value:function(t){var e=t.filter,n=t.keys;return h(this,void 0,void 0,E().mark(function t(){return E().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._postMessage("download",{filter:I.transFunc(e),keys:n});case 2:return t.abrupt("return",t.sent.result);case 3:case"end":return t.stop()}},t,this)}))}},{key:"filter",value:function(e){return h(this,void 0,void 0,E().mark(function t(){return E().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._postMessage("filter",I.transFunc(e));case 2:return t.abrupt("return",t.sent.result);case 3:case"end":return t.stop()}},t,this)}))}},{key:"_postMessage",value:function(n){var r=this,o=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null;return new Promise(function(t){var e={msgid:L++,type:n,id:r.id,data:o};r.resolveMap[e.msgid]=t,k.postMessage(e)})}},{key:"_transformPayload",value:function(t){return t.payload instanceof window.HTMLElement&&(t.payload=function(t){for(var e=t.attributes,n="",r=0;r<e.length;r++){var o=e[r];n+=" ".concat(o.name,'="').concat(o.value,'"')}return"<".concat(t.tagName.toLowerCase()).concat(n,"/>")}(t.payload)),t}}]),c}());function P(t,e){if("function"==typeof e)return e(t);if("object"!==f(t))return e instanceof RegExp?e.test(t):t===e;if("Object"!==t.constructor.name)return t.toString()===e.toString();if(e instanceof Array){for(var n=0;n<e.length;n++)if(P(t,e[n]))return!0;return!1}for(var r in e)if(!P(t[r],e[r]))return!1;return!0}var T=function(){e(r,j);var n=a(r);function r(t){var e;return s(this,r),(e=n.call(this,t)).data=[],e.key="".concat(S.DEFAULT_DB_NAME_PREFIX,"_").concat(t.id),e.onDiscard=t.onDiscard,e.onReport=t.onReport,e.onError=t.onError,e._initStoreType(t.storeType),e.data=e._getAll(),e}return t(r,[{key:"useStorage",get:function(){return"storage"===this.type}},{key:"useTemp",get:function(){return"temp"===this.type}},{key:"noStore",get:function(){return"none"===this.type}},{key:"_initStoreType",value:function(t){window.localStorage||"storage"!==t||(t="temp"),this.type=t}},{key:"_getAll",value:function(){return this.useStorage?JSON.parse(localStorage.getItem(this.key)||"[]"):[]}},{key:"_saveAll",value:function(){if(this.useStorage)try{localStorage.setItem(this.key,JSON.stringify(this.data))}catch(t){x.warn("localStorage 存储失败",t)}}},{key:"add",value:function(t){var e,n,t=this.baseInfo.appendBaseInfo(t),r=null;return(this.useTemp||this.useStorage)&&(e=this.baseInfo.config.maxRecords,this.data.length>=e&&(n=this.data.shift())&&(r=n,this.onDiscard&&this.onDiscard(t),x.warn("达到最大存储数量:".concat(e,"; 已丢弃最早的记录:"),n)),this.onReport&&this.onReport(t),this.data.push(t),this._saveAll()),Promise.resolve({discard:r,add:t})}},{key:"close",value:function(){return Promise.resolve(!0)}},{key:"destory",value:function(){return this.data=[],localStorage.removeItem(this.key),Promise.resolve(!0)}},{key:"get",value:function(e){return Promise.resolve(this.data.find(function(t){return t.logid===e})||null)}},{key:"clear",value:function(){return this.data=[],this._saveAll(),Promise.resolve(!0)}},{key:"delete",value:function(e){var t=this.data.findIndex(function(t){return t.logid===e});return-1===t?Promise.resolve(!1):(this.data.splice(t,1),this._saveAll(),Promise.resolve(!0))}},{key:"count",value:function(){return Promise.resolve(this.data.length)}},{key:"download",value:function(t){for(var e=t.filter,n=t.keys,r="",o=0,i=0;i<this.data.length;i++){var a=this.data[i];P(a,e)&&(o++,r+=w(a,n)+"\n")}return Promise.resolve({content:r,count:o})}},{key:"filter",value:function(e){return this.noStore?Promise.resolve([]):Promise.resolve(this.data.filter(function(t){return P(t,e)}))}},{key:"getAll",value:function(){return this.noStore?Promise.resolve([]):Promise.resolve(this.data)}}]),r}(),A=function(){function c(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},e=t.id,e=void 0===e?"default":e,n=t.useConsole,n=void 0===n||n,r=t.storeType,r=void 0===r?"idb":r,o=t.maxRecords,o=void 0===o?1e4:o,i=t.baseInfo,a=t.onReport,u=t.onDiscard,t=t.onError;s(this,c),this._store=C.initStore({id:e,storeType:r,maxRecords:o,useConsole:n,onReport:a,onDiscard:u,onError:t}),this.storeType=this._store.type,this.id=e,this.injectBaseInfo(i)}return t(c,[{key:"injectBaseInfo",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return t.uid=C.initUUid("_tc_logger_uid",null==t?void 0:t.uid),t.clientid=C.initUUid("_tc_logger_clientid",null==t?void 0:t.clientid),t.url=t.url||window.location.href,t.ua=t.ua||window.navigator.userAgent,this._store.injectBaseInfo(t)}},{key:"log",value:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return this._logCommon(e,"log")}},{key:"error",value:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return this._logCommon(e,"error")}},{key:"warn",value:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return this._logCommon(e,"warn")}},{key:"info",value:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return this._logCommon(e,"info")}},{key:"_logCommon",value:function(t,e){t=C.buildLogData(t,e);return this._store.add(t)}},{key:"close",value:function(){return this._store.close()}},{key:"destory",value:function(){return this._store.destory()}},{key:"clear",value:function(){return this._store.clear()}},{key:"count",value:function(){return this._store.count()}},{key:"delete",value:function(t){return this._store.delete(t)}},{key:"refreshTraceId",value:function(){return this._store.refreshTraceId()}},{key:"refreshDurationStart",value:function(){return this._store.refreshDurationStart()}},{key:"download",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},u=t.name,c=t.filter,s=t.keys;return h(this,void 0,void 0,E().mark(function t(){var i,a;return E().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return u=u||y(new Date,"_"),t.next=3,this._store.download({filter:c,keys:s});case 3:return a=t.sent,i=a.content,a=a.count,e={name:"".concat(u,".log"),content:i},r=n=o=r=n=void 0,n=e.name,r=e.content,e=void 0===(e=e.type)?"text/plain":e,(o=document.createElement("a")).setAttribute("style","position: fixed;top: -100px"),document.body.appendChild(o),o.setAttribute("download",n),n=new Blob([r],{type:e}),r=URL.createObjectURL(n),o.href=r,o.click(),t.abrupt("return",a);case 8:case"end":return t.stop()}var e,n,r,o},t,this)}))}},{key:"get",value:function(t){return this._store.get(t)}},{key:"getAll",value:function(){return this._store.getAll()}},{key:"filter",value:function(t){return t?this._store.filter(t):this.getAll()}}]),c}(),C=(A.version="0.0.5",{buildLogData:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"log",n="__def__",r=t,o=void 0,i=t[0],a=f(i),t=("string"===a||"number"===a?(n="".concat(i),r=t.slice(1)):1===t.length&&"object"===f(a=i)&&"Object"===a.constructor.name&&(o=i,r=[]),{msg:n,type:e,extend:o});return 0<r.length&&(t.payload=r),t},initUUid:function(t,e){return e?(window.localStorage.setItem(t,e),e):((e=window.localStorage.getItem(t))||(e=v(),window.localStorage.setItem(t,e)),e)},initStore:function(t){var e=t.id,n=t.storeType,r=t.maxRecords,o=t.useConsole,i=t.onReport,a=t.onDiscard,t=t.onError,u=!!window.Worker&&!!window.indexedDB,e={id:e,useConsole:o,maxRecords:r,onReport:i,onDiscard:a,onError:t};return"idb"===n&&u?new D(e):new T(Object.assign(Object.assign({},e),{storeType:n}))}});return A});