@pisell/core 1.0.61 → 1.0.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/app/app.d.ts CHANGED
@@ -10,6 +10,7 @@ import { TasksManager } from '../tasks';
10
10
  import IndexDBManager, { DBOptions } from '../indexDB';
11
11
  import CMD, { CMDOptions } from "../cmd";
12
12
  import AWS, { AWSOptions } from "../aws";
13
+ import CommunicationManager from '../communicationManager';
13
14
  declare global {
14
15
  interface Window {
15
16
  app: App;
@@ -81,6 +82,7 @@ declare class App {
81
82
  channel: string;
82
83
  [key: string]: string;
83
84
  };
85
+ comm: CommunicationManager;
84
86
  private constructor();
85
87
  static getInstance(options?: AppOptions): App;
86
88
  setGlobalData(globalData: any): void;
package/es/app/app.js CHANGED
@@ -26,6 +26,7 @@ import pubsub from "../pubsub";
26
26
  import { APPEvent } from "./const";
27
27
  import CMD from "../cmd";
28
28
  import AWS from "../aws";
29
+ import CommunicationManager from "../communicationManager";
29
30
  var App = /*#__PURE__*/function () {
30
31
  function App(options) {
31
32
  _classCallCheck(this, App);
@@ -74,6 +75,8 @@ var App = /*#__PURE__*/function () {
74
75
  _defineProperty(this, "constants", {
75
76
  channel: ""
76
77
  });
78
+ // 通信管理
79
+ _defineProperty(this, "comm", void 0);
77
80
  this.plugins = new Map();
78
81
  this.globalData = {};
79
82
  this.router = new RouterManager({}, this);
@@ -94,6 +97,7 @@ var App = /*#__PURE__*/function () {
94
97
  if (options !== null && options !== void 0 && options.constants) {
95
98
  this.constants = options.constants || {};
96
99
  }
100
+ this.comm = new CommunicationManager(this);
97
101
  }
98
102
 
99
103
  // 单例模式
@@ -0,0 +1,59 @@
1
+ import App from '../app';
2
+ /**
3
+ * 插件基础类型,通信插件(如 socket、ably)需符合此结构
4
+ * 具体插件可扩展自有方法以支持链式调用
5
+ */
6
+ export interface CommunicationPlugin {
7
+ destroy?: () => Promise<void>;
8
+ [key: string]: any;
9
+ }
10
+ /**
11
+ * 插件注册选项
12
+ */
13
+ export interface RegisterOptions {
14
+ /**
15
+ * 是否强制覆盖已存在的同名插件
16
+ * @default false
17
+ */
18
+ force?: boolean;
19
+ }
20
+ /**
21
+ * 通信管理器:支持注入、获取、移除多种通信插件(如 socket、ably 等)
22
+ * 管理器自身方法支持链式调用
23
+ */
24
+ export default class CommunicationManager {
25
+ private app;
26
+ private plugins;
27
+ constructor(app: App);
28
+ /**
29
+ * 注入插件
30
+ * @param name 插件名称,如 'socket'、'ably'
31
+ * @param plugin 插件实例
32
+ * @param options 注册选项,可通过 force 强制覆盖已存在的插件
33
+ * @throws 当插件已存在且未设置 force 时抛出错误
34
+ */
35
+ register<T extends CommunicationPlugin>(name: string, plugin: T, options?: RegisterOptions): void;
36
+ /**
37
+ * 根据名称获取插件,可对返回值进行链式调用(由插件自身实现)
38
+ * @param name 插件名称
39
+ * @returns 插件实例,未注册时返回 undefined
40
+ */
41
+ getPlugin<T extends CommunicationPlugin = CommunicationPlugin>(name: string): T | undefined;
42
+ /**
43
+ * 移除指定插件
44
+ * @param name 插件名称
45
+ */
46
+ remove(name: string): Promise<void>;
47
+ /**
48
+ * 移除所有插件
49
+ */
50
+ removeAll(): Promise<void>;
51
+ /**
52
+ * 检查是否已注册指定插件
53
+ */
54
+ has(name: string): boolean;
55
+ /**
56
+ * 获取已注册的插件名称列表
57
+ */
58
+ getPluginNames(): string[];
59
+ }
@@ -0,0 +1,174 @@
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 _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; }
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
+ 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); } }
7
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
10
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
11
+ /**
12
+ * 插件基础类型,通信插件(如 socket、ably)需符合此结构
13
+ * 具体插件可扩展自有方法以支持链式调用
14
+ */
15
+ /**
16
+ * 插件注册选项
17
+ */
18
+ /**
19
+ * 通信管理器:支持注入、获取、移除多种通信插件(如 socket、ably 等)
20
+ * 管理器自身方法支持链式调用
21
+ */
22
+ var CommunicationManager = /*#__PURE__*/function () {
23
+ function CommunicationManager(app) {
24
+ _classCallCheck(this, CommunicationManager);
25
+ _defineProperty(this, "app", void 0);
26
+ _defineProperty(this, "plugins", new Map());
27
+ this.app = app;
28
+ }
29
+
30
+ /**
31
+ * 注入插件
32
+ * @param name 插件名称,如 'socket'、'ably'
33
+ * @param plugin 插件实例
34
+ * @param options 注册选项,可通过 force 强制覆盖已存在的插件
35
+ * @throws 当插件已存在且未设置 force 时抛出错误
36
+ */
37
+ _createClass(CommunicationManager, [{
38
+ key: "register",
39
+ value: function register(name, plugin, options) {
40
+ if (!(options !== null && options !== void 0 && options.force) && this.plugins.has(name)) {
41
+ var msg = "CommunicationManager: \u63D2\u4EF6 \"".concat(name, "\" \u5DF2\u6CE8\u518C");
42
+ this.app.logger.addLog({
43
+ type: 'warning',
44
+ title: msg
45
+ });
46
+ throw new Error(msg);
47
+ }
48
+ this.plugins.set(name, plugin);
49
+ this.app.logger.addLog({
50
+ type: 'info',
51
+ title: "CommunicationManager: \u6CE8\u518C\u63D2\u4EF6 \"".concat(name, "\" \u6210\u529F")
52
+ });
53
+ }
54
+
55
+ /**
56
+ * 根据名称获取插件,可对返回值进行链式调用(由插件自身实现)
57
+ * @param name 插件名称
58
+ * @returns 插件实例,未注册时返回 undefined
59
+ */
60
+ }, {
61
+ key: "getPlugin",
62
+ value: function getPlugin(name) {
63
+ return this.plugins.get(name);
64
+ }
65
+
66
+ /**
67
+ * 移除指定插件
68
+ * @param name 插件名称
69
+ */
70
+ }, {
71
+ key: "remove",
72
+ value: (function () {
73
+ var _remove = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(name) {
74
+ var msg, plugin;
75
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
76
+ while (1) switch (_context.prev = _context.next) {
77
+ case 0:
78
+ msg = "CommunicationManager: \u79FB\u9664\u63D2\u4EF6 \"".concat(name, "\"");
79
+ this.app.logger.addLog({
80
+ type: 'info',
81
+ title: msg
82
+ });
83
+ plugin = this.getPlugin(name);
84
+ if (!(plugin && plugin.destroy)) {
85
+ _context.next = 6;
86
+ break;
87
+ }
88
+ _context.next = 6;
89
+ return plugin.destroy();
90
+ case 6:
91
+ this.plugins.delete(name);
92
+ this.app.logger.addLog({
93
+ type: 'info',
94
+ title: "".concat(msg, " \u6210\u529F")
95
+ });
96
+ case 8:
97
+ case "end":
98
+ return _context.stop();
99
+ }
100
+ }, _callee, this);
101
+ }));
102
+ function remove(_x) {
103
+ return _remove.apply(this, arguments);
104
+ }
105
+ return remove;
106
+ }()
107
+ /**
108
+ * 移除所有插件
109
+ */
110
+ )
111
+ }, {
112
+ key: "removeAll",
113
+ value: (function () {
114
+ var _removeAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
115
+ var msg, promises;
116
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
117
+ while (1) switch (_context2.prev = _context2.next) {
118
+ case 0:
119
+ msg = "CommunicationManager: \u79FB\u9664\u6240\u6709\u63D2\u4EF6";
120
+ this.app.logger.addLog({
121
+ type: 'info',
122
+ title: msg
123
+ });
124
+ promises = [];
125
+ this.plugins.forEach(function (plugin) {
126
+ if (plugin !== null && plugin !== void 0 && plugin.destroy) {
127
+ promises.push(plugin.destroy());
128
+ }
129
+ });
130
+ if (!(promises.length > 0)) {
131
+ _context2.next = 7;
132
+ break;
133
+ }
134
+ _context2.next = 7;
135
+ return Promise.all(promises);
136
+ case 7:
137
+ this.plugins.clear();
138
+ this.app.logger.addLog({
139
+ type: 'info',
140
+ title: "".concat(msg, " \u6210\u529F")
141
+ });
142
+ case 9:
143
+ case "end":
144
+ return _context2.stop();
145
+ }
146
+ }, _callee2, this);
147
+ }));
148
+ function removeAll() {
149
+ return _removeAll.apply(this, arguments);
150
+ }
151
+ return removeAll;
152
+ }()
153
+ /**
154
+ * 检查是否已注册指定插件
155
+ */
156
+ )
157
+ }, {
158
+ key: "has",
159
+ value: function has(name) {
160
+ return this.plugins.has(name);
161
+ }
162
+
163
+ /**
164
+ * 获取已注册的插件名称列表
165
+ */
166
+ }, {
167
+ key: "getPluginNames",
168
+ value: function getPluginNames() {
169
+ return Array.from(this.plugins.keys());
170
+ }
171
+ }]);
172
+ return CommunicationManager;
173
+ }();
174
+ export { CommunicationManager as default };
package/es/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export { default as pubsub } from './pubsub';
5
5
  export { default as socket } from './socket';
