@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,1619 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function 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; }
3
+ 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; }
4
+ 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; } } }; }
5
+ 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; }
6
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
7
+ 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."); }
8
+ 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); }
9
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
10
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
11
+ 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; }
12
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
13
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
14
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
+ 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); } }
16
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
19
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
20
+ import dayjs from 'dayjs';
21
+ import Dexie from 'dexie';
22
+ export var mockPromise = function mockPromise(data) {
23
+ var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
24
+ return new Promise(function (resolve, reject) {
25
+ setTimeout(function () {
26
+ resolve(data);
27
+ }, timeout);
28
+ });
29
+ };
30
+
31
+ /**
32
+ * IndexDB 管理器模块
33
+ *
34
+ * 这个模块使用 Dexie.js 提供了对浏览器 IndexedDB 的简单封装,并在不支持 IndexedDB 的环境中
35
+ * 自动降级使用内存存储作为备选存储方案。
36
+ */
37
+
38
+ /**
39
+ * 数据库配置选项接口
40
+ * @interface DBOptions
41
+ * @property {string} dbName - 数据库名称
42
+ * @property {number} version - 数据库版本号
43
+ * @property {Array} stores - 存储对象配置数组
44
+ * @property {string} stores[].name - 存储对象名称
45
+ * @property {string} stores[].keyPath - 主键路径
46
+ * @property {Array} [stores[].indexes] - 索引配置数组(可选)
47
+ * @property {string} stores[].indexes[].name - 索引名称
48
+ * @property {string} stores[].indexes[].keyPath - 索引键路径
49
+ * @property {IDBIndexParameters} [stores[].indexes[].options] - 索引选项(可选)
50
+ */
51
+ /**
52
+ * IndexDB 管理器类
53
+ * 使用 Dexie.js 提供对 IndexedDB 的封装,支持自动降级到内存存储
54
+ * @class IndexDBManager
55
+ */
56
+ var IndexDBManager = /*#__PURE__*/function () {
57
+ /**
58
+ * 创建 IndexDBManager 实例
59
+ * @param {DBOptions} options - 数据库配置选项
60
+ */
61
+ function IndexDBManager(app, options) {
62
+ var _options$timeout,
63
+ _this = this;
64
+ _classCallCheck(this, IndexDBManager);
65
+ _defineProperty(this, "db", null);
66
+ _defineProperty(this, "dbName", void 0);
67
+ _defineProperty(this, "version", void 0);
68
+ _defineProperty(this, "stores", void 0);
69
+ _defineProperty(this, "useIndexDB", void 0);
70
+ _defineProperty(this, "app", void 0);
71
+ // 内存存储:每个 store 使用一个 Map,key 为主键,value 为数据
72
+ _defineProperty(this, "memoryStorage", new Map());
73
+ // 操作超时时间(毫秒)
74
+ _defineProperty(this, "timeout", 10000);
75
+ // ===== 防抖 add 相关 =====
76
+ // 每个 store 一个 buffer
77
+ _defineProperty(this, "debouncedBuffers", new Map());
78
+ // 每个 store 一个 timer
79
+ _defineProperty(this, "debouncedTimers", new Map());
80
+ // 正在 flush 的 store
81
+ _defineProperty(this, "debouncedFlushing", new Set());
82
+ // 防抖时间(ms)
83
+ _defineProperty(this, "debouncedDelay", 200);
84
+ // 单次事务最大写入条数
85
+ _defineProperty(this, "debouncedBatchSize", 50);
86
+ // ===== 防抖 update 相关 =====
87
+ // 每个 store 一个 Map(key -> data)
88
+ _defineProperty(this, "debouncedUpdateBuffers", new Map());
89
+ _defineProperty(this, "debouncedUpdateTimers", new Map());
90
+ _defineProperty(this, "debouncedUpdateFlushing", new Set());
91
+ _defineProperty(this, "debouncedUpdateDelay", 200);
92
+ _defineProperty(this, "debouncedUpdateBatchSize", 50);
93
+ this.app = app;
94
+ this.dbName = options.dbName;
95
+ this.version = options.version;
96
+ this.stores = options.stores;
97
+ this.useIndexDB = IndexDBManager.isSupported();
98
+ this.timeout = (_options$timeout = options.timeout) !== null && _options$timeout !== void 0 ? _options$timeout : 10000; // 默认 10 秒超时
99
+
100
+ // 初始化内存存储的各个 store
101
+ if (!this.useIndexDB) {
102
+ this.stores.forEach(function (store) {
103
+ _this.memoryStorage.set(store.name, new Map());
104
+ });
105
+ }
106
+ }
107
+
108
+ /**
109
+ * 超时包装器 - 为 Promise 添加超时控制
110
+ * @param {Promise<T>} promise - 需要包装的 Promise
111
+ * @param {string} operation - 操作名称(用于错误提示)
112
+ * @returns {Promise<T>} 带超时控制的 Promise
113
+ * @private
114
+ */
115
+ _createClass(IndexDBManager, [{
116
+ key: "withTimeout",
117
+ value: function withTimeout(promise, operation) {
118
+ var _this2 = this;
119
+ var timeoutId = null;
120
+ var timeoutPromise = new Promise(function (_, reject) {
121
+ timeoutId = setTimeout(function () {
122
+ var error = new Error("\u64CD\u4F5C\u8D85\u65F6: ".concat(operation, " \u5728 ").concat(_this2.timeout, "ms \u5185\u672A\u5B8C\u6210"));
123
+ _this2.app.logger.addLog({
124
+ type: 'error',
125
+ title: '[ IndexDB ] TIMEOUT',
126
+ metadata: {
127
+ msg: "\u64CD\u4F5C\u8D85\u65F6: ".concat(operation),
128
+ timeout: _this2.timeout,
129
+ operation: operation
130
+ }
131
+ });
132
+ reject(error);
133
+ }, _this2.timeout);
134
+ });
135
+ return Promise.race([promise.then(function (result) {
136
+ // Promise 成功完成,清除超时定时器
137
+ if (timeoutId) clearTimeout(timeoutId);
138
+ return result;
139
+ }, function (error) {
140
+ // Promise 失败,清除超时定时器
141
+ if (timeoutId) clearTimeout(timeoutId);
142
+ throw error;
143
+ }), timeoutPromise]);
144
+ }
145
+
146
+ /**
147
+ * 初始化数据库连接
148
+ * 如果环境不支持 IndexedDB,将自动使用内存存储
149
+ * @returns {Promise<boolean>} 连接是否成功
150
+ */
151
+ }, {
152
+ key: "connect",
153
+ value: (function () {
154
+ var _connect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
155
+ var _this3 = this;
156
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
157
+ while (1) switch (_context2.prev = _context2.next) {
158
+ case 0:
159
+ if (this.useIndexDB) {
160
+ _context2.next = 2;
161
+ break;
162
+ }
163
+ return _context2.abrupt("return", true);
164
+ case 2:
165
+ return _context2.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
166
+ var schema;
167
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
168
+ while (1) switch (_context.prev = _context.next) {
169
+ case 0:
170
+ _context.prev = 0;
171
+ // 创建 Dexie 实例
172
+ _this3.db = new Dexie(_this3.dbName);
173
+
174
+ // 构建 schema
175
+ schema = {};
176
+ _this3.stores.forEach(function (store) {
177
+ var _store$indexes;
178
+ // Dexie schema 格式: "primaryKey, index1, index2, ..."
179
+ var indexes = ((_store$indexes = store.indexes) === null || _store$indexes === void 0 ? void 0 : _store$indexes.map(function (index) {
180
+ var _index$options, _index$options2;
181
+ var indexStr = index.name;
182
+ // Dexie 使用 & 表示复合索引,* 表示多值索引,+ 表示自增主键
183
+ if ((_index$options = index.options) !== null && _index$options !== void 0 && _index$options.unique) {
184
+ indexStr = "&".concat(indexStr);
185
+ }
186
+ if ((_index$options2 = index.options) !== null && _index$options2 !== void 0 && _index$options2.multiEntry) {
187
+ indexStr = "*".concat(indexStr);
188
+ }
189
+ return indexStr;
190
+ })) || [];
191
+
192
+ // 主键需要放在最前面,使用 ++ 表示自增,& 表示唯一
193
+ var primaryKey = store.keyPath;
194
+ schema[store.name] = [primaryKey].concat(_toConsumableArray(indexes)).join(',');
195
+ });
196
+
197
+ // 定义数据库版本和 schema
198
+ _this3.db.version(_this3.version).stores(schema);
199
+
200
+ // 打开数据库
201
+ _context.next = 7;
202
+ return _this3.db.open();
203
+ case 7:
204
+ // 监听错误和关闭事件
205
+ _this3.db.on('blocked', function () {
206
+ _this3.app.logger.addLog({
207
+ type: 'error',
208
+ title: '[ IndexDB ] blocked',
209
+ metadata: {
210
+ msg: 'DB blocked'
211
+ }
212
+ });
213
+ });
214
+ _this3.db.on('close', function () {
215
+ _this3.app.logger.addLog({
216
+ type: 'error',
217
+ title: '[ IndexDB ] CLOSE',
218
+ metadata: {
219
+ msg: 'DB close'
220
+ }
221
+ });
222
+ });
223
+ return _context.abrupt("return", true);
224
+ case 12:
225
+ _context.prev = 12;
226
+ _context.t0 = _context["catch"](0);
227
+ _this3.app.logger.addLog({
228
+ type: 'error',
229
+ title: '[ IndexDB ] ERROR',
230
+ metadata: {
231
+ msg: 'DB request error',
232
+ message: _context.t0.message
233
+ }
234
+ });
235
+ throw _context.t0;
236
+ case 16:
237
+ case "end":
238
+ return _context.stop();
239
+ }
240
+ }, _callee, null, [[0, 12]]);
241
+ }))(), 'connect'));
242
+ case 3:
243
+ case "end":
244
+ return _context2.stop();
245
+ }
246
+ }, _callee2, this);
247
+ }));
248
+ function connect() {
249
+ return _connect.apply(this, arguments);
250
+ }
251
+ return connect;
252
+ }()
253
+ /**
254
+ * 获取内存存储中指定 store 的 Map
255
+ * @param {string} storeName - 存储对象名称
256
+ * @returns {Map<string | number, any>} 存储 Map
257
+ * @private
258
+ */
259
+ )
260
+ }, {
261
+ key: "getMemoryStore",
262
+ value: function getMemoryStore(storeName) {
263
+ var store = this.memoryStorage.get(storeName);
264
+ if (!store) {
265
+ store = new Map();
266
+ this.memoryStorage.set(storeName, store);
267
+ }
268
+ return store;
269
+ }
270
+
271
+ /**
272
+ * 防抖合并 add(用于高频写入场景)
273
+ * @param storeName 存储对象名称
274
+ * @param data 数据
275
+ */
276
+ }, {
277
+ key: "debouncedAdd",
278
+ value: function debouncedAdd(storeName, data) {
279
+ var _this4 = this;
280
+ if (!this.db) return;
281
+
282
+ // 初始化 buffer
283
+ if (!this.debouncedBuffers.has(storeName)) {
284
+ this.debouncedBuffers.set(storeName, []);
285
+ }
286
+ this.debouncedBuffers.get(storeName).push(data);
287
+
288
+ // 如果正在 flush,不重新 debounce
289
+ if (this.debouncedFlushing.has(storeName)) return;
290
+
291
+ // 重置 timer
292
+ var oldTimer = this.debouncedTimers.get(storeName);
293
+ if (oldTimer) clearTimeout(oldTimer);
294
+ this.debouncedTimers.set(storeName, setTimeout(function () {
295
+ _this4.flushDebouncedAdd(storeName);
296
+ }, this.debouncedDelay));
297
+ }
298
+
299
+ /**
300
+ * 立即 flush 指定 store 的防抖 add
301
+ */
302
+ }, {
303
+ key: "flushDebouncedAdd",
304
+ value: (function () {
305
+ var _flushDebouncedAdd = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(storeName) {
306
+ var buffer, uuid, batch, _iterator, _step, item;
307
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
308
+ while (1) switch (_context3.prev = _context3.next) {
309
+ case 0:
310
+ if (!(!this.useIndexDB || !this.db)) {
311
+ _context3.next = 2;
312
+ break;
313
+ }
314
+ return _context3.abrupt("return");
315
+ case 2:
316
+ if (!this.debouncedFlushing.has(storeName)) {
317
+ _context3.next = 4;
318
+ break;
319
+ }
320
+ return _context3.abrupt("return");
321
+ case 4:
322
+ buffer = this.debouncedBuffers.get(storeName);
323
+ if (!(!buffer || buffer.length === 0)) {
324
+ _context3.next = 7;
325
+ break;
326
+ }
327
+ return _context3.abrupt("return");
328
+ case 7:
329
+ this.debouncedFlushing.add(storeName);
330
+ uuid = "[ IndexDB ] DEBOUNCED_ADD: - ".concat(storeName, " - ").concat(dayjs().valueOf());
331
+ _context3.prev = 9;
332
+ case 10:
333
+ if (!(buffer.length > 0)) {
334
+ _context3.next = 38;
335
+ break;
336
+ }
337
+ batch = buffer.splice(0, this.debouncedBatchSize);
338
+ _iterator = _createForOfIteratorHelper(batch);
339
+ _context3.prev = 13;
340
+ _iterator.s();
341
+ case 15:
342
+ if ((_step = _iterator.n()).done) {
343
+ _context3.next = 28;
344
+ break;
345
+ }
346
+ item = _step.value;
347
+ _context3.next = 19;
348
+ return mockPromise({}, this.debouncedDelay);
349
+ case 19:
350
+ _context3.prev = 19;
351
+ _context3.next = 22;
352
+ return this.add(storeName, item);
353
+ case 22:
354
+ _context3.next = 26;
355
+ break;
356
+ case 24:
357
+ _context3.prev = 24;
358
+ _context3.t0 = _context3["catch"](19);
359
+ case 26:
360
+ _context3.next = 15;
361
+ break;
362
+ case 28:
363
+ _context3.next = 33;
364
+ break;
365
+ case 30:
366
+ _context3.prev = 30;
367
+ _context3.t1 = _context3["catch"](13);
368
+ _iterator.e(_context3.t1);
369
+ case 33:
370
+ _context3.prev = 33;
371
+ _iterator.f();
372
+ return _context3.finish(33);
373
+ case 36:
374
+ _context3.next = 10;
375
+ break;
376
+ case 38:
377
+ _context3.next = 43;
378
+ break;
379
+ case 40:
380
+ _context3.prev = 40;
381
+ _context3.t2 = _context3["catch"](9);
382
+ this.app.logger.addLog({
383
+ type: 'error',
384
+ title: uuid,
385
+ metadata: {
386
+ msg: '防抖合并 add 失败',
387
+ error: _context3.t2.message
388
+ }
389
+ });
390
+ case 43:
391
+ _context3.prev = 43;
392
+ this.debouncedFlushing.delete(storeName);
393
+ return _context3.finish(43);
394
+ case 46:
395
+ case "end":
396
+ return _context3.stop();
397
+ }
398
+ }, _callee3, this, [[9, 40, 43, 46], [13, 30, 33, 36], [19, 24]]);
399
+ }));
400
+ function flushDebouncedAdd(_x) {
401
+ return _flushDebouncedAdd.apply(this, arguments);
402
+ }
403
+ return flushDebouncedAdd;
404
+ }()
405
+ /**
406
+ * 防抖合并 update(同 key 自动合并)
407
+ */
408
+ )
409
+ }, {
410
+ key: "debouncedUpdate",
411
+ value: function debouncedUpdate(storeName, data) {
412
+ var _this5 = this;
413
+ // 内存模式
414
+ if (!this.useIndexDB) {
415
+ var _storeConfig = this.stores.find(function (s) {
416
+ return s.name === storeName;
417
+ });
418
+ var _keyPath = (_storeConfig === null || _storeConfig === void 0 ? void 0 : _storeConfig.keyPath) || 'id';
419
+ var _key = data[_keyPath];
420
+ this.getMemoryStore(storeName).set(_key, _objectSpread(_objectSpread({}, this.getMemoryStore(storeName).get(_key)), data));
421
+ return;
422
+ }
423
+ if (!this.db) return;
424
+ var storeConfig = this.stores.find(function (s) {
425
+ return s.name === storeName;
426
+ });
427
+ var keyPath = (storeConfig === null || storeConfig === void 0 ? void 0 : storeConfig.keyPath) || 'id';
428
+ var key = data[keyPath];
429
+ if (key == null) {
430
+ console.warn("[IndexDB] debouncedUpdate missing keyPath: ".concat(keyPath));
431
+ return;
432
+ }
433
+ if (!this.debouncedUpdateBuffers.has(storeName)) {
434
+ this.debouncedUpdateBuffers.set(storeName, new Map());
435
+ }
436
+
437
+ // 同 key 合并(后写覆盖)
438
+ var storeBuffer = this.debouncedUpdateBuffers.get(storeName);
439
+ storeBuffer.set(key, _objectSpread(_objectSpread({}, storeBuffer.get(key) || {}), data));
440
+ if (this.debouncedUpdateFlushing.has(storeName)) return;
441
+ var oldTimer = this.debouncedUpdateTimers.get(storeName);
442
+ if (oldTimer) clearTimeout(oldTimer);
443
+ this.debouncedUpdateTimers.set(storeName, setTimeout(function () {
444
+ _this5.flushDebouncedUpdate(storeName);
445
+ }, this.debouncedUpdateDelay));
446
+ }
447
+ /**
448
+ * flush 防抖 update
449
+ */
450
+ }, {
451
+ key: "flushDebouncedUpdate",
452
+ value: (function () {
453
+ var _flushDebouncedUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(storeName) {
454
+ var bufferMap, uuid, entries, i, batch, _iterator2, _step2, item;
455
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
456
+ while (1) switch (_context4.prev = _context4.next) {
457
+ case 0:
458
+ if (!(!this.useIndexDB || !this.db)) {
459
+ _context4.next = 2;
460
+ break;
461
+ }
462
+ return _context4.abrupt("return");
463
+ case 2:
464
+ if (!this.debouncedUpdateFlushing.has(storeName)) {
465
+ _context4.next = 4;
466
+ break;
467
+ }
468
+ return _context4.abrupt("return");
469
+ case 4:
470
+ bufferMap = this.debouncedUpdateBuffers.get(storeName);
471
+ if (!(!bufferMap || bufferMap.size === 0)) {
472
+ _context4.next = 7;
473
+ break;
474
+ }
475
+ return _context4.abrupt("return");
476
+ case 7:
477
+ this.debouncedUpdateFlushing.add(storeName);
478
+ uuid = "[ IndexDB ] DEBOUNCED_UPDATE: - ".concat(storeName, " - ").concat(dayjs().valueOf());
479
+ _context4.prev = 9;
480
+ entries = Array.from(bufferMap.values());
481
+ bufferMap.clear();
482
+ i = 0;
483
+ case 13:
484
+ if (!(i < entries.length)) {
485
+ _context4.next = 42;
486
+ break;
487
+ }
488
+ batch = entries.slice(i, i + this.debouncedUpdateBatchSize);
489
+ _iterator2 = _createForOfIteratorHelper(batch);
490
+ _context4.prev = 16;
491
+ _iterator2.s();
492
+ case 18:
493
+ if ((_step2 = _iterator2.n()).done) {
494
+ _context4.next = 31;
495
+ break;
496
+ }
497
+ item = _step2.value;
498
+ _context4.next = 22;
499
+ return mockPromise(item, this.debouncedUpdateDelay);
500
+ case 22:
501
+ _context4.prev = 22;
502
+ _context4.next = 25;
503
+ return this.update(storeName, item);
504
+ case 25:
505
+ _context4.next = 29;
506
+ break;
507
+ case 27:
508
+ _context4.prev = 27;
509
+ _context4.t0 = _context4["catch"](22);
510
+ case 29:
511
+ _context4.next = 18;
512
+ break;
513
+ case 31:
514
+ _context4.next = 36;
515
+ break;
516
+ case 33:
517
+ _context4.prev = 33;
518
+ _context4.t1 = _context4["catch"](16);
519
+ _iterator2.e(_context4.t1);
520
+ case 36:
521
+ _context4.prev = 36;
522
+ _iterator2.f();
523
+ return _context4.finish(36);
524
+ case 39:
525
+ i += this.debouncedUpdateBatchSize;
526
+ _context4.next = 13;
527
+ break;
528
+ case 42:
529
+ _context4.next = 47;
530
+ break;
531
+ case 44:
532
+ _context4.prev = 44;
533
+ _context4.t2 = _context4["catch"](9);
534
+ this.app.logger.addLog({
535
+ type: 'error',
536
+ title: uuid,
537
+ metadata: {
538
+ msg: '防抖合并 update 失败',
539
+ error: _context4.t2.message
540
+ }
541
+ });
542
+ case 47:
543
+ _context4.prev = 47;
544
+ this.debouncedUpdateFlushing.delete(storeName);
545
+ return _context4.finish(47);
546
+ case 50:
547
+ case "end":
548
+ return _context4.stop();
549
+ }
550
+ }, _callee4, this, [[9, 44, 47, 50], [16, 33, 36, 39], [22, 27]]);
551
+ }));
552
+ function flushDebouncedUpdate(_x2) {
553
+ return _flushDebouncedUpdate.apply(this, arguments);
554
+ }
555
+ return flushDebouncedUpdate;
556
+ }()
557
+ /**
558
+ * 添加数据到指定的存储对象
559
+ * @param {string} storeName - 存储对象名称
560
+ * @param {T} data - 要添加的数据
561
+ * * @param {boolean} [log=true] - 是否记录日志
562
+ * @returns {Promise<T>} 添加的数据
563
+ * @template T
564
+ */
565
+ )
566
+ }, {
567
+ key: "add",
568
+ value: (function () {
569
+ var _add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(storeName, data) {
570
+ var _this6 = this;
571
+ var log,
572
+ storeConfig,
573
+ keyPath,
574
+ _key2,
575
+ memStore,
576
+ uuid,
577
+ _args6 = arguments;
578
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
579
+ while (1) switch (_context6.prev = _context6.next) {
580
+ case 0:
581
+ log = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : false;
582
+ if (this.useIndexDB) {
583
+ _context6.next = 8;
584
+ break;
585
+ }
586
+ // 使用内存存储
587
+ storeConfig = this.stores.find(function (s) {
588
+ return s.name === storeName;
589
+ });
590
+ keyPath = (storeConfig === null || storeConfig === void 0 ? void 0 : storeConfig.keyPath) || 'id';
591
+ _key2 = data[keyPath];
592
+ memStore = this.getMemoryStore(storeName);
593
+ memStore.set(_key2, data);
594
+ return _context6.abrupt("return", data);
595
+ case 8:
596
+ uuid = "[ IndexDB ] ADD: - ".concat(storeName, " - ").concat(dayjs().valueOf());
597
+ if (log) {
598
+ // this.app.logger.addLog({
599
+ // type: 'info',
600
+ // title: uuid,
601
+ // metadata: { msg: '添加数据前', data: data }
602
+ // })
603
+ }
604
+ return _context6.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
605
+ var issExists;
606
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
607
+ while (1) switch (_context5.prev = _context5.next) {
608
+ case 0:
609
+ if (_this6.db) {
610
+ _context5.next = 3;
611
+ break;
612
+ }
613
+ if (log) {
614
+ _this6.app.logger.addLog({
615
+ type: 'error',
616
+ title: uuid,
617
+ metadata: {
618
+ msg: '添加数据前 数据库未连接',
619
+ data: data
620
+ }
621
+ });
622
+ }
623
+ throw new Error('数据库未连接');
624
+ case 3:
625
+ _context5.prev = 3;
626
+ _context5.next = 6;
627
+ return _this6.db.table(storeName).add(data);
628
+ case 6:
629
+ return _context5.abrupt("return", data);
630
+ case 9:
631
+ _context5.prev = 9;
632
+ _context5.t0 = _context5["catch"](3);
633
+ issExists = ((_context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.message) || '').includes('exists'); // 如果错误信息中包含 'exists',则表示数据已存在,不报日志
634
+ _this6.app.logger.addLog({
635
+ type: issExists ? 'info' : 'error',
636
+ title: uuid,
637
+ metadata: {
638
+ msg: '添加数据失败',
639
+ data: data,
640
+ error: _context5.t0.message
641
+ }
642
+ });
643
+ throw new Error(_context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.message);
644
+ case 14:
645
+ case "end":
646
+ return _context5.stop();
647
+ }
648
+ }, _callee5, null, [[3, 9]]);
649
+ }))(), "add(".concat(storeName, ")")));
650
+ case 11:
651
+ case "end":
652
+ return _context6.stop();
653
+ }
654
+ }, _callee6, this);
655
+ }));
656
+ function add(_x3, _x4) {
657
+ return _add.apply(this, arguments);
658
+ }
659
+ return add;
660
+ }()
661
+ /**
662
+ * 快速检查指定存储对象中的数据是否存在
663
+ * @param {string} storeName - 存储对象名称
664
+ * @param {string|number} key - 数据主键
665
+ * @returns {Promise<boolean>} 数据是否存在
666
+ */
667
+ )
668
+ }, {
669
+ key: "exists",
670
+ value: (function () {
671
+ var _exists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(storeName, key) {
672
+ var _this7 = this;
673
+ var memStore;
674
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
675
+ while (1) switch (_context8.prev = _context8.next) {
676
+ case 0:
677
+ if (this.useIndexDB) {
678
+ _context8.next = 3;
679
+ break;
680
+ }
681
+ // 使用内存存储
682
+ memStore = this.getMemoryStore(storeName);
683
+ return _context8.abrupt("return", memStore.has(key));
684
+ case 3:
685
+ return _context8.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
686
+ var result;
687
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
688
+ while (1) switch (_context7.prev = _context7.next) {
689
+ case 0:
690
+ if (_this7.db) {
691
+ _context7.next = 2;
692
+ break;
693
+ }
694
+ throw new Error('数据库未连接');
695
+ case 2:
696
+ _context7.prev = 2;
697
+ _context7.next = 5;
698
+ return _this7.db.table(storeName).get(key);
699
+ case 5:
700
+ result = _context7.sent;
701
+ return _context7.abrupt("return", result !== undefined);
702
+ case 9:
703
+ _context7.prev = 9;
704
+ _context7.t0 = _context7["catch"](2);
705
+ throw new Error('检查数据存在性失败');
706
+ case 12:
707
+ case "end":
708
+ return _context7.stop();
709
+ }
710
+ }, _callee7, null, [[2, 9]]);
711
+ }))(), "exists(".concat(storeName, ")")));
712
+ case 4:
713
+ case "end":
714
+ return _context8.stop();
715
+ }
716
+ }, _callee8, this);
717
+ }));
718
+ function exists(_x5, _x6) {
719
+ return _exists.apply(this, arguments);
720
+ }
721
+ return exists;
722
+ }()
723
+ /**
724
+ * 获取指定存储对象中的数据
725
+ * @param {string} storeName - 存储对象名称
726
+ * @param {string|number} key - 数据主键
727
+ * * @param {boolean} [log=true] - 是否记录日志
728
+ * @returns {Promise<T|null>} 获取的数据,不存在则返回 null
729
+ * @template T
730
+ */
731
+ )
732
+ }, {
733
+ key: "get",
734
+ value: (function () {
735
+ var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(storeName, key) {
736
+ var _this8 = this;
737
+ var log,
738
+ uuid,
739
+ _memStore$get,
740
+ memStore,
741
+ _args10 = arguments;
742
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
743
+ while (1) switch (_context10.prev = _context10.next) {
744
+ case 0:
745
+ log = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : false;
746
+ uuid = "[ IndexDB ] GET: - ".concat(storeName, " - ").concat(key, " - ").concat(dayjs().valueOf());
747
+ if (log) {
748
+ // this.app.logger.addLog({
749
+ // type: 'info',
750
+ // title: uuid,
751
+ // metadata: { msg: '获取数据前' }
752
+ // })
753
+ }
754
+ if (this.useIndexDB) {
755
+ _context10.next = 6;
756
+ break;
757
+ }
758
+ // 使用内存存储
759
+ memStore = this.getMemoryStore(storeName);
760
+ return _context10.abrupt("return", (_memStore$get = memStore.get(key)) !== null && _memStore$get !== void 0 ? _memStore$get : null);
761
+ case 6:
762
+ return _context10.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
763
+ var result;
764
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
765
+ while (1) switch (_context9.prev = _context9.next) {
766
+ case 0:
767
+ if (_this8.db) {
768
+ _context9.next = 3;
769
+ break;
770
+ }
771
+ if (log) {
772
+ _this8.app.logger.addLog({
773
+ type: 'error',
774
+ title: uuid,
775
+ metadata: {
776
+ msg: '数据库未连接'
777
+ }
778
+ });
779
+ }
780
+ throw new Error('数据库未连接');
781
+ case 3:
782
+ _context9.prev = 3;
783
+ _context9.next = 6;
784
+ return _this8.db.table(storeName).get(key);
785
+ case 6:
786
+ result = _context9.sent;
787
+ if (log) {
788
+ // this.app.logger.addLog({
789
+ // type: 'info',
790
+ // title: uuid,
791
+ // metadata: { msg: '获取成功' }
792
+ // });
793
+ // this.app.logger.addLog({
794
+ // type: 'info',
795
+ // title: uuid,
796
+ // metadata: { msg: '事务完成' }
797
+ // });
798
+ }
799
+ return _context9.abrupt("return", result !== null && result !== void 0 ? result : null);
800
+ case 11:
801
+ _context9.prev = 11;
802
+ _context9.t0 = _context9["catch"](3);
803
+ if (log) {
804
+ _this8.app.logger.addLog({
805
+ type: 'error',
806
+ title: uuid,
807
+ metadata: {
808
+ msg: '获取失败',
809
+ error: _context9.t0.message
810
+ }
811
+ });
812
+ }
813
+ throw new Error('获取数据失败');
814
+ case 15:
815
+ case "end":
816
+ return _context9.stop();
817
+ }
818
+ }, _callee9, null, [[3, 11]]);
819
+ }))(), "get(".concat(storeName, ")")));
820
+ case 7:
821
+ case "end":
822
+ return _context10.stop();
823
+ }
824
+ }, _callee10, this);
825
+ }));
826
+ function get(_x7, _x8) {
827
+ return _get.apply(this, arguments);
828
+ }
829
+ return get;
830
+ }()
831
+ /**
832
+ * 更新指定存储对象中的数据
833
+ * @param {string} storeName - 存储对象名称
834
+ * @param {T} data - 要更新的数据
835
+ * * @param {boolean} [log=true] - 是否记录日志
836
+ * @returns {Promise<T>} 更新后的数据
837
+ * @template T
838
+ */
839
+ )
840
+ }, {
841
+ key: "update",
842
+ value: (function () {
843
+ var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(storeName, data) {
844
+ var _this9 = this;
845
+ var log,
846
+ storeConfig,
847
+ keyPath,
848
+ _key3,
849
+ memStore,
850
+ uuid,
851
+ _args12 = arguments;
852
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
853
+ while (1) switch (_context12.prev = _context12.next) {
854
+ case 0:
855
+ log = _args12.length > 2 && _args12[2] !== undefined ? _args12[2] : false;
856
+ if (this.useIndexDB) {
857
+ _context12.next = 8;
858
+ break;
859
+ }
860
+ // 使用内存存储
861
+ storeConfig = this.stores.find(function (s) {
862
+ return s.name === storeName;
863
+ });
864
+ keyPath = (storeConfig === null || storeConfig === void 0 ? void 0 : storeConfig.keyPath) || 'id';
865
+ _key3 = data[keyPath];
866
+ memStore = this.getMemoryStore(storeName);
867
+ memStore.set(_key3, data);
868
+ return _context12.abrupt("return", data);
869
+ case 8:
870
+ uuid = "[ IndexDB ] UPDATE: - ".concat(storeName, " - ").concat(dayjs().valueOf());
871
+ if (log) {
872
+ // this.app.logger.addLog({
873
+ // type: 'info',
874
+ // title: uuid,
875
+ // metadata: { msg: '更新数据前', data: data }
876
+ // })
877
+ }
878
+ return _context12.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
879
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
880
+ while (1) switch (_context11.prev = _context11.next) {
881
+ case 0:
882
+ if (_this9.db) {
883
+ _context11.next = 3;
884
+ break;
885
+ }
886
+ if (log) {
887
+ _this9.app.logger.addLog({
888
+ type: 'error',
889
+ title: uuid,
890
+ metadata: {
891
+ msg: '数据库未连接'
892
+ }
893
+ });
894
+ }
895
+ throw new Error('数据库未连接');
896
+ case 3:
897
+ _context11.prev = 3;
898
+ _context11.next = 6;
899
+ return _this9.db.table(storeName).put(data);
900
+ case 6:
901
+ if (log) {
902
+ // this.app.logger.addLog({
903
+ // type: 'info',
904
+ // title: uuid,
905
+ // metadata: { msg: '数据更新完成' }
906
+ // });
907
+ // console.log('✅ 事务完成');
908
+ // this.app.logger.addLog({
909
+ // type: 'info',
910
+ // title: uuid,
911
+ // metadata: { msg: '事务完成' }
912
+ // });
913
+ }
914
+ return _context11.abrupt("return", data);
915
+ case 10:
916
+ _context11.prev = 10;
917
+ _context11.t0 = _context11["catch"](3);
918
+ _this9.app.logger.addLog({
919
+ type: 'error',
920
+ title: uuid,
921
+ metadata: {
922
+ msg: '数据更新失败',
923
+ error: _context11.t0.message
924
+ }
925
+ });
926
+ throw new Error(_context11.t0 === null || _context11.t0 === void 0 ? void 0 : _context11.t0.message);
927
+ case 14:
928
+ case "end":
929
+ return _context11.stop();
930
+ }
931
+ }, _callee11, null, [[3, 10]]);
932
+ }))(), "update(".concat(storeName, ")")));
933
+ case 11:
934
+ case "end":
935
+ return _context12.stop();
936
+ }
937
+ }, _callee12, this);
938
+ }));
939
+ function update(_x9, _x10) {
940
+ return _update.apply(this, arguments);
941
+ }
942
+ return update;
943
+ }()
944
+ /**
945
+ * 删除指定存储对象中的数据
946
+ * @param {string} storeName - 存储对象名称
947
+ * @param {string|number} key - 数据主键
948
+ * @returns {Promise<boolean>} 删除是否成功
949
+ */
950
+ )
951
+ }, {
952
+ key: "delete",
953
+ value: (function () {
954
+ var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(storeName, key) {
955
+ var _this10 = this;
956
+ var memStore;
957
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
958
+ while (1) switch (_context14.prev = _context14.next) {
959
+ case 0:
960
+ if (this.useIndexDB) {
961
+ _context14.next = 3;
962
+ break;
963
+ }
964
+ // 使用内存存储
965
+ memStore = this.getMemoryStore(storeName);
966
+ return _context14.abrupt("return", memStore.delete(key));
967
+ case 3:
968
+ return _context14.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
969
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
970
+ while (1) switch (_context13.prev = _context13.next) {
971
+ case 0:
972
+ if (_this10.db) {
973
+ _context13.next = 2;
974
+ break;
975
+ }
976
+ throw new Error('数据库未连接');
977
+ case 2:
978
+ _context13.prev = 2;
979
+ _context13.next = 5;
980
+ return _this10.db.table(storeName).delete(key);
981
+ case 5:
982
+ return _context13.abrupt("return", true);
983
+ case 8:
984
+ _context13.prev = 8;
985
+ _context13.t0 = _context13["catch"](2);
986
+ throw new Error('删除数据失败');
987
+ case 11:
988
+ case "end":
989
+ return _context13.stop();
990
+ }
991
+ }, _callee13, null, [[2, 8]]);
992
+ }))(), "delete(".concat(storeName, ")")));
993
+ case 4:
994
+ case "end":
995
+ return _context14.stop();
996
+ }
997
+ }, _callee14, this);
998
+ }));
999
+ function _delete(_x11, _x12) {
1000
+ return _delete2.apply(this, arguments);
1001
+ }
1002
+ return _delete;
1003
+ }()
1004
+ /**
1005
+ * 通过索引获取数据
1006
+ * @param {string} storeName - 存储对象名称
1007
+ * @param {string} indexName - 索引名称
1008
+ * @param {string|number} indexValue - 索引值
1009
+ * @returns {Promise<T|null>} 获取的数据,不存在则返回 null
1010
+ * @template T
1011
+ */
1012
+ )
1013
+ }, {
1014
+ key: "getByIndex",
1015
+ value: (function () {
1016
+ var _getByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(storeName, indexName, indexValue) {
1017
+ var _this11 = this;
1018
+ var _storeConfig$indexes, allData, storeConfig, index;
1019
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1020
+ while (1) switch (_context16.prev = _context16.next) {
1021
+ case 0:
1022
+ if (this.useIndexDB) {
1023
+ _context16.next = 9;
1024
+ break;
1025
+ }
1026
+ _context16.next = 3;
1027
+ return this.getAll(storeName);
1028
+ case 3:
1029
+ allData = _context16.sent;
1030
+ storeConfig = this.stores.find(function (s) {
1031
+ return s.name === storeName;
1032
+ });
1033
+ index = storeConfig === null || storeConfig === void 0 || (_storeConfig$indexes = storeConfig.indexes) === null || _storeConfig$indexes === void 0 ? void 0 : _storeConfig$indexes.find(function (i) {
1034
+ return i.name === indexName;
1035
+ });
1036
+ if (index) {
1037
+ _context16.next = 8;
1038
+ break;
1039
+ }
1040
+ return _context16.abrupt("return", null);
1041
+ case 8:
1042
+ return _context16.abrupt("return", allData.find(function (item) {
1043
+ return item[index.keyPath] === indexValue;
1044
+ }) || null);
1045
+ case 9:
1046
+ return _context16.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
1047
+ var result;
1048
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1049
+ while (1) switch (_context15.prev = _context15.next) {
1050
+ case 0:
1051
+ if (_this11.db) {
1052
+ _context15.next = 2;
1053
+ break;
1054
+ }
1055
+ throw new Error('数据库未连接');
1056
+ case 2:
1057
+ _context15.prev = 2;
1058
+ _context15.next = 5;
1059
+ return _this11.db.table(storeName).where(indexName).equals(indexValue).first();
1060
+ case 5:
1061
+ result = _context15.sent;
1062
+ return _context15.abrupt("return", result || null);
1063
+ case 9:
1064
+ _context15.prev = 9;
1065
+ _context15.t0 = _context15["catch"](2);
1066
+ throw new Error('通过索引获取数据失败');
1067
+ case 12:
1068
+ case "end":
1069
+ return _context15.stop();
1070
+ }
1071
+ }, _callee15, null, [[2, 9]]);
1072
+ }))(), "getByIndex(".concat(storeName, ", ").concat(indexName, ")")));
1073
+ case 10:
1074
+ case "end":
1075
+ return _context16.stop();
1076
+ }
1077
+ }, _callee16, this);
1078
+ }));
1079
+ function getByIndex(_x13, _x14, _x15) {
1080
+ return _getByIndex.apply(this, arguments);
1081
+ }
1082
+ return getByIndex;
1083
+ }()
1084
+ /**
1085
+ * 通过索引检查数据是否存在
1086
+ * @param {string} storeName - 存储对象名称
1087
+ * @param {string} indexName - 索引名称
1088
+ * @param {string|number} indexValue - 索引值
1089
+ * @returns {Promise<boolean>} 数据是否存在
1090
+ */
1091
+ )
1092
+ }, {
1093
+ key: "existsByIndex",
1094
+ value: (function () {
1095
+ var _existsByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(storeName, indexName, indexValue) {
1096
+ var _this12 = this;
1097
+ var _storeConfig$indexes2, allData, storeConfig, index;
1098
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1099
+ while (1) switch (_context18.prev = _context18.next) {
1100
+ case 0:
1101
+ if (this.useIndexDB) {
1102
+ _context18.next = 9;
1103
+ break;
1104
+ }
1105
+ _context18.next = 3;
1106
+ return this.getAll(storeName);
1107
+ case 3:
1108
+ allData = _context18.sent;
1109
+ storeConfig = this.stores.find(function (s) {
1110
+ return s.name === storeName;
1111
+ });
1112
+ index = storeConfig === null || storeConfig === void 0 || (_storeConfig$indexes2 = storeConfig.indexes) === null || _storeConfig$indexes2 === void 0 ? void 0 : _storeConfig$indexes2.find(function (i) {
1113
+ return i.name === indexName;
1114
+ });
1115
+ if (index) {
1116
+ _context18.next = 8;
1117
+ break;
1118
+ }
1119
+ return _context18.abrupt("return", false);
1120
+ case 8:
1121
+ return _context18.abrupt("return", allData.some(function (item) {
1122
+ return item[index.keyPath] === indexValue;
1123
+ }));
1124
+ case 9:
1125
+ return _context18.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1126
+ var count;
1127
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1128
+ while (1) switch (_context17.prev = _context17.next) {
1129
+ case 0:
1130
+ if (_this12.db) {
1131
+ _context17.next = 2;
1132
+ break;
1133
+ }
1134
+ throw new Error('数据库未连接');
1135
+ case 2:
1136
+ _context17.prev = 2;
1137
+ _context17.next = 5;
1138
+ return _this12.db.table(storeName).where(indexName).equals(indexValue).count();
1139
+ case 5:
1140
+ count = _context17.sent;
1141
+ return _context17.abrupt("return", count > 0);
1142
+ case 9:
1143
+ _context17.prev = 9;
1144
+ _context17.t0 = _context17["catch"](2);
1145
+ throw new Error('通过索引检查数据存在性失败');
1146
+ case 12:
1147
+ case "end":
1148
+ return _context17.stop();
1149
+ }
1150
+ }, _callee17, null, [[2, 9]]);
1151
+ }))(), "existsByIndex(".concat(storeName, ", ").concat(indexName, ")")));
1152
+ case 10:
1153
+ case "end":
1154
+ return _context18.stop();
1155
+ }
1156
+ }, _callee18, this);
1157
+ }));
1158
+ function existsByIndex(_x16, _x17, _x18) {
1159
+ return _existsByIndex.apply(this, arguments);
1160
+ }
1161
+ return existsByIndex;
1162
+ }()
1163
+ /**
1164
+ * 通过索引获取多条数据
1165
+ * @param {string} storeName - 存储对象名称
1166
+ * @param {string} indexName - 索引名称
1167
+ * @param {string|number} indexValue - 索引值
1168
+ * @returns {Promise<T[]>} 数据数组
1169
+ * @template T
1170
+ */
1171
+ )
1172
+ }, {
1173
+ key: "getAllByIndex",
1174
+ value: (function () {
1175
+ var _getAllByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(storeName, indexName, indexValue) {
1176
+ var _this13 = this;
1177
+ var _storeConfig$indexes3, allData, storeConfig, index;
1178
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1179
+ while (1) switch (_context20.prev = _context20.next) {
1180
+ case 0:
1181
+ if (this.useIndexDB) {
1182
+ _context20.next = 9;
1183
+ break;
1184
+ }
1185
+ _context20.next = 3;
1186
+ return this.getAll(storeName);
1187
+ case 3:
1188
+ allData = _context20.sent;
1189
+ storeConfig = this.stores.find(function (s) {
1190
+ return s.name === storeName;
1191
+ });
1192
+ index = storeConfig === null || storeConfig === void 0 || (_storeConfig$indexes3 = storeConfig.indexes) === null || _storeConfig$indexes3 === void 0 ? void 0 : _storeConfig$indexes3.find(function (i) {
1193
+ return i.name === indexName;
1194
+ });
1195
+ if (index) {
1196
+ _context20.next = 8;
1197
+ break;
1198
+ }
1199
+ return _context20.abrupt("return", []);
1200
+ case 8:
1201
+ return _context20.abrupt("return", allData.filter(function (item) {
1202
+ return item[index.keyPath] === indexValue;
1203
+ }));
1204
+ case 9:
1205
+ return _context20.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1206
+ var results;
1207
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1208
+ while (1) switch (_context19.prev = _context19.next) {
1209
+ case 0:
1210
+ if (_this13.db) {
1211
+ _context19.next = 2;
1212
+ break;
1213
+ }
1214
+ throw new Error('数据库未连接');
1215
+ case 2:
1216
+ _context19.prev = 2;
1217
+ _context19.next = 5;
1218
+ return _this13.db.table(storeName).where(indexName).equals(indexValue).toArray();
1219
+ case 5:
1220
+ results = _context19.sent;
1221
+ return _context19.abrupt("return", results);
1222
+ case 9:
1223
+ _context19.prev = 9;
1224
+ _context19.t0 = _context19["catch"](2);
1225
+ throw new Error('通过索引获取多条数据失败');
1226
+ case 12:
1227
+ case "end":
1228
+ return _context19.stop();
1229
+ }
1230
+ }, _callee19, null, [[2, 9]]);
1231
+ }))(), "getAllByIndex(".concat(storeName, ", ").concat(indexName, ")")));
1232
+ case 10:
1233
+ case "end":
1234
+ return _context20.stop();
1235
+ }
1236
+ }, _callee20, this);
1237
+ }));
1238
+ function getAllByIndex(_x19, _x20, _x21) {
1239
+ return _getAllByIndex.apply(this, arguments);
1240
+ }
1241
+ return getAllByIndex;
1242
+ }()
1243
+ /**
1244
+ * 统计指定存储对象中的数据数量
1245
+ * @param {string} storeName - 存储对象名称
1246
+ * @returns {Promise<number>} 数据数量
1247
+ */
1248
+ )
1249
+ }, {
1250
+ key: "count",
1251
+ value: (function () {
1252
+ var _count = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(storeName) {
1253
+ var _this14 = this;
1254
+ var allData;
1255
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1256
+ while (1) switch (_context22.prev = _context22.next) {
1257
+ case 0:
1258
+ if (this.useIndexDB) {
1259
+ _context22.next = 5;
1260
+ break;
1261
+ }
1262
+ _context22.next = 3;
1263
+ return this.getAll(storeName);
1264
+ case 3:
1265
+ allData = _context22.sent;
1266
+ return _context22.abrupt("return", allData.length);
1267
+ case 5:
1268
+ return _context22.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1269
+ var _count2;
1270
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1271
+ while (1) switch (_context21.prev = _context21.next) {
1272
+ case 0:
1273
+ if (_this14.db) {
1274
+ _context21.next = 2;
1275
+ break;
1276
+ }
1277
+ throw new Error('数据库未连接');
1278
+ case 2:
1279
+ _context21.prev = 2;
1280
+ _context21.next = 5;
1281
+ return _this14.db.table(storeName).count();
1282
+ case 5:
1283
+ _count2 = _context21.sent;
1284
+ return _context21.abrupt("return", _count2);
1285
+ case 9:
1286
+ _context21.prev = 9;
1287
+ _context21.t0 = _context21["catch"](2);
1288
+ throw new Error('统计数据数量失败');
1289
+ case 12:
1290
+ case "end":
1291
+ return _context21.stop();
1292
+ }
1293
+ }, _callee21, null, [[2, 9]]);
1294
+ }))(), "count(".concat(storeName, ")")));
1295
+ case 6:
1296
+ case "end":
1297
+ return _context22.stop();
1298
+ }
1299
+ }, _callee22, this);
1300
+ }));
1301
+ function count(_x22) {
1302
+ return _count.apply(this, arguments);
1303
+ }
1304
+ return count;
1305
+ }()
1306
+ /**
1307
+ * 通过索引统计数据数量
1308
+ * @param {string} storeName - 存储对象名称
1309
+ * @param {string} indexName - 索引名称
1310
+ * @param {string|number} indexValue - 索引值
1311
+ * @returns {Promise<number>} 数据数量
1312
+ */
1313
+ )
1314
+ }, {
1315
+ key: "countByIndex",
1316
+ value: (function () {
1317
+ var _countByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(storeName, indexName, indexValue) {
1318
+ var _this15 = this;
1319
+ var matchingData;
1320
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1321
+ while (1) switch (_context24.prev = _context24.next) {
1322
+ case 0:
1323
+ if (this.useIndexDB) {
1324
+ _context24.next = 5;
1325
+ break;
1326
+ }
1327
+ _context24.next = 3;
1328
+ return this.getAllByIndex(storeName, indexName, indexValue);
1329
+ case 3:
1330
+ matchingData = _context24.sent;
1331
+ return _context24.abrupt("return", matchingData.length);
1332
+ case 5:
1333
+ return _context24.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1334
+ var count;
1335
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1336
+ while (1) switch (_context23.prev = _context23.next) {
1337
+ case 0:
1338
+ if (_this15.db) {
1339
+ _context23.next = 2;
1340
+ break;
1341
+ }
1342
+ throw new Error('数据库未连接');
1343
+ case 2:
1344
+ _context23.prev = 2;
1345
+ _context23.next = 5;
1346
+ return _this15.db.table(storeName).where(indexName).equals(indexValue).count();
1347
+ case 5:
1348
+ count = _context23.sent;
1349
+ return _context23.abrupt("return", count);
1350
+ case 9:
1351
+ _context23.prev = 9;
1352
+ _context23.t0 = _context23["catch"](2);
1353
+ throw new Error('通过索引统计数据数量失败');
1354
+ case 12:
1355
+ case "end":
1356
+ return _context23.stop();
1357
+ }
1358
+ }, _callee23, null, [[2, 9]]);
1359
+ }))(), "countByIndex(".concat(storeName, ", ").concat(indexName, ")")));
1360
+ case 6:
1361
+ case "end":
1362
+ return _context24.stop();
1363
+ }
1364
+ }, _callee24, this);
1365
+ }));
1366
+ function countByIndex(_x23, _x24, _x25) {
1367
+ return _countByIndex.apply(this, arguments);
1368
+ }
1369
+ return countByIndex;
1370
+ }()
1371
+ /**
1372
+ * 获取指定存储对象中的所有数据
1373
+ * @param {string} storeName - 存储对象名称
1374
+ * @returns {Promise<T[]>} 数据数组
1375
+ * @template T
1376
+ */
1377
+ )
1378
+ }, {
1379
+ key: "getAll",
1380
+ value: (function () {
1381
+ var _getAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(storeName) {
1382
+ var _this16 = this;
1383
+ var memStore;
1384
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
1385
+ while (1) switch (_context26.prev = _context26.next) {
1386
+ case 0:
1387
+ if (this.useIndexDB) {
1388
+ _context26.next = 3;
1389
+ break;
1390
+ }
1391
+ // 使用内存存储
1392
+ memStore = this.getMemoryStore(storeName);
1393
+ return _context26.abrupt("return", Array.from(memStore.values()));
1394
+ case 3:
1395
+ return _context26.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
1396
+ var results;
1397
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1398
+ while (1) switch (_context25.prev = _context25.next) {
1399
+ case 0:
1400
+ if (_this16.db) {
1401
+ _context25.next = 2;
1402
+ break;
1403
+ }
1404
+ throw new Error('数据库未连接');
1405
+ case 2:
1406
+ _context25.prev = 2;
1407
+ _context25.next = 5;
1408
+ return _this16.db.table(storeName).toArray();
1409
+ case 5:
1410
+ results = _context25.sent;
1411
+ return _context25.abrupt("return", results);
1412
+ case 9:
1413
+ _context25.prev = 9;
1414
+ _context25.t0 = _context25["catch"](2);
1415
+ _this16.app.logger.addLog({
1416
+ type: 'error',
1417
+ title: "[ IndexDB ] ERROR: - getAll(".concat(storeName, ")"),
1418
+ metadata: {
1419
+ msg: '获取所有数据失败',
1420
+ error: _context25.t0.message
1421
+ }
1422
+ });
1423
+ throw new Error(_context25.t0 === null || _context25.t0 === void 0 ? void 0 : _context25.t0.message);
1424
+ case 13:
1425
+ case "end":
1426
+ return _context25.stop();
1427
+ }
1428
+ }, _callee25, null, [[2, 9]]);
1429
+ }))(), "getAll(".concat(storeName, ")")));
1430
+ case 4:
1431
+ case "end":
1432
+ return _context26.stop();
1433
+ }
1434
+ }, _callee26, this);
1435
+ }));
1436
+ function getAll(_x26) {
1437
+ return _getAll.apply(this, arguments);
1438
+ }
1439
+ return getAll;
1440
+ }()
1441
+ /**
1442
+ * 清空指定存储对象中的所有数据
1443
+ * @param {string} storeName - 存储对象名称
1444
+ * @returns {Promise<boolean>} 清空是否成功
1445
+ */
1446
+ )
1447
+ }, {
1448
+ key: "clear",
1449
+ value: (function () {
1450
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(storeName) {
1451
+ var _this17 = this;
1452
+ var memStore;
1453
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
1454
+ while (1) switch (_context28.prev = _context28.next) {
1455
+ case 0:
1456
+ if (this.useIndexDB) {
1457
+ _context28.next = 4;
1458
+ break;
1459
+ }
1460
+ // 使用内存存储
1461
+ memStore = this.getMemoryStore(storeName);
1462
+ memStore.clear();
1463
+ return _context28.abrupt("return", true);
1464
+ case 4:
1465
+ return _context28.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
1466
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
1467
+ while (1) switch (_context27.prev = _context27.next) {
1468
+ case 0:
1469
+ if (_this17.db) {
1470
+ _context27.next = 2;
1471
+ break;
1472
+ }
1473
+ throw new Error('数据库未连接');
1474
+ case 2:
1475
+ _context27.prev = 2;
1476
+ _context27.next = 5;
1477
+ return _this17.db.table(storeName).clear();
1478
+ case 5:
1479
+ return _context27.abrupt("return", true);
1480
+ case 8:
1481
+ _context27.prev = 8;
1482
+ _context27.t0 = _context27["catch"](2);
1483
+ throw new Error('清空数据失败');
1484
+ case 11:
1485
+ case "end":
1486
+ return _context27.stop();
1487
+ }
1488
+ }, _callee27, null, [[2, 8]]);
1489
+ }))(), "clear(".concat(storeName, ")")));
1490
+ case 5:
1491
+ case "end":
1492
+ return _context28.stop();
1493
+ }
1494
+ }, _callee28, this);
1495
+ }));
1496
+ function clear(_x27) {
1497
+ return _clear.apply(this, arguments);
1498
+ }
1499
+ return clear;
1500
+ }()
1501
+ /**
1502
+ * 关闭数据库连接
1503
+ * 在不再需要使用数据库时调用,释放资源
1504
+ */
1505
+ )
1506
+ }, {
1507
+ key: "close",
1508
+ value: function close() {
1509
+ if (this.db) {
1510
+ this.db.close();
1511
+ this.db = null;
1512
+ }
1513
+ }
1514
+
1515
+ /**
1516
+ * 获取当前使用的存储方式
1517
+ * @returns {'indexDB'|'memory'} 当前使用的存储方式
1518
+ */
1519
+ }, {
1520
+ key: "getCurrentStorage",
1521
+ value: function getCurrentStorage() {
1522
+ return this.useIndexDB ? 'indexDB' : 'memory';
1523
+ }
1524
+ }], [{
1525
+ key: "isSupported",
1526
+ value:
1527
+ /**
1528
+ * 检查环境是否支持 IndexedDB
1529
+ * @returns {boolean} 是否支持 IndexedDB
1530
+ * @private
1531
+ */
1532
+ function isSupported() {
1533
+ return typeof window !== 'undefined' && 'indexedDB' in window;
1534
+ }
1535
+ }]);
1536
+ return IndexDBManager;
1537
+ }();
1538
+ /**
1539
+ * 使用示例:
1540
+ *
1541
+ * // 1. 创建数据库配置
1542
+ * const dbOptions: DBOptions = {
1543
+ * dbName: 'myApp',
1544
+ * version: 1,
1545
+ * stores: [
1546
+ * {
1547
+ * name: 'users',
1548
+ * keyPath: 'id',
1549
+ * indexes: [
1550
+ * { name: 'email', keyPath: 'email', options: { unique: true } },
1551
+ * { name: 'department', keyPath: 'department', options: { unique: false } }
1552
+ * ]
1553
+ * },
1554
+ * {
1555
+ * name: 'products',
1556
+ * keyPath: 'id'
1557
+ * }
1558
+ * ]
1559
+ * };
1560
+ *
1561
+ * // 2. 创建并连接数据库
1562
+ * const db = new IndexDBManager(app, dbOptions);
1563
+ * await db.connect();
1564
+ *
1565
+ * // 3. 添加数据
1566
+ * const user = { id: '1', name: '张三', email: 'zhangsan@example.com', department: 'IT' };
1567
+ * await db.add('users', user);
1568
+ *
1569
+ * // 4. 获取数据
1570
+ * const retrievedUser = await db.get('users', '1');
1571
+ *
1572
+ * // 5. 快速检查数据是否存在(推荐用法)
1573
+ * const userExists = await db.exists('users', '1'); // 返回 true/false,比 get 更高效
1574
+ *
1575
+ * // 6. 通过索引获取数据
1576
+ * const userByEmail = await db.getByIndex('users', 'email', 'zhangsan@example.com');
1577
+ *
1578
+ * // 7. 通过索引检查数据是否存在
1579
+ * const emailExists = await db.existsByIndex('users', 'email', 'zhangsan@example.com');
1580
+ *
1581
+ * // 8. 通过索引获取多条数据
1582
+ * const itUsers = await db.getAllByIndex('users', 'department', 'IT');
1583
+ *
1584
+ * // 9. 统计数据数量
1585
+ * const totalUsers = await db.count('users');
1586
+ * const itUserCount = await db.countByIndex('users', 'department', 'IT');
1587
+ *
1588
+ * // 10. 更新数据
1589
+ * user.name = '张三 (已更新)';
1590
+ * await db.update('users', user);
1591
+ *
1592
+ * // 11. 获取所有数据
1593
+ * const allUsers = await db.getAll('users');
1594
+ *
1595
+ * // 12. 删除数据
1596
+ * await db.delete('users', '1');
1597
+ *
1598
+ * // 13. 清空存储对象
1599
+ * await db.clear('users');
1600
+ *
1601
+ * // 14. 关闭数据库连接
1602
+ * db.close();
1603
+ *
1604
+ * // 15. 检查当前使用的存储方式
1605
+ * const storageType = db.getCurrentStorage(); // 'indexDB' 或 'memory'
1606
+ *
1607
+ * // 性能优化建议:
1608
+ * // - 使用 exists() 而不是 get() 来检查数据是否存在
1609
+ * // - 为常用查询字段创建索引
1610
+ * // - 使用索引查询方法来提高查询效率
1611
+ * // - 批量操作时使用事务(可以考虑后续扩展)
1612
+ *
1613
+ * // 降级方案说明:
1614
+ * // - 当浏览器不支持 IndexedDB 时,会自动使用内存存储 (Map) 作为降级方案
1615
+ * // - 内存存储的数据在页面刷新后会丢失,仅适合临时数据存储
1616
+ * // - 内存存储支持所有 IndexedDB API,包括索引查询
1617
+ * // - 对于需要持久化的数据,请确保浏览器支持 IndexedDB
1618
+ */
1619
+ export default IndexDBManager;