@pisell/core 1.0.61 → 1.0.63

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.
@@ -19,6 +19,8 @@ import { isString, isNumber } from "@pisell/utils";
19
19
  import en from "./en";
20
20
  import zhCN from "./zh-CN";
21
21
  import zhHK from "./zh-HK";
22
+ import ja from "./ja";
23
+ import pt from "./pt";
22
24
  import original from "./original";
23
25
  export var Locales = /*#__PURE__*/function () {
24
26
  function Locales(app, options) {
@@ -28,7 +30,7 @@ export var Locales = /*#__PURE__*/function () {
28
30
  // 当前语言 本地语言 > 英文语言包
29
31
  _defineProperty(this, "locale", en.locale);
30
32
  // 语言包
31
- _defineProperty(this, "library", [original, en, zhCN, zhHK].reduce(function (pre, cur) {
33
+ _defineProperty(this, "library", [original, en, zhCN, zhHK, ja, pt].reduce(function (pre, cur) {
32
34
  pre[cur.locale] = cur;
33
35
  return pre;
34
36
  }, {}));
@@ -36,7 +38,8 @@ export var Locales = /*#__PURE__*/function () {
36
38
  return _this.locale;
37
39
  });
38
40
  _defineProperty(this, "getCurrentTexts", function (locale) {
39
- return _this.library[locale || _this.locale].translations;
41
+ var _this$library, _this$library$en;
42
+ return ((_this$library = _this.library[locale || _this.locale]) === null || _this$library === void 0 ? void 0 : _this$library.translations) || ((_this$library$en = _this.library.en) === null || _this$library$en === void 0 ? void 0 : _this$library$en.translations) || {};
40
43
  });
41
44
  _defineProperty(this, "setLocale", function (locale) {
42
45
  var reload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -47,8 +50,8 @@ export var Locales = /*#__PURE__*/function () {
47
50
  }
48
51
  });
49
52
  _defineProperty(this, "getText", function (id, locale) {
50
- var _this$getCurrentTexts;
51
- return ((_this$getCurrentTexts = _this.getCurrentTexts(locale)) === null || _this$getCurrentTexts === void 0 ? void 0 : _this$getCurrentTexts[id]) || id;
53
+ var _this$getCurrentTexts, _this$getCurrentTexts2;
54
+ return ((_this$getCurrentTexts = _this.getCurrentTexts(locale)) === null || _this$getCurrentTexts === void 0 ? void 0 : _this$getCurrentTexts[id]) || ((_this$getCurrentTexts2 = _this.getCurrentTexts('en')) === null || _this$getCurrentTexts2 === void 0 ? void 0 : _this$getCurrentTexts2[id]) || id;
52
55
  });
53
56
  _defineProperty(this, "isCN", function () {
54
57
  var locale = _this.getLocale();
@@ -157,7 +160,7 @@ export var Locales = /*#__PURE__*/function () {
157
160
  if (typeof text === 'string') {
158
161
  return text;
159
162
  }
160
- return text[primary] || text["original"] || text["en"] || text["zh-CN"] || text["zh-HK"];
163
+ return text[primary] || text["original"] || text["en"] || text["zh-CN"] || text["zh-HK"] || text['ja'] || text['pt'];
161
164
  });
162
165
  _defineProperty(this, "getLibraryByData", function (data) {
163
166
  return data.reduce(function (pre, next) {
@@ -178,7 +181,7 @@ export var Locales = /*#__PURE__*/function () {
178
181
  });
179
182
  this.app = app;
180
183
  this.locale = (options === null || options === void 0 ? void 0 : options.locale) || this.app.storage.getStorage('locale') || en.locale;
181
- this.library = (options === null || options === void 0 ? void 0 : options.library) || [original, en, zhCN, zhHK].reduce(function (pre, cur) {
184
+ this.library = (options === null || options === void 0 ? void 0 : options.library) || [original, en, zhCN, zhHK, ja, pt].reduce(function (pre, cur) {
182
185
  pre[cur.locale] = cur;
183
186
  return pre;
184
187
  }, {});
@@ -0,0 +1,3 @@
1
+ import { LibraryItem } from './type';
2
+ declare const _default: LibraryItem;
3
+ export default _default;
@@ -0,0 +1,5 @@
1
+ export default {
2
+ "locale": "ja",
3
+ "name": "japanese",
4
+ "translations": {}
5
+ };
@@ -0,0 +1,3 @@
1
+ import { LibraryItem } from './type';
2
+ declare const _default: LibraryItem;
3
+ export default _default;
@@ -0,0 +1,5 @@
1
+ export default {
2
+ "locale": "pt",
3
+ "name": "portuguese",
4
+ "translations": {}
5
+ };
@@ -20,9 +20,9 @@ export declare class RouterManager {
20
20
  get(name: string): RouteType;
21
21
  has(name: string): boolean;
22
22
  remove(name: string): void;
23
- renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean | React.ReactFragment | JSX.Element | null | undefined;
23
+ renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean | React.JSX.Element | Iterable<React.ReactNode> | null | undefined;
24
24
  getPageByRoute(route: string): ApplicationInterface | undefined;
25
25
  getRouterComponent({ fallback }: {
26
26
  fallback?: React.ReactNode;
27
- }): JSX.Element[];
27
+ }): React.JSX.Element[];
28
28
  }
@@ -108,7 +108,7 @@ export declare class TasksManager {
108
108
  */
109
109
  getQueueStatus(module: string, queueId: string): {
110
110
  isRunning: boolean;
111
- status: "uncompleted" | "completed";
111
+ status: "completed" | "uncompleted";
112
112
  progress: {
113
113
  total: number;
114
114
  completed: number;
package/lib/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/lib/app/app.js CHANGED
@@ -51,6 +51,7 @@ var import_pubsub = __toESM(require("../pubsub"));
51
51
  var import_const = require("./const");
52
52
  var import_cmd = __toESM(require("../cmd"));
53
53
  var import_aws = __toESM(require("../aws"));
54
+ var import_communicationManager = __toESM(require("../communicationManager"));
54
55
  var App = class _App {
55
56
  // 实例
56
57
  static instance;
@@ -99,6 +100,8 @@ var App = class _App {
99
100
  constants = {
100
101
  channel: ""
101
102
  };
103
+ // 通信管理
104
+ comm;
102
105
  constructor(options) {
103
106
  this.plugins = /* @__PURE__ */ new Map();
104
107
  this.globalData = {};
@@ -120,6 +123,7 @@ var App = class _App {
120
123
  if (options == null ? void 0 : options.constants) {
121
124
  this.constants = options.constants || {};
122
125
  }
126
+ this.comm = new import_communicationManager.default(this);
123
127
  }
124
128
  // 单例模式
125
129
  static getInstance(options) {
@@ -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,102 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/communicationManager/index.ts
20
+ var communicationManager_exports = {};
21
+ __export(communicationManager_exports, {
22
+ default: () => CommunicationManager
23
+ });
24
+ module.exports = __toCommonJS(communicationManager_exports);
25
+ var CommunicationManager = class {
26
+ app;
27
+ plugins = /* @__PURE__ */ new Map();
28
+ constructor(app) {
29
+ this.app = app;
30
+ }
31
+ /**
32
+ * 注入插件
33
+ * @param name 插件名称,如 'socket'、'ably'
34
+ * @param plugin 插件实例
35
+ * @param options 注册选项,可通过 force 强制覆盖已存在的插件
36
+ * @throws 当插件已存在且未设置 force 时抛出错误
37
+ */
38
+ register(name, plugin, options) {
39
+ if (!(options == null ? void 0 : options.force) && this.plugins.has(name)) {
40
+ const msg = `CommunicationManager: 插件 "${name}" 已注册`;
41
+ this.app.logger.addLog({ type: "warning", title: msg });
42
+ throw new Error(msg);
43
+ }
44
+ this.plugins.set(name, plugin);
45
+ this.app.logger.addLog({
46
+ type: "info",
47
+ title: `CommunicationManager: 注册插件 "${name}" 成功`
48
+ });
49
+ }
50
+ /**
51
+ * 根据名称获取插件,可对返回值进行链式调用(由插件自身实现)
52
+ * @param name 插件名称
53
+ * @returns 插件实例,未注册时返回 undefined
54
+ */
55
+ getPlugin(name) {
56
+ return this.plugins.get(name);
57
+ }
58
+ /**
59
+ * 移除指定插件
60
+ * @param name 插件名称
61
+ */
62
+ async remove(name) {
63
+ const msg = `CommunicationManager: 移除插件 "${name}"`;
64
+ this.app.logger.addLog({ type: "info", title: msg });
65
+ const plugin = this.getPlugin(name);
66
+ if (plugin && plugin.destroy) {
67
+ await plugin.destroy();
68
+ }
69
+ this.plugins.delete(name);
70
+ this.app.logger.addLog({ type: "info", title: `${msg} 成功` });
71
+ }
72
+ /**
73
+ * 移除所有插件
74
+ */
75
+ async removeAll() {
76
+ const msg = `CommunicationManager: 移除所有插件`;
77
+ this.app.logger.addLog({ type: "info", title: msg });
78
+ const promises = [];
79
+ this.plugins.forEach((plugin) => {
80
+ if (plugin == null ? void 0 : plugin.destroy) {
81
+ promises.push(plugin.destroy());
82
+ }
83
+ });
84
+ if (promises.length > 0) {
85
+ await Promise.all(promises);
86
+ }
87
+ this.plugins.clear();
88
+ this.app.logger.addLog({ type: "info", title: `${msg} 成功` });
89
+ }
90
+ /**
91
+ * 检查是否已注册指定插件
92
+ */
93
+ has(name) {
94
+ return this.plugins.has(name);
95
+ }
96
+ /**
97
+ * 获取已注册的插件名称列表
98
+ */
99
+ getPluginNames() {
100
+ return Array.from(this.plugins.keys());
101
+ }
102
+ };
@@ -21,6 +21,6 @@ export declare class History {
21
21
  externalPage: (path: string) => void;
22
22
  goLogin: () => any;
23
23
  getQuery: () => {
24
- [k: string]: string;
24
+ [k: string]: any;
25
25
  };
26
26
  }
package/lib/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/lib/index.js CHANGED
@@ -44,6 +44,7 @@ var import_pubsub = __toESM(require("./pubsub"));
44
44
  var import_socket = __toESM(require("./socket"));
45
45
  __reExport(src_exports, require("./applicationManager"), module.exports);
46
46
  __reExport(src_exports, require("./app"), module.exports);
47
+ __reExport(src_exports, require("./communicationManager"), module.exports);
47
48
  // Annotate the CommonJS export names for ESM import in node:
48
49
  0 && (module.exports = {
49
50
  hooks,
@@ -52,5 +53,6 @@ __reExport(src_exports, require("./app"), module.exports);
52
53
  request,
53
54
  socket,
54
55
  ...require("./applicationManager"),
55
- ...require("./app")
56
+ ...require("./app"),
57
+ ...require("./communicationManager")
56
58
  });
@@ -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) 作为降级方案
@@ -338,6 +338,84 @@ var IndexDBManager = class _IndexDBManager {
338
338
  this.debouncedUpdateFlushing.delete(storeName);
339
339
  }
340
340
  }
341
+ /**
342
+ * 批量添加数据到指定的存储对象
343
+ * @param {string} storeName - 存储对象名称
344
+ * @param {T[]} dataList - 要批量添加的数据数组
345
+ * @param {boolean} [log=false] - 是否记录日志
346
+ * @returns {Promise<T[]>} 成功添加的数据数组
347
+ * @template T
348
+ */
349
+ async bulkAdd(storeName, dataList, log = false) {
350
+ if (!dataList || dataList.length === 0) {
351
+ return [];
352
+ }
353
+ if (!this.useIndexDB) {
354
+ const storeConfig = this.stores.find((s) => s.name === storeName);
355
+ const keyPath = (storeConfig == null ? void 0 : storeConfig.keyPath) || "id";
356
+ const memStore = this.getMemoryStore(storeName);
357
+ dataList.forEach((data) => {
358
+ const key = data[keyPath];
359
+ memStore.set(key, data);
360
+ });
361
+ return dataList;
362
+ }
363
+ const uuid = `[ IndexDB ] BULK_ADD: - ${storeName} - ${(0, import_dayjs.default)().valueOf()}`;
364
+ if (log) {
365
+ this.app.logger.addLog({
366
+ type: "info",
367
+ title: uuid,
368
+ metadata: {
369
+ msg: "批量添加数据前",
370
+ count: dataList.length
371
+ }
372
+ });
373
+ }
374
+ return this.withTimeout(
375
+ (async () => {
376
+ if (!this.db) {
377
+ if (log) {
378
+ this.app.logger.addLog({
379
+ type: "error",
380
+ title: uuid,
381
+ metadata: {
382
+ msg: "批量添加数据前 数据库未连接",
383
+ count: dataList.length
384
+ }
385
+ });
386
+ }
387
+ throw new Error("数据库未连接");
388
+ }
389
+ try {
390
+ await this.db.table(storeName).bulkAdd(dataList);
391
+ if (log) {
392
+ this.app.logger.addLog({
393
+ type: "info",
394
+ title: uuid,
395
+ metadata: {
396
+ msg: "批量添加成功",
397
+ count: dataList.length
398
+ }
399
+ });
400
+ }
401
+ return dataList;
402
+ } catch (error) {
403
+ const hasExistingData = ((error == null ? void 0 : error.message) || "").includes("exists") || ((error == null ? void 0 : error.message) || "").includes("Key already exists");
404
+ this.app.logger.addLog({
405
+ type: hasExistingData ? "info" : "error",
406
+ title: uuid,
407
+ metadata: {
408
+ msg: "批量添加数据失败",
409
+ count: dataList.length,
410
+ error: error.message
411
+ }
412
+ });
413
+ throw new Error(error == null ? void 0 : error.message);
414
+ }
415
+ })(),
416
+ `bulkAdd(${storeName})`
417
+ );
418
+ }
341
419
  /**
342
420
  * 添加数据到指定的存储对象
343
421
  * @param {string} storeName - 存储对象名称
@@ -463,6 +541,83 @@ var IndexDBManager = class _IndexDBManager {
463
541
  `get(${storeName})`
464
542
  );
465
543
  }
544
+ /**
545
+ * 批量更新指定存储对象中的数据
546
+ * @param {string} storeName - 存储对象名称
547
+ * @param {T[]} dataList - 要批量更新的数据数组
548
+ * @param {boolean} [log=false] - 是否记录日志
549
+ * @returns {Promise<T[]>} 更新后的数据数组
550
+ * @template T
551
+ */
552
+ async bulkUpdate(storeName, dataList, log = false) {
553
+ if (!dataList || dataList.length === 0) {
554
+ return [];
555
+ }
556
+ if (!this.useIndexDB) {
557
+ const storeConfig = this.stores.find((s) => s.name === storeName);
558
+ const keyPath = (storeConfig == null ? void 0 : storeConfig.keyPath) || "id";
559
+ const memStore = this.getMemoryStore(storeName);
560
+ dataList.forEach((data) => {
561
+ const key = data[keyPath];
562
+ memStore.set(key, data);
563
+ });
564
+ return dataList;
565
+ }
566
+ const uuid = `[ IndexDB ] BULK_UPDATE: - ${storeName} - ${(0, import_dayjs.default)().valueOf()}`;
567
+ if (log) {
568
+ this.app.logger.addLog({
569
+ type: "info",
570
+ title: uuid,
571
+ metadata: {
572
+ msg: "批量更新数据前",
573
+ count: dataList.length
574
+ }
575
+ });
576
+ }
577
+ return this.withTimeout(
578
+ (async () => {
579
+ if (!this.db) {
580
+ if (log) {
581
+ this.app.logger.addLog({
582
+ type: "error",
583
+ title: uuid,
584
+ metadata: {
585
+ msg: "批量更新数据前 数据库未连接",
586
+ count: dataList.length
587
+ }
588
+ });
589
+ }
590
+ throw new Error("数据库未连接");
591
+ }
592
+ try {
593
+ await this.db.table(storeName).bulkPut(dataList);
594
+ if (log) {
595
+ this.app.logger.addLog({
596
+ type: "info",
597
+ title: uuid,
598
+ metadata: {
599
+ msg: "批量更新成功",
600
+ count: dataList.length
601
+ }
602
+ });
603
+ }
604
+ return dataList;
605
+ } catch (error) {
606
+ this.app.logger.addLog({
607
+ type: "error",
608
+ title: uuid,
609
+ metadata: {
610
+ msg: "批量更新数据失败",
611
+ count: dataList.length,
612
+ error: error.message
613
+ }
614
+ });
615
+ throw new Error(error == null ? void 0 : error.message);
616
+ }
617
+ })(),
618
+ `bulkUpdate(${storeName})`
619
+ );
620
+ }
466
621
  /**
467
622
  * 更新指定存储对象中的数据
468
623
  * @param {string} storeName - 存储对象名称
@@ -512,6 +667,77 @@ var IndexDBManager = class _IndexDBManager {
512
667
  `update(${storeName})`
513
668
  );
514
669
  }
670
+ /**
671
+ * 批量删除指定存储对象中的数据
672
+ * @param {string} storeName - 存储对象名称
673
+ * @param {(string|number)[]} keys - 数据主键数组
674
+ * @param {boolean} [log=false] - 是否记录日志
675
+ * @returns {Promise<boolean>} 删除是否成功
676
+ */
677
+ async bulkDelete(storeName, keys, log = false) {
678
+ if (!keys || keys.length === 0) {
679
+ return true;
680
+ }
681
+ if (!this.useIndexDB) {
682
+ const memStore = this.getMemoryStore(storeName);
683
+ keys.forEach((key) => memStore.delete(key));
684
+ return true;
685
+ }
686
+ const uuid = `[ IndexDB ] BULK_DELETE: - ${storeName} - ${(0, import_dayjs.default)().valueOf()}`;
687
+ if (log) {
688
+ this.app.logger.addLog({
689
+ type: "info",
690
+ title: uuid,
691
+ metadata: {
692
+ msg: "批量删除数据前",
693
+ count: keys.length
694
+ }
695
+ });
696
+ }
697
+ return this.withTimeout(
698
+ (async () => {
699
+ if (!this.db) {
700
+ if (log) {
701
+ this.app.logger.addLog({
702
+ type: "error",
703
+ title: uuid,
704
+ metadata: {
705
+ msg: "批量删除数据前 数据库未连接",
706
+ count: keys.length
707
+ }
708
+ });
709
+ }
710
+ throw new Error("数据库未连接");
711
+ }
712
+ try {
713
+ await this.db.table(storeName).bulkDelete(keys);
714
+ if (log) {
715
+ this.app.logger.addLog({
716
+ type: "info",
717
+ title: uuid,
718
+ metadata: {
719
+ msg: "批量删除成功",
720
+ count: keys.length
721
+ }
722
+ });
723
+ }
724
+ return true;
725
+ } catch (error) {
726
+ this.app.logger.addLog({
727
+ type: "error",
728
+ title: uuid,
729
+ metadata: {
730
+ msg: "批量删除数据失败",
731
+ count: keys.length,
732
+ error: error.message
733
+ }
734
+ });
735
+ throw new Error(error == null ? void 0 : error.message);
736
+ }
737
+ })(),
738
+ `bulkDelete(${storeName})`
739
+ );
740
+ }
515
741
  /**
516
742
  * 删除指定存储对象中的数据
517
743
  * @param {string} storeName - 存储对象名称