@pisell/core 0.0.2

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.
Files changed (296) hide show
  1. package/README.md +1 -0
  2. package/es/app/app.d.ts +101 -0
  3. package/es/app/app.js +177 -0
  4. package/es/app/const.d.ts +4 -0
  5. package/es/app/const.js +6 -0
  6. package/es/app/index.d.ts +14 -0
  7. package/es/app/index.js +52 -0
  8. package/es/applicationManager/application.d.ts +197 -0
  9. package/es/applicationManager/application.js +469 -0
  10. package/es/applicationManager/index.d.ts +19 -0
  11. package/es/applicationManager/index.js +206 -0
  12. package/es/aws/index.d.ts +16 -0
  13. package/es/aws/index.js +76 -0
  14. package/es/cmd/const.d.ts +11 -0
  15. package/es/cmd/const.js +13 -0
  16. package/es/cmd/index.d.ts +13 -0
  17. package/es/cmd/index.js +91 -0
  18. package/es/cmd/type.d.ts +5 -0
  19. package/es/cmd/type.js +1 -0
  20. package/es/communicationManager/index.d.ts +59 -0
  21. package/es/communicationManager/index.js +174 -0
  22. package/es/config.d.ts +3 -0
  23. package/es/config.js +14 -0
  24. package/es/cookie/index.d.ts +13 -0
  25. package/es/cookie/index.js +47 -0
  26. package/es/css/global.less +73 -0
  27. package/es/css/index.less +31 -0
  28. package/es/css/variables.css +84 -0
  29. package/es/data/index.d.ts +8 -0
  30. package/es/data/index.js +16 -0
  31. package/es/history/config.d.ts +24 -0
  32. package/es/history/config.js +43 -0
  33. package/es/history/index.d.ts +26 -0
  34. package/es/history/index.js +80 -0
  35. package/es/history/type.d.ts +2 -0
  36. package/es/history/type.js +1 -0
  37. package/es/hooks/index.d.ts +12 -0
  38. package/es/hooks/index.js +13 -0
  39. package/es/hooks/useDelayedValue/index.d.ts +2 -0
  40. package/es/hooks/useDelayedValue/index.js +26 -0
  41. package/es/hooks/useDispatch/index.d.ts +2 -0
  42. package/es/hooks/useDispatch/index.js +2 -0
  43. package/es/hooks/useLowCode/index.d.ts +13 -0
  44. package/es/hooks/useLowCode/index.js +74 -0
  45. package/es/hooks/useStore/index.d.ts +6 -0
  46. package/es/hooks/useStore/index.js +11 -0
  47. package/es/index.d.ts +8 -0
  48. package/es/index.js +10 -0
  49. package/es/indexDB/index.d.ts +296 -0
  50. package/es/indexDB/index.js +1619 -0
  51. package/es/locales/en.d.ts +3 -0
  52. package/es/locales/en.js +5 -0
  53. package/es/locales/index.d.ts +39 -0
  54. package/es/locales/index.js +199 -0
  55. package/es/locales/original.d.ts +3 -0
  56. package/es/locales/original.js +7 -0
  57. package/es/locales/type.d.ts +19 -0
  58. package/es/locales/type.js +1 -0
  59. package/es/locales/zh-CN.d.ts +3 -0
  60. package/es/locales/zh-CN.js +5 -0
  61. package/es/locales/zh-HK.d.ts +3 -0
  62. package/es/locales/zh-HK.js +5 -0
  63. package/es/logger/feishu.d.ts +11 -0
  64. package/es/logger/feishu.js +50 -0
  65. package/es/logger/index.d.ts +135 -0
  66. package/es/logger/index.js +870 -0
  67. package/es/menuManager/hooks.d.ts +17 -0
  68. package/es/menuManager/hooks.js +136 -0
  69. package/es/menuManager/index.d.ts +28 -0
  70. package/es/menuManager/index.js +165 -0
  71. package/es/models/global.d.ts +32 -0
  72. package/es/models/global.js +66 -0
  73. package/es/models/index.d.ts +45 -0
  74. package/es/models/index.js +65 -0
  75. package/es/models/type.d.ts +2 -0
  76. package/es/models/type.js +1 -0
  77. package/es/plugin/index.d.ts +0 -0
  78. package/es/plugin/index.js +0 -0
  79. package/es/pubsub/example.d.ts +5 -0
  80. package/es/pubsub/example.js +92 -0
  81. package/es/pubsub/index.d.ts +73 -0
  82. package/es/pubsub/index.js +166 -0
  83. package/es/render/index.d.ts +0 -0
  84. package/es/render/index.js +0 -0
  85. package/es/request/cache.d.ts +46 -0
  86. package/es/request/cache.js +372 -0
  87. package/es/request/cancelToken.d.ts +38 -0
  88. package/es/request/cancelToken.js +59 -0
  89. package/es/request/config.d.ts +3 -0
  90. package/es/request/config.js +63 -0
  91. package/es/request/constants.d.ts +2 -0
  92. package/es/request/constants.js +6 -0
  93. package/es/request/index.d.ts +24 -0
  94. package/es/request/index.js +267 -0
  95. package/es/request/pisell2Request.d.ts +6 -0
  96. package/es/request/pisell2Request.js +62 -0
  97. package/es/request/type.d.ts +57 -0
  98. package/es/request/type.js +10 -0
  99. package/es/request/utils.d.ts +46 -0
  100. package/es/request/utils.js +147 -0
  101. package/es/routes/config.d.ts +7 -0
  102. package/es/routes/config.js +17 -0
  103. package/es/routes/index.d.ts +28 -0
  104. package/es/routes/index.js +151 -0
  105. package/es/socket/components/SocketMonitorPage.d.ts +6 -0
  106. package/es/socket/components/SocketMonitorPage.js +485 -0
  107. package/es/socket/components/index.d.ts +2 -0
  108. package/es/socket/components/index.js +2 -0
  109. package/es/socket/constants.d.ts +33 -0
  110. package/es/socket/constants.js +39 -0
  111. package/es/socket/events.d.ts +31 -0
  112. package/es/socket/events.js +19 -0
  113. package/es/socket/heartbeat.d.ts +66 -0
  114. package/es/socket/heartbeat.js +184 -0
  115. package/es/socket/index.d.ts +61 -0
  116. package/es/socket/index.js +246 -0
  117. package/es/socket/monitor.d.ts +169 -0
  118. package/es/socket/monitor.js +448 -0
  119. package/es/socket/reconnect.d.ts +61 -0
  120. package/es/socket/reconnect.js +199 -0
  121. package/es/socket/socket.d.ts +130 -0
  122. package/es/socket/socket.js +613 -0
  123. package/es/socket/types.d.ts +85 -0
  124. package/es/socket/types.js +35 -0
  125. package/es/storage/index.d.ts +17 -0
  126. package/es/storage/index.js +46 -0
  127. package/es/tasks/index.d.ts +127 -0
  128. package/es/tasks/index.js +1119 -0
  129. package/es/tasks/scheduledTasksExample.d.ts +61 -0
  130. package/es/tasks/scheduledTasksExample.js +351 -0
  131. package/es/tasks/type.d.ts +100 -0
  132. package/es/tasks/type.js +1 -0
  133. package/es/tasks/useTasks.d.ts +5 -0
  134. package/es/tasks/useTasks.js +25 -0
  135. package/es/type.d.ts +2 -0
  136. package/es/type.js +1 -0
  137. package/es/utils/adaptiveThrottle/index.d.ts +36 -0
  138. package/es/utils/adaptiveThrottle/index.js +136 -0
  139. package/es/variables/VariablesProvider.d.ts +7 -0
  140. package/es/variables/VariablesProvider.js +12 -0
  141. package/es/variables/config.d.ts +3 -0
  142. package/es/variables/config.js +16 -0
  143. package/es/variables/index.d.ts +6 -0
  144. package/es/variables/index.js +5 -0
  145. package/es/variables/type.d.ts +2 -0
  146. package/es/variables/type.js +1 -0
  147. package/es/website/index.d.ts +6 -0
  148. package/es/website/index.js +65 -0
  149. package/lib/app/app.d.ts +101 -0
  150. package/lib/app/app.js +171 -0
  151. package/lib/app/const.d.ts +4 -0
  152. package/lib/app/const.js +33 -0
  153. package/lib/app/index.d.ts +14 -0
  154. package/lib/app/index.js +76 -0
  155. package/lib/applicationManager/application.d.ts +197 -0
  156. package/lib/applicationManager/application.js +280 -0
  157. package/lib/applicationManager/index.d.ts +19 -0
  158. package/lib/applicationManager/index.js +88 -0
  159. package/lib/aws/index.d.ts +16 -0
  160. package/lib/aws/index.js +67 -0
  161. package/lib/cmd/const.d.ts +11 -0
  162. package/lib/cmd/const.js +39 -0
  163. package/lib/cmd/index.d.ts +13 -0
  164. package/lib/cmd/index.js +96 -0
  165. package/lib/cmd/type.d.ts +5 -0
  166. package/lib/cmd/type.js +17 -0
  167. package/lib/communicationManager/index.d.ts +59 -0
  168. package/lib/communicationManager/index.js +102 -0
  169. package/lib/config.d.ts +3 -0
  170. package/lib/config.js +36 -0
  171. package/lib/cookie/index.d.ts +13 -0
  172. package/lib/cookie/index.js +62 -0
  173. package/lib/css/global.less +73 -0
  174. package/lib/css/index.less +31 -0
  175. package/lib/css/variables.css +84 -0
  176. package/lib/data/index.d.ts +8 -0
  177. package/lib/data/index.js +38 -0
  178. package/lib/history/config.d.ts +24 -0
  179. package/lib/history/config.js +41 -0
  180. package/lib/history/index.d.ts +26 -0
  181. package/lib/history/index.js +99 -0
  182. package/lib/history/type.d.ts +2 -0
  183. package/lib/history/type.js +17 -0
  184. package/lib/hooks/index.d.ts +12 -0
  185. package/lib/hooks/index.js +44 -0
  186. package/lib/hooks/useDelayedValue/index.d.ts +2 -0
  187. package/lib/hooks/useDelayedValue/index.js +36 -0
  188. package/lib/hooks/useDispatch/index.d.ts +2 -0
  189. package/lib/hooks/useDispatch/index.js +26 -0
  190. package/lib/hooks/useLowCode/index.d.ts +13 -0
  191. package/lib/hooks/useLowCode/index.js +75 -0
  192. package/lib/hooks/useStore/index.d.ts +6 -0
  193. package/lib/hooks/useStore/index.js +33 -0
  194. package/lib/index.d.ts +8 -0
  195. package/lib/index.js +58 -0
  196. package/lib/indexDB/index.d.ts +296 -0
  197. package/lib/indexDB/index.js +767 -0
  198. package/lib/locales/en.d.ts +3 -0
  199. package/lib/locales/en.js +29 -0
  200. package/lib/locales/index.d.ts +39 -0
  201. package/lib/locales/index.js +159 -0
  202. package/lib/locales/original.d.ts +3 -0
  203. package/lib/locales/original.js +31 -0
  204. package/lib/locales/type.d.ts +19 -0
  205. package/lib/locales/type.js +17 -0
  206. package/lib/locales/zh-CN.d.ts +3 -0
  207. package/lib/locales/zh-CN.js +29 -0
  208. package/lib/locales/zh-HK.d.ts +3 -0
  209. package/lib/locales/zh-HK.js +29 -0
  210. package/lib/logger/feishu.d.ts +11 -0
  211. package/lib/logger/feishu.js +52 -0
  212. package/lib/logger/index.d.ts +135 -0
  213. package/lib/logger/index.js +476 -0
  214. package/lib/menuManager/hooks.d.ts +17 -0
  215. package/lib/menuManager/hooks.js +135 -0
  216. package/lib/menuManager/index.d.ts +28 -0
  217. package/lib/menuManager/index.js +125 -0
  218. package/lib/models/global.d.ts +32 -0
  219. package/lib/models/global.js +62 -0
  220. package/lib/models/index.d.ts +45 -0
  221. package/lib/models/index.js +69 -0
  222. package/lib/models/type.d.ts +2 -0
  223. package/lib/models/type.js +17 -0
  224. package/lib/plugin/index.d.ts +0 -0
  225. package/lib/plugin/index.js +0 -0
  226. package/lib/pubsub/example.d.ts +5 -0
  227. package/lib/pubsub/example.js +61 -0
  228. package/lib/pubsub/index.d.ts +73 -0
  229. package/lib/pubsub/index.js +141 -0
  230. package/lib/render/index.d.ts +0 -0
  231. package/lib/render/index.js +0 -0
  232. package/lib/request/cache.d.ts +46 -0
  233. package/lib/request/cache.js +195 -0
  234. package/lib/request/cancelToken.d.ts +38 -0
  235. package/lib/request/cancelToken.js +59 -0
  236. package/lib/request/config.d.ts +3 -0
  237. package/lib/request/config.js +69 -0
  238. package/lib/request/constants.d.ts +2 -0
  239. package/lib/request/constants.js +34 -0
  240. package/lib/request/index.d.ts +24 -0
  241. package/lib/request/index.js +210 -0
  242. package/lib/request/pisell2Request.d.ts +6 -0
  243. package/lib/request/pisell2Request.js +75 -0
  244. package/lib/request/type.d.ts +57 -0
  245. package/lib/request/type.js +36 -0
  246. package/lib/request/utils.d.ts +46 -0
  247. package/lib/request/utils.js +113 -0
  248. package/lib/routes/config.d.ts +7 -0
  249. package/lib/routes/config.js +50 -0
  250. package/lib/routes/index.d.ts +28 -0
  251. package/lib/routes/index.js +121 -0
  252. package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
  253. package/lib/socket/components/SocketMonitorPage.js +340 -0
  254. package/lib/socket/components/index.d.ts +2 -0
  255. package/lib/socket/components/index.js +39 -0
  256. package/lib/socket/constants.d.ts +33 -0
  257. package/lib/socket/constants.js +62 -0
  258. package/lib/socket/events.d.ts +31 -0
  259. package/lib/socket/events.js +44 -0
  260. package/lib/socket/heartbeat.d.ts +66 -0
  261. package/lib/socket/heartbeat.js +157 -0
  262. package/lib/socket/index.d.ts +61 -0
  263. package/lib/socket/index.js +198 -0
  264. package/lib/socket/monitor.d.ts +169 -0
  265. package/lib/socket/monitor.js +350 -0
  266. package/lib/socket/reconnect.d.ts +61 -0
  267. package/lib/socket/reconnect.js +157 -0
  268. package/lib/socket/socket.d.ts +130 -0
  269. package/lib/socket/socket.js +426 -0
  270. package/lib/socket/types.d.ts +85 -0
  271. package/lib/socket/types.js +36 -0
  272. package/lib/storage/index.d.ts +17 -0
  273. package/lib/storage/index.js +64 -0
  274. package/lib/tasks/index.d.ts +127 -0
  275. package/lib/tasks/index.js +710 -0
  276. package/lib/tasks/scheduledTasksExample.d.ts +61 -0
  277. package/lib/tasks/scheduledTasksExample.js +267 -0
  278. package/lib/tasks/type.d.ts +100 -0
  279. package/lib/tasks/type.js +17 -0
  280. package/lib/tasks/useTasks.d.ts +5 -0
  281. package/lib/tasks/useTasks.js +37 -0
  282. package/lib/type.d.ts +2 -0
  283. package/lib/type.js +17 -0
  284. package/lib/utils/adaptiveThrottle/index.d.ts +36 -0
  285. package/lib/utils/adaptiveThrottle/index.js +121 -0
  286. package/lib/variables/VariablesProvider.d.ts +7 -0
  287. package/lib/variables/VariablesProvider.js +51 -0
  288. package/lib/variables/config.d.ts +3 -0
  289. package/lib/variables/config.js +38 -0
  290. package/lib/variables/index.d.ts +6 -0
  291. package/lib/variables/index.js +29 -0
  292. package/lib/variables/type.d.ts +2 -0
  293. package/lib/variables/type.js +17 -0
  294. package/lib/website/index.d.ts +6 -0
  295. package/lib/website/index.js +75 -0
  296. package/package.json +49 -0