6
6
  export * from './applicationManager';
7
7
  export * from './app';
8
+ export * from './communicationManager';
package/es/index.js CHANGED
@@ -6,4 +6,5 @@ export { default as models } from "./models";
6
6
  export { default as pubsub } from "./pubsub";
7
7
  export { default as socket } from "./socket";
8
8
  export * from "./applicationManager";
9
- export * from "./app";
9
+ export * from "./app";
10
+ export * from "./communicationManager";
@@ -107,6 +107,15 @@ declare class IndexDBManager {
107
107
  * flush 防抖 update
108
108
  */
109
109
  flushDebouncedUpdate(storeName: string): Promise<void>;
110
+ /**
111
+ * 批量添加数据到指定的存储对象
112
+ * @param {string} storeName - 存储对象名称
113
+ * @param {T[]} dataList - 要批量添加的数据数组
114
+ * @param {boolean} [log=false] - 是否记录日志
115
+ * @returns {Promise<T[]>} 成功添加的数据数组
116
+ * @template T
117
+ */
118
+ bulkAdd<T>(storeName: string, dataList: T[], log?: boolean): Promise<T[]>;
110
119
  /**
111
120
  * 添加数据到指定的存储对象
112
121
  * @param {string} storeName - 存储对象名称
@@ -132,6 +141,15 @@ declare class IndexDBManager {
132
141
  * @template T
133
142
  */
134
143
  get<T>(storeName: string, key: string | number, log?: boolean): Promise<T | null>;
144
+ /**
145
+ * 批量更新指定存储对象中的数据
146
+ * @param {string} storeName - 存储对象名称
147
+ * @param {T[]} dataList - 要批量更新的数据数组
148
+ * @param {boolean} [log=false] - 是否记录日志
149
+ * @returns {Promise<T[]>} 更新后的数据数组
150
+ * @template T
151
+ */
152
+ bulkUpdate<T>(storeName: string, dataList: T[], log?: boolean): Promise<T[]>;
135
153
  /**
136
154
  * 更新指定存储对象中的数据
137
155
  * @param {string} storeName - 存储对象名称
@@ -141,6 +159,14 @@ declare class IndexDBManager {
141
159
  * @template T
142
160
  */
143
161
  update<T>(storeName: string, data: T, log?: boolean): Promise<T>;
162
+ /**
163
+ * 批量删除指定存储对象中的数据
164
+ * @param {string} storeName - 存储对象名称
165
+ * @param {(string|number)[]} keys - 数据主键数组
166
+ * @param {boolean} [log=false] - 是否记录日志
167
+ * @returns {Promise<boolean>} 删除是否成功
168
+ */
169
+ bulkDelete(storeName: string, keys: (string | number)[], log?: boolean): Promise<boolean>;
144
170
  /**
145
171
  * 删除指定存储对象中的数据
146
172
  * @param {string} storeName - 存储对象名称
@@ -243,6 +269,14 @@ declare class IndexDBManager {
243
269
  * const user = { id: '1', name: '张三', email: 'zhangsan@example.com', department: 'IT' };
244
270
  * await db.add('users', user);
245
271
  *
272
+ * // 3.1 批量添加数据
273
+ * const users = [
274
+ * { id: '2', name: '李四', email: 'lisi@example.com', department: 'IT' },
275
+ * { id: '3', name: '王五', email: 'wangwu@example.com', department: 'HR' },
276
+ * { id: '4', name: '赵六', email: 'zhaoliu@example.com', department: 'IT' }
277
+ * ];
278
+ * await db.bulkAdd('users', users);
279
+ *
246
280
  * // 4. 获取数据
247
281
  * const retrievedUser = await db.get('users', '1');
248
282
  *
@@ -266,12 +300,22 @@ declare class IndexDBManager {
266
300
  * user.name = '张三 (已更新)';
267
301
  * await db.update('users', user);
268
302
  *
303
+ * // 10.1 批量更新数据
304
+ * const updatedUsers = [
305
+ * { id: '2', name: '李四 (已更新)', email: 'lisi@example.com', department: 'IT' },
306
+ * { id: '3', name: '王五 (已更新)', email: 'wangwu@example.com', department: 'Sales' }
307
+ * ];
308
+ * await db.bulkUpdate('users', updatedUsers);
309
+ *
269
310
  * // 11. 获取所有数据
270
311
  * const allUsers = await db.getAll('users');
271
312
  *
272
313
  * // 12. 删除数据
273
314
  * await db.delete('users', '1');
274
315
  *
316
+ * // 12.1 批量删除数据
317
+ * await db.bulkDelete('users', ['2', '3', '4']);
318
+ *
275
319
  * // 13. 清空存储对象
276
320
  * await db.clear('users');
277
321
  *
@@ -285,7 +329,8 @@ declare class IndexDBManager {
285
329
  * // - 使用 exists() 而不是 get() 来检查数据是否存在
286
330
  * // - 为常用查询字段创建索引
287
331
  * // - 使用索引查询方法来提高查询效率
288
- * // - 批量操作时使用事务(可以考虑后续扩展)
332
+ * // - 批量操作时优先使用 bulkAdd/bulkUpdate/bulkDelete,比循环调用单条方法性能更好
333
+ * // - 批量操作会自动在单个事务中完成,保证原子性
289
334
  *
290
335
  * // 降级方案说明:
291
336
  * // - 当浏览器不支持 IndexedDB 时,会自动使用内存存储 (Map) 作为降级方案