@@ -0,0 +1,870 @@
1
+ var _excluded = ["feishu"];
2
+ 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); }
3
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
4
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5
+ 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."); }
6
+ 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); }
7
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
9
+ 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; }
10
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
13
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
14
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
15
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
16
+ 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); }); }; }
17
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
19
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
20
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
22
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
+ import dayjs from "dayjs";
24
+ import { sendWarningLog } from "./feishu";
25
+
26
+ /**
27
+ * 日志项接口
28
+ */
29
+ /**
30
+ * 日志管理器类
31
+ */
32
+ var LoggerManager = /*#__PURE__*/function () {
33
+ // 日志管理器状态
34
+ /**
35
+ * 构造函数
36
+ * @param prefix 日志前缀
37
+ * @param checkInterval 检查间隔时间,默认5分钟
38
+ */
39
+ function LoggerManager(app, options) {
40
+ _classCallCheck(this, LoggerManager);
41
+ // 私有属性
42
+ _defineProperty(this, "logBuffer", []);
43
+ // 日志缓冲区
44
+ _defineProperty(this, "timer", null);
45
+ // 定时器
46
+ _defineProperty(this, "checkInterval", void 0);
47
+ // 检查间隔时间(毫秒)
48
+ _defineProperty(this, "prefix", "app");
49
+ // 日志文件前缀
50
+ _defineProperty(this, "metadata", void 0);
51
+ _defineProperty(this, "db", null);
52
+ // IndexDB 实例
53
+ _defineProperty(this, "app", void 0);
54
+ _defineProperty(this, "feishuConfig", void 0);
55
+ _defineProperty(this, "retentionDays", void 0);
56
+ // 日志保留天数
57
+ _defineProperty(this, "metadataFunction", void 0);
58
+ _defineProperty(this, "status", "running");
59
+ this.prefix = (options === null || options === void 0 ? void 0 : options.prefix) || "app";
60
+ this.checkInterval = (options === null || options === void 0 ? void 0 : options.checkInterval) || 5 * 60 * 1000;
61
+ this.app = app;
62
+ this.feishuConfig = options === null || options === void 0 ? void 0 : options.feishuConfig;
63
+ this.retentionDays = (options === null || options === void 0 ? void 0 : options.retentionDays) || 7; // 默认保留7天
64
+ this.initDB();
65
+ }
66
+ _createClass(LoggerManager, [{
67
+ key: "init",
68
+ value: function () {
69
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
70
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
71
+ while (1) switch (_context.prev = _context.next) {
72
+ case 0:
73
+ this.setStatus("running");
74
+ this.initTimer();
75
+ // 定期清理旧日志
76
+ this.cleanupOldLogs();
77
+ case 3:
78
+ case "end":
79
+ return _context.stop();
80
+ }
81
+ }, _callee, this);
82
+ }));
83
+ function init() {
84
+ return _init.apply(this, arguments);
85
+ }
86
+ return init;
87
+ }()
88
+ /**
89
+ * 初始化 IndexDB
90
+ */
91
+ }, {
92
+ key: "initDB",
93
+ value: (function () {
94
+ var _initDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
95
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
96
+ while (1) switch (_context2.prev = _context2.next) {
97
+ case 0:
98
+ if (this.app.dbManager) {
99
+ this.db = this.app.dbManager;
100
+ }
101
+ case 1:
102
+ case "end":
103
+ return _context2.stop();
104
+ }
105
+ }, _callee2, this);
106
+ }));
107
+ function initDB() {
108
+ return _initDB.apply(this, arguments);
109
+ }
110
+ return initDB;
111
+ }()
112
+ /**
113
+ * 设置元数据
114
+ * @param metadata 元数据
115
+ */
116
+ )
117
+ }, {
118
+ key: "setMetadata",
119
+ value: function setMetadata(metadata) {
120
+ this.metadata = metadata;
121
+ }
122
+ }, {
123
+ key: "setMetadataFunction",
124
+ value: function setMetadataFunction(metadataFunction) {
125
+ this.metadataFunction = metadataFunction;
126
+ }
127
+
128
+ /**
129
+ * 初始化定时器
130
+ */
131
+ }, {
132
+ key: "initTimer",
133
+ value: function initTimer() {
134
+ var _this = this;
135
+ this.timer = setInterval(function () {
136
+ if (_this.logBuffer.length > 0) {
137
+ _this.storeLog();
138
+ }
139
+ }, this.checkInterval);
140
+ }
141
+ }, {
142
+ key: "setStatus",
143
+ value: function setStatus(status) {
144
+ this.status = status;
145
+ }
146
+ }, {
147
+ key: "stop",
148
+ value: function stop() {
149
+ this.setStatus("stop");
150
+ if (this.timer) {
151
+ clearInterval(this.timer);
152
+ }
153
+ }
154
+
155
+ /**
156
+ * 添加日志
157
+ * @param log 日志项
158
+ */
159
+ }, {
160
+ key: "addLog",
161
+ value: function addLog(log) {
162
+ if (this.status === "stop") {
163
+ return;
164
+ }
165
+ var _ref = log || {},
166
+ feishu = _ref.feishu,
167
+ restLog = _objectWithoutProperties(_ref, _excluded);
168
+ var logItem = _objectSpread(_objectSpread({}, restLog), {}, {
169
+ date: log.date || dayjs().format("YYYY-MM-DD HH:mm:ss"),
170
+ metadata: JSON.stringify(log.metadata || {}),
171
+ // 以时间戳生成logId
172
+ logId: dayjs().valueOf()
173
+ });
174
+ console.log("---- 行为日志", logItem);
175
+ this.logBuffer.push(logItem);
176
+ if (log.type === "error" || log.type === "warning") {
177
+ this.sendFeishuNotification(_objectSpread(_objectSpread({}, logItem || {}), {}, {
178
+ feishu: feishu
179
+ }));
180
+ // error 级别日志需要立即存储
181
+ this.storeLog(log.type === "error");
182
+ }
183
+ }
184
+
185
+ /**
186
+ * 发送飞书通知
187
+ * @param log 日志项
188
+ */
189
+ }, {
190
+ key: "sendFeishuNotification",
191
+ value: function sendFeishuNotification(log) {
192
+ if (this.feishuConfig) {
193
+ var _this$metadataFunctio;
194
+ var _metadata = ((_this$metadataFunctio = this.metadataFunction) === null || _this$metadataFunctio === void 0 ? void 0 : _this$metadataFunctio.call(this)) || {};
195
+ var content = [{
196
+ key: "日志类型",
197
+ value: log.type
198
+ }, {
199
+ key: "日志时间",
200
+ value: log.date || dayjs().format("YYYY-MM-DD HH:mm:ss")
201
+ }, {
202
+ key: "日志来源",
203
+ value: JSON.stringify(_objectSpread(_objectSpread({}, this.metadata || {}), _metadata))
204
+ }];
205
+ if (log.feishu) {
206
+ content.push({
207
+ key: "日志内容",
208
+ value: JSON.stringify(log.feishu || {})
209
+ });
210
+ } else {
211
+ content.push({
212
+ key: "日志内容",
213
+ value: JSON.stringify(log.metadata || {})
214
+ });
215
+ }
216
+ sendWarningLog({
217
+ title: log.title,
218
+ content: content,
219
+ webhook: this.feishuConfig.webhook
220
+ });
221
+ console.log("-------- 发送飞书通知", log);
222
+ }
223
+ }
224
+
225
+ /**
226
+ * 创建日志文件名
227
+ * @returns 日志文件名
228
+ */
229
+ }, {
230
+ key: "createFileName",
231
+ value: function createFileName(date) {
232
+ var _date = date || dayjs().format("YYYY-MM-DD-HH");
233
+ var fileName = "".concat(this.prefix, "_").concat(_date, ".log");
234
+ return fileName;
235
+ }
236
+
237
+ /**
238
+ * 创建AWS日志文件名
239
+ * @param isManual 紧急上传
240
+ * @returns 日志文件名
241
+ */
242
+ }, {
243
+ key: "createAWSFileName",
244
+ value: (function () {
245
+ var _createAWSFileName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(urgent) {
246
+ var _this$app;
247
+ var _date, _hour, _this$app2, fileName;
248
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
249
+ while (1) switch (_context3.prev = _context3.next) {
250
+ case 0:
251
+ _date = dayjs().format("YYYY-MM-DD");
252
+ _hour = dayjs().format("HH:mm"); // 紧急上传时,在小时后面加上当前时间戳 避免文件名重复覆盖
253
+ if (urgent) {
254
+ _hour = "".concat(dayjs().format("HH:mm"), " [ urgent ] ").concat(dayjs().valueOf());
255
+ }
256
+ if (!((_this$app = this.app) !== null && _this$app !== void 0 && (_this$app = _this$app.getPlugin("aws")) !== null && _this$app !== void 0 && _this$app.createFileName)) {
257
+ _context3.next = 5;
258
+ break;
259
+ }
260
+ return _context3.abrupt("return", (_this$app2 = this.app) === null || _this$app2 === void 0 || (_this$app2 = _this$app2.getPlugin("aws")) === null || _this$app2 === void 0 ? void 0 : _this$app2.createFileName({
261
+ date: _date,
262
+ hour: _hour,
263
+ isManual: false
264
+ }));
265
+ case 5:
266
+ fileName = "logs/".concat("pisell", "/", _date, "/").concat(_hour);
267
+ return _context3.abrupt("return", "".concat(fileName, ".json"));
268
+ case 7:
269
+ case "end":
270
+ return _context3.stop();
271
+ }
272
+ }, _callee3, this);
273
+ }));
274
+ function createAWSFileName(_x) {
275
+ return _createAWSFileName.apply(this, arguments);
276
+ }
277
+ return createAWSFileName;
278
+ }()
279
+ /**
280
+ * 创建日志文件
281
+ * @param _fileName 文件名
282
+ * @returns 日志文件对象
283
+ */
284
+ )
285
+ }, {
286
+ key: "createFile",
287
+ value: function createFile(_fileName) {
288
+ var _date = dayjs().format("YYYY-MM-DD-HH");
289
+ var fileName = _fileName || this.createFileName(_date);
290
+ return {
291
+ fileName: fileName,
292
+ date: _date,
293
+ fileContent: {
294
+ metadata: this.metadata,
295
+ logs: []
296
+ }
297
+ };
298
+ }
299
+
300
+ /**
301
+ * 存储日志到持久化存储
302
+ */
303
+ }, {
304
+ key: "storeLog",
305
+ value: (function () {
306
+ var _storeLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(urgent) {
307
+ var _this$logBuffer, fileName, buffer, bufferIds, logs;
308
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
309
+ while (1) switch (_context4.prev = _context4.next) {
310
+ case 0:
311
+ if (!(this.logBuffer.length === 0 || !this.db)) {
312
+ _context4.next = 2;
313
+ break;
314
+ }
315
+ return _context4.abrupt("return");
316
+ case 2:
317
+ _context4.prev = 2;
318
+ _context4.next = 5;
319
+ return this.createAWSFileName(urgent);
320
+ case 5:
321
+ fileName = _context4.sent;
322
+ console.log("-------- 存储日志到AWS 开始", fileName);
323
+
324
+ // 将buffer中的metadata转换为对象
325
+ buffer = (_this$logBuffer = this.logBuffer) === null || _this$logBuffer === void 0 ? void 0 : _this$logBuffer.map(function (item) {
326
+ return _objectSpread(_objectSpread({}, item || {}), {}, {
327
+ metadata: JSON.parse(item.metadata || "{}")
328
+ });
329
+ });
330
+ bufferIds = buffer.map(function (item) {
331
+ return item.logId;
332
+ });
333
+ logs = JSON.stringify(buffer, null, 2);
334
+ _context4.next = 12;
335
+ return this.app.aws.upload({
336
+ Bucket: "",
337
+ Key: fileName,
338
+ Body: logs
339
+ });
340
+ case 12:
341
+ this.addLog({
342
+ type: "info",
343
+ title: "存储日志到AWS 成功",
344
+ metadata: {
345
+ fileName: fileName,
346
+ '本地上传的ids': bufferIds,
347
+ '实例下的ids': this.logBuffer.map(function (item) {
348
+ return item.logId;
349
+ })
350
+ }
351
+ });
352
+ console.log("-------- 存储日志到AWS 成功");
353
+ // 上传成功后需要清空缓冲区,避免重复上传
354
+ this.logBuffer = this.logBuffer.filter(function (item) {
355
+ return !bufferIds.includes(item.logId);
356
+ });
357
+ _context4.next = 30;
358
+ break;
359
+ case 17:
360
+ _context4.prev = 17;
361
+ _context4.t0 = _context4["catch"](2);
362
+ console.error("存储日志上传AWS失败:", _context4.t0);
363
+ this.addLog({
364
+ type: "info",
365
+ title: "存储日志到AWS失败",
366
+ metadata: {
367
+ error: {
368
+ name: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.name,
369
+ message: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.message,
370
+ stack: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.stack
371
+ }
372
+ }
373
+ });
374
+
375
+ // 将日志存储到IndexDB
376
+ _context4.prev = 21;
377
+ _context4.next = 24;
378
+ return this.storeLogToIndexDB();
379
+ case 24:
380
+ _context4.next = 30;
381
+ break;
382
+ case 26:
383
+ _context4.prev = 26;
384
+ _context4.t1 = _context4["catch"](21);
385
+ this.sendFeishuNotification({
386
+ type: "error",
387
+ title: "将日志存储到IndexDB失败",
388
+ metadata: {
389
+ indexDBError: {
390
+ name: _context4.t1 === null || _context4.t1 === void 0 ? void 0 : _context4.t1.name,
391
+ message: _context4.t1 === null || _context4.t1 === void 0 ? void 0 : _context4.t1.message,
392
+ stack: _context4.t1 === null || _context4.t1 === void 0 ? void 0 : _context4.t1.stack
393
+ }
394
+ }
395
+ });
396
+ console.error("存储日志到IndexDB也失败:", _context4.t1);
397
+ case 30:
398
+ case "end":
399
+ return _context4.stop();
400
+ }
401
+ }, _callee4, this, [[2, 17], [21, 26]]);
402
+ }));
403
+ function storeLog(_x2) {
404
+ return _storeLog.apply(this, arguments);
405
+ }
406
+ return storeLog;
407
+ }())
408
+ }, {
409
+ key: "uploadIndexDBLog",
410
+ value: function () {
411
+ var _uploadIndexDBLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
412
+ var _this$db, _this$db2, logFile, awsFileName, logs;
413
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
414
+ while (1) switch (_context5.prev = _context5.next) {
415
+ case 0:
416
+ _context5.prev = 0;
417
+ this.addLog({
418
+ type: "info",
419
+ title: "准备将IndexDB中的日志上传到AWS"
420
+ });
421
+ if (this.db) {
422
+ _context5.next = 4;
423
+ break;
424
+ }
425
+ return _context5.abrupt("return");
426
+ case 4:
427
+ _context5.next = 6;
428
+ return (_this$db = this.db) === null || _this$db === void 0 ? void 0 : _this$db.getAll("logs");
429
+ case 6:
430
+ logFile = _context5.sent;
431
+ if (!(!logFile || (logFile === null || logFile === void 0 ? void 0 : logFile.length) === 0)) {
432
+ _context5.next = 9;
433
+ break;
434
+ }
435
+ return _context5.abrupt("return");
436
+ case 9:
437
+ _context5.next = 11;
438
+ return this.createAWSFileName(true);
439
+ case 11:
440
+ awsFileName = _context5.sent;
441
+ logs = JSON.stringify(logFile, null, 2);
442
+ _context5.next = 15;
443
+ return this.app.aws.upload({
444
+ Bucket: "",
445
+ Key: awsFileName,
446
+ Body: logs
447
+ });
448
+ case 15:
449
+ console.log("-------- 存储日志到AWS 成功");
450
+ _context5.next = 18;
451
+ return (_this$db2 = this.db) === null || _this$db2 === void 0 ? void 0 : _this$db2.clear("logs");
452
+ case 18:
453
+ console.log("-------- 清空IndexDB日志成功");
454
+ _context5.next = 26;
455
+ break;
456
+ case 21:
457
+ _context5.prev = 21;
458
+ _context5.t0 = _context5["catch"](0);
459
+ console.log("-------- 存储日志到IndexDB 失败", _context5.t0);
460
+ this.addLog({
461
+ type: "info",
462
+ title: "存储IndexDB日志到AWS失败",
463
+ metadata: {
464
+ error: {
465
+ name: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.name,
466
+ message: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.message,
467
+ stack: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.stack
468
+ }
469
+ }
470
+ });
471
+ // this.sendFeishuNotification({
472
+ // type: "error",
473
+ // title: "存储IndexDB日志到AWS失败",
474
+ // metadata: {
475
+ // error: {
476
+ // name: error?.name,
477
+ // message: error?.message,
478
+ // stack: error?.stack,
479
+ // }
480
+ // },
481
+ // });
482
+ // 重新抛出错误,让外层 catch 能够捕获
483
+ throw _context5.t0;
484
+ case 26:
485
+ case "end":
486
+ return _context5.stop();
487
+ }
488
+ }, _callee5, this, [[0, 21]]);
489
+ }));
490
+ function uploadIndexDBLog() {
491
+ return _uploadIndexDBLog.apply(this, arguments);
492
+ }
493
+ return uploadIndexDBLog;
494
+ }()
495
+ }, {
496
+ key: "storeLogToIndexDB",
497
+ value: function () {
498
+ var _storeLogToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
499
+ var _this$db3, _this$db5, fileName, buffer, logFile, _this$db4, bufferIds;
500
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
501
+ while (1) switch (_context6.prev = _context6.next) {
502
+ case 0:
503
+ _context6.prev = 0;
504
+ fileName = this.createFileName();
505
+ console.log("storeLog", fileName);
506
+ buffer = this.logBuffer || []; // 获取现有日志文件
507
+ _context6.next = 6;
508
+ return (_this$db3 = this.db) === null || _this$db3 === void 0 ? void 0 : _this$db3.get("logs", fileName);
509
+ case 6:
510
+ logFile = _context6.sent;
511
+ if (logFile) {
512
+ _context6.next = 11;
513
+ break;
514
+ }
515
+ logFile = this.createFile(fileName);
516
+ _context6.next = 11;
517
+ return (_this$db4 = this.db) === null || _this$db4 === void 0 ? void 0 : _this$db4.add("logs", logFile);
518
+ case 11:
519
+ // 添加日志到文件内容
520
+ logFile.fileContent.logs = [].concat(_toConsumableArray(logFile.fileContent.logs), _toConsumableArray(buffer));
521
+
522
+ // 更新日志文件
523
+ _context6.next = 14;
524
+ return (_this$db5 = this.db) === null || _this$db5 === void 0 ? void 0 : _this$db5.update("logs", logFile);
525
+ case 14:
526
+ console.log("-------- 存储日志到IndexDB", {
527
+ fileName: fileName,
528
+ logFile: logFile
529
+ });
530
+ bufferIds = buffer.map(function (item) {
531
+ return item.logId;
532
+ }); // 上传成功后需要清空缓冲区,避免重复上传
533
+ this.logBuffer = this.logBuffer.filter(function (item) {
534
+ return !bufferIds.includes(item.logId);
535
+ });
536
+ _context6.next = 23;
537
+ break;
538
+ case 19:
539
+ _context6.prev = 19;
540
+ _context6.t0 = _context6["catch"](0);
541
+ console.log("-------- 存储日志到IndexDB 失败", _context6.t0);
542
+ // 重新抛出错误,让外层 catch 能够捕获
543
+ throw _context6.t0;
544
+ case 23:
545
+ case "end":
546
+ return _context6.stop();
547
+ }
548
+ }, _callee6, this, [[0, 19]]);
549
+ }));
550
+ function storeLogToIndexDB() {
551
+ return _storeLogToIndexDB.apply(this, arguments);
552
+ }
553
+ return storeLogToIndexDB;
554
+ }()
555
+ /**
556
+ * 清理旧日志,只保留最近指定天数的日志
557
+ */
558
+ }, {
559
+ key: "cleanupOldLogs",
560
+ value: (function () {
561
+ var _cleanupOldLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
562
+ var logFiles, cutoffDate, filesToDelete, _iterator, _step, file;
563
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
564
+ while (1) switch (_context7.prev = _context7.next) {
565
+ case 0:
566
+ if (this.db) {
567
+ _context7.next = 2;
568
+ break;
569
+ }
570
+ return _context7.abrupt("return");
571
+ case 2:
572
+ _context7.prev = 2;
573
+ this.addLog({
574
+ type: "info",
575
+ title: "准备清理旧日志,开始获取所有日志文件"
576
+ });
577
+
578
+ // 获取所有日志文件
579
+ _context7.next = 6;
580
+ return this.getLogFiles();
581
+ case 6:
582
+ logFiles = _context7.sent;
583
+ this.addLog({
584
+ type: "info",
585
+ title: "获取旧日志成功",
586
+ metadata: {
587
+ logFilesCount: logFiles === null || logFiles === void 0 ? void 0 : logFiles.length
588
+ }
589
+ });
590
+
591
+ // 计算保留日志的截止日期
592
+ cutoffDate = dayjs().subtract(this.retentionDays, "day").format("YYYY-MM-DD"); // 筛选出需要删除的日志文件
593
+ filesToDelete = (logFiles || []).filter(function (file) {
594
+ return file.date < cutoffDate;
595
+ });
596
+ console.log("-------- \u6E05\u7406\u65E7\u65E5\u5FD7\uFF0C\u4FDD\u7559 ".concat(this.retentionDays, " \u5929\u5185\u7684\u65E5\u5FD7\uFF0C\u622A\u6B62\u65E5\u671F: ").concat(cutoffDate));
597
+
598
+ // 删除旧日志文件
599
+ _iterator = _createForOfIteratorHelper(filesToDelete);
600
+ _context7.prev = 12;
601
+ _iterator.s();
602
+ case 14:
603
+ if ((_step = _iterator.n()).done) {
604
+ _context7.next = 21;
605
+ break;
606
+ }
607
+ file = _step.value;
608
+ _context7.next = 18;
609
+ return this.db.delete("logs", file.fileName);
610
+ case 18:
611
+ console.log("-------- \u5220\u9664\u65E7\u65E5\u5FD7\u6587\u4EF6: ".concat(file.fileName, ", \u65E5\u671F: ").concat(file.date));
612
+ case 19:
613
+ _context7.next = 14;
614
+ break;
615
+ case 21:
616
+ _context7.next = 26;
617
+ break;
618
+ case 23:
619
+ _context7.prev = 23;
620
+ _context7.t0 = _context7["catch"](12);
621
+ _iterator.e(_context7.t0);
622
+ case 26:
623
+ _context7.prev = 26;
624
+ _iterator.f();
625
+ return _context7.finish(26);
626
+ case 29:
627
+ if (filesToDelete.length > 0) {
628
+ console.log("-------- \u5171\u6E05\u7406 ".concat(filesToDelete.length, " \u4E2A\u65E7\u65E5\u5FD7\u6587\u4EF6"));
629
+ }
630
+ this.addLog({
631
+ type: "info",
632
+ title: "清理旧日志成功",
633
+ metadata: {
634
+ filesToDelete: filesToDelete
635
+ }
636
+ });
637
+
638
+ // 清理完成后,将IndexDB中的日志上传到AWS
639
+ this.uploadIndexDBLog();
640
+ _context7.next = 38;
641
+ break;
642
+ case 34:
643
+ _context7.prev = 34;
644
+ _context7.t1 = _context7["catch"](2);
645
+ this.addLog({
646
+ type: "error",
647
+ title: "清理旧日志失败!",
648
+ metadata: {
649
+ error: {
650
+ name: _context7.t1 === null || _context7.t1 === void 0 ? void 0 : _context7.t1.name,
651
+ message: _context7.t1 === null || _context7.t1 === void 0 ? void 0 : _context7.t1.message,
652
+ stack: _context7.t1 === null || _context7.t1 === void 0 ? void 0 : _context7.t1.stack
653
+ }
654
+ }
655
+ });
656
+ console.error("清理旧日志失败:", _context7.t1);
657
+ case 38:
658
+ case "end":
659
+ return _context7.stop();
660
+ }
661
+ }, _callee7, this, [[2, 34], [12, 23, 26, 29]]);
662
+ }));
663
+ function cleanupOldLogs() {
664
+ return _cleanupOldLogs.apply(this, arguments);
665
+ }
666
+ return cleanupOldLogs;
667
+ }()
668
+ /**
669
+ * 获取日志文件列表
670
+ * @returns 日志文件列表
671
+ */
672
+ )
673
+ }, {
674
+ key: "getLogFiles",
675
+ value: (function () {
676
+ var _getLogFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
677
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
678
+ while (1) switch (_context8.prev = _context8.next) {
679
+ case 0:
680
+ if (this.db) {
681
+ _context8.next = 2;
682
+ break;
683
+ }
684
+ return _context8.abrupt("return", []);
685
+ case 2:
686
+ _context8.prev = 2;
687
+ _context8.next = 5;
688
+ return this.db.getAll("logs");
689
+ case 5:
690
+ return _context8.abrupt("return", _context8.sent);
691
+ case 8:
692
+ _context8.prev = 8;
693
+ _context8.t0 = _context8["catch"](2);
694
+ this.addLog({
695
+ type: "error",
696
+ title: "获取本地日志文件列表失败"
697
+ });
698
+ console.error("获取日志文件列表失败:", _context8.t0);
699
+ return _context8.abrupt("return", []);
700
+ case 13:
701
+ case "end":
702
+ return _context8.stop();
703
+ }
704
+ }, _callee8, this, [[2, 8]]);
705
+ }));
706
+ function getLogFiles() {
707
+ return _getLogFiles.apply(this, arguments);
708
+ }
709
+ return getLogFiles;
710
+ }()
711
+ /**
712
+ * 获取指定日志文件的内容
713
+ * @param fileName 日志文件名
714
+ * @returns 日志文件内容
715
+ */
716
+ )
717
+ }, {
718
+ key: "getLogFile",
719
+ value: (function () {
720
+ var _getLogFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(fileName) {
721
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
722
+ while (1) switch (_context9.prev = _context9.next) {
723
+ case 0:
724
+ if (this.db) {
725
+ _context9.next = 2;
726
+ break;
727
+ }
728
+ return _context9.abrupt("return", null);
729
+ case 2:
730
+ _context9.prev = 2;
731
+ _context9.next = 5;
732
+ return this.db.get("logs", fileName);
733
+ case 5:
734
+ return _context9.abrupt("return", _context9.sent);
735
+ case 8:
736
+ _context9.prev = 8;
737
+ _context9.t0 = _context9["catch"](2);
738
+ console.error("获取日志文件内容失败:", _context9.t0);
739
+ return _context9.abrupt("return", null);
740
+ case 12:
741
+ case "end":
742
+ return _context9.stop();
743
+ }
744
+ }, _callee9, this, [[2, 8]]);
745
+ }));
746
+ function getLogFile(_x3) {
747
+ return _getLogFile.apply(this, arguments);
748
+ }
749
+ return getLogFile;
750
+ }()
751
+ /**
752
+ * 清空指定日志文件
753
+ * @param fileName 日志文件名,不指定则清空所有日志
754
+ * @returns 是否成功
755
+ */
756
+ )
757
+ }, {
758
+ key: "clearLogs",
759
+ value: (function () {
760
+ var _clearLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(fileName) {
761
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
762
+ while (1) switch (_context10.prev = _context10.next) {
763
+ case 0:
764
+ if (this.db) {
765
+ _context10.next = 2;
766
+ break;
767
+ }
768
+ return _context10.abrupt("return", false);
769
+ case 2:
770
+ _context10.prev = 2;
771
+ if (!fileName) {
772
+ _context10.next = 8;
773
+ break;
774
+ }
775
+ _context10.next = 6;
776
+ return this.db.delete("logs", fileName);
777
+ case 6:
778
+ _context10.next = 10;
779
+ break;
780
+ case 8:
781
+ _context10.next = 10;
782
+ return this.db.clear("logs");
783
+ case 10:
784
+ return _context10.abrupt("return", true);
785
+ case 13:
786
+ _context10.prev = 13;
787
+ _context10.t0 = _context10["catch"](2);
788
+ console.error("清空日志失败:", _context10.t0);
789
+ return _context10.abrupt("return", false);
790
+ case 17:
791
+ case "end":
792
+ return _context10.stop();
793
+ }
794
+ }, _callee10, this, [[2, 13]]);
795
+ }));
796
+ function clearLogs(_x4) {
797
+ return _clearLogs.apply(this, arguments);
798
+ }
799
+ return clearLogs;
800
+ }()
801
+ /**
802
+ * 设置日志保留天数
803
+ * @param days 保留天数
804
+ */
805
+ )
806
+ }, {
807
+ key: "setRetentionDays",
808
+ value: function setRetentionDays(days) {
809
+ if (days > 0) {
810
+ this.retentionDays = days;
811
+ console.log("-------- \u8BBE\u7F6E\u65E5\u5FD7\u4FDD\u7559\u5929\u6570\u4E3A ".concat(days, " \u5929"));
812
+ } else {
813
+ console.error("日志保留天数必须大于0");
814
+ }
815
+ }
816
+
817
+ /**
818
+ * 手动触发清理旧日志
819
+ */
820
+ }, {
821
+ key: "manualCleanup",
822
+ value: (function () {
823
+ var _manualCleanup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
824
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
825
+ while (1) switch (_context11.prev = _context11.next) {
826
+ case 0:
827
+ this.addLog({
828
+ type: "info",
829
+ title: "manualCleanup 手动触发清理旧日志"
830
+ });
831
+ _context11.next = 3;
832
+ return this.cleanupOldLogs();
833
+ case 3:
834
+ case "end":
835
+ return _context11.stop();
836
+ }
837
+ }, _callee11, this);
838
+ }));
839
+ function manualCleanup() {
840
+ return _manualCleanup.apply(this, arguments);
841
+ }
842
+ return manualCleanup;
843
+ }()
844
+ /**
845
+ * 销毁实例
846
+ */
847
+ )
848
+ }, {
849
+ key: "destroy",
850
+ value: function destroy() {
851
+ if (this.timer) {
852
+ clearInterval(this.timer);
853
+ this.timer = null;
854
+ }
855
+
856
+ // 存储剩余的日志
857
+ if (this.logBuffer.length > 0) {
858
+ this.storeLog();
859
+ }
860
+
861
+ // 关闭数据库连接
862
+ if (this.db) {
863
+ this.db.close();
864
+ this.db = null;
865
+ }
866
+ }
867
+ }]);
868
+ return LoggerManager;
869
+ }();
870
+ export default LoggerManager;