@pisell/core 1.0.50 → 1.0.51

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 (59) hide show
  1. package/es/app/app.d.ts +7 -7
  2. package/es/app/index.d.ts +1 -1
  3. package/es/applicationManager/application.d.ts +2 -2
  4. package/es/cmd/const.d.ts +5 -5
  5. package/es/hooks/useStore/index.d.ts +1 -1
  6. package/es/indexDB/index.d.ts +28 -0
  7. package/es/indexDB/index.js +663 -314
  8. package/es/locales/type.d.ts +3 -3
  9. package/es/logger/index.d.ts +1 -1
  10. package/es/models/index.d.ts +4 -4
  11. package/es/pubsub/index.d.ts +1 -1
  12. package/es/request/cache.d.ts +1 -1
  13. package/es/request/cache.js +2 -2
  14. package/es/request/pisell2Request.d.ts +1 -1
  15. package/es/request/type.d.ts +1 -1
  16. package/es/routes/index.d.ts +2 -2
  17. package/es/socket/types.d.ts +1 -1
  18. package/es/tasks/index.d.ts +1 -1
  19. package/es/tasks/type.d.ts +4 -4
  20. package/es/utils/adaptiveThrottle/index.d.ts +2 -2
  21. package/es/variables/index.d.ts +3 -3
  22. package/lib/app/app.d.ts +7 -7
  23. package/lib/app/index.d.ts +1 -1
  24. package/lib/applicationManager/application.d.ts +2 -2
  25. package/lib/aws/index.js +3 -0
  26. package/lib/cmd/const.d.ts +5 -5
  27. package/lib/cmd/const.js +5 -5
  28. package/lib/cmd/index.js +2 -0
  29. package/lib/cookie/index.js +2 -4
  30. package/lib/data/index.js +3 -0
  31. package/lib/hooks/useStore/index.d.ts +1 -1
  32. package/lib/indexDB/index.d.ts +28 -0
  33. package/lib/indexDB/index.js +157 -1
  34. package/lib/locales/index.js +95 -94
  35. package/lib/locales/type.d.ts +3 -3
  36. package/lib/logger/index.d.ts +1 -1
  37. package/lib/models/index.d.ts +4 -4
  38. package/lib/pubsub/index.d.ts +1 -1
  39. package/lib/pubsub/index.js +1 -3
  40. package/lib/request/cache.d.ts +1 -1
  41. package/lib/request/cache.js +2 -2
  42. package/lib/request/pisell2Request.d.ts +1 -1
  43. package/lib/request/type.d.ts +1 -1
  44. package/lib/routes/index.d.ts +2 -2
  45. package/lib/routes/index.js +3 -1
  46. package/lib/socket/components/SocketMonitorPage.js +6 -12
  47. package/lib/socket/heartbeat.js +10 -5
  48. package/lib/socket/index.js +1 -3
  49. package/lib/socket/monitor.js +26 -24
  50. package/lib/socket/reconnect.js +10 -3
  51. package/lib/socket/socket.js +12 -10
  52. package/lib/socket/types.d.ts +1 -1
  53. package/lib/storage/index.js +25 -24
  54. package/lib/tasks/index.d.ts +1 -1
  55. package/lib/tasks/index.js +333 -329
  56. package/lib/tasks/type.d.ts +4 -4
  57. package/lib/utils/adaptiveThrottle/index.d.ts +2 -2
  58. package/lib/variables/index.d.ts +3 -3
  59. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
- export type Locale = 'original' | 'en' | 'zh-CN' | 'zh-HK' | string;
2
- export type MultiLanguage = {
1
+ export declare type Locale = 'original' | 'en' | 'zh-CN' | 'zh-HK' | string;
2
+ export declare type MultiLanguage = {
3
3
  [key in Locale]: string;
4
4
  };
5
5
  export interface LibraryItem {
@@ -16,4 +16,4 @@ export interface LocaleConfig {
16
16
  [key in Locale]: LibraryItem;
17
17
  };
18
18
  }
19
- export type LoadLibraryByUrlParams = (string | Promise<LibraryItem> | (() => Promise<LibraryItem>) | LibraryItem)[];
19
+ export declare type LoadLibraryByUrlParams = (string | Promise<LibraryItem> | (() => Promise<LibraryItem>) | LibraryItem)[];
@@ -1,5 +1,5 @@
1
1
  import App from "../app";
2
- export type LogConsoleType = "info" | "warning" | "error" | "debug";
2
+ export declare type LogConsoleType = "info" | "warning" | "error" | "debug";
3
3
  /**
4
4
  * 日志项接口
5
5
  */
@@ -1,7 +1,7 @@
1
1
  import hooks from '../hooks';
2
2
  import { Provider as StoreProvider } from "react-redux";
3
3
  declare const models: import("./global").GlobalModal[];
4
- type ModalsType = (typeof models[number]);
4
+ declare type ModalsType = (typeof models[number]);
5
5
  export interface Store {
6
6
  getDataByModel: typeof getDataByModel;
7
7
  useStore: typeof hooks.useStore;
@@ -10,8 +10,8 @@ export interface Store {
10
10
  dispatch: any;
11
11
  getState: any;
12
12
  }
13
- export type ModelsNames = ModalsType['namespace'];
14
- export type ModelsState = {
13
+ export declare type ModelsNames = ModalsType['namespace'];
14
+ export declare type ModelsState = {
15
15
  [K in (ModalsType['namespace'])]: Extract<ModalsType, {
16
16
  namespace: K;
17
17
  }>['state'];
@@ -25,7 +25,7 @@ export type ModelsState = {
25
25
  * @Author: zhiwei.Wang
26
26
  * @Date: 2024-09-03 11:07
27
27
  */
28
- declare const getDataByModel: <T extends "global", D extends keyof ModelsState[T]>(model: string, key?: D) => D extends undefined ? ModelsState[T] : ModelsState[T][D];
28
+ declare const getDataByModel: <T extends "global", D extends keyof ModelsState[T]>(model: string, key?: D | undefined) => D extends undefined ? ModelsState[T] : ModelsState[T][D];
29
29
  /**
30
30
  * @title: 设置数据到store
31
31
  * @description:
@@ -2,7 +2,7 @@
2
2
  * 发布订阅模块
3
3
  * 用于组件/服务间的事件通信
4
4
  */
5
- type EventCallback = (...args: any[]) => void;
5
+ declare type EventCallback = (...args: any[]) => void;
6
6
  interface EventSubscription {
7
7
  unsubscribe: () => void;
8
8
  }
@@ -1,5 +1,5 @@
1
1
  import { CacheProps } from './type';
2
- export type CacheType = 'memory' | 'storage' | 'indexDB';
2
+ export declare type CacheType = 'memory' | 'storage' | 'indexDB';
3
3
  /**
4
4
  * @title: 设置缓存
5
5
  * @description:
@@ -90,13 +90,13 @@ export var setCache = /*#__PURE__*/function () {
90
90
  break;
91
91
  }
92
92
  _context.next = 19;
93
- return app.dbManager.add('requests', cacheData);
93
+ return app.dbManager.debouncedAdd('requests', cacheData);
94
94
  case 19:
95
95
  _context.next = 23;
96
96
  break;
97
97
  case 21:
98
98
  _context.next = 23;
99
- return app.dbManager.update('requests', cacheData);
99
+ return app.dbManager.debouncedUpdate('requests', cacheData);
100
100
  case 23:
101
101
  console.log('设置缓存成功', CACHES);
102
102
  case 24:
@@ -1,4 +1,4 @@
1
- type RequestMethod = any;
1
+ declare type RequestMethod = any;
2
2
  declare const pisell2Get: RequestMethod;
3
3
  declare const pisell2Post: RequestMethod;
4
4
  declare const pisell2Put: RequestMethod;
@@ -31,7 +31,7 @@ export declare enum RequestModeENUM {
31
31
  REMOTE_LOCAL = "remote_local",
32
32
  OS_SERVER = "os_server"
33
33
  }
34
- export type RequestModeType = RequestModeENUM.LOCAL | RequestModeENUM.REMOTE | RequestModeENUM.LOCAL_REMOTE | RequestModeENUM.REMOTE_LOCAL | RequestModeENUM.OS_SERVER;
34
+ export declare type RequestModeType = RequestModeENUM.LOCAL | RequestModeENUM.REMOTE | RequestModeENUM.LOCAL_REMOTE | RequestModeENUM.REMOTE_LOCAL | RequestModeENUM.OS_SERVER;
35
35
  export interface CacheProps {
36
36
  key?: string;
37
37
  type?: CacheType;
@@ -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 | Iterable<React.ReactNode> | React.JSX.Element | null | undefined;
23
+ renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean | JSX.Element | React.ReactFragment | null | undefined;
24
24
  getPageByRoute(route: string): ApplicationInterface | undefined;
25
25
  getRouterComponent({ fallback }: {
26
26
  fallback?: React.ReactNode;
27
- }): React.JSX.Element[];
27
+ }): JSX.Element[];
28
28
  }
@@ -76,7 +76,7 @@ export interface ReconnectOptions {
76
76
  /**
77
77
  * 事件处理函数类型
78
78
  */
79
- export type EventHandler = (...args: any[]) => void;
79
+ export declare type EventHandler = (...args: any[]) => void;
80
80
  /**
81
81
  * 事件处理函数映射
82
82
  */
@@ -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;
@@ -1,4 +1,4 @@
1
- export type TaskRunStatus = "pending" | "in-progress" | "success" | "failure";
1
+ export declare type TaskRunStatus = "pending" | "in-progress" | "success" | "failure";
2
2
  export interface Task {
3
3
  id?: string;
4
4
  type?: "local" | "cloud";
@@ -37,9 +37,9 @@ export interface Task {
37
37
  export interface TaskConfig {
38
38
  tasks: Task[];
39
39
  }
40
- type TaskModuleName = string;
41
- type TaskQueueName = string;
42
- type TaskStatus = "uncompleted" | "completed";
40
+ declare type TaskModuleName = string;
41
+ declare type TaskQueueName = string;
42
+ declare type TaskStatus = "uncompleted" | "completed";
43
43
  export interface TaskQueue {
44
44
  status: TaskStatus;
45
45
  tasks: Task[];
@@ -1,4 +1,4 @@
1
- export type ThrottleLevel = number;
1
+ export declare type ThrottleLevel = number;
2
2
  export interface ThrottleExecuteContext {
3
3
  /** 事务唯一 key */
4
4
  key: string;
@@ -11,7 +11,7 @@ export interface ThrottleExecuteContext {
11
11
  /** 上一次执行时间 */
12
12
  lastExecuteTime: number;
13
13
  }
14
- export type ThrottleHandler = (ctx: ThrottleExecuteContext) => void | Promise<void>;
14
+ export declare type ThrottleHandler = (ctx: ThrottleExecuteContext) => void | Promise<void>;
15
15
  export declare const DEFAULT_THROTTLE_INTERVALS: number[];
16
16
  export declare class AdaptiveThrottle {
17
17
  private store;
@@ -1,6 +1,6 @@
1
- export type VariableMap = Record<string, string>;
1
+ export declare type VariableMap = Record<string, string>;
2
2
  declare const _default: {
3
- setConfig: (newConfig: Partial<import("@").VariablesConfig>) => void;
4
- getConfig: () => import("@").VariablesConfig;
3
+ setConfig: (newConfig: Partial<import("./type").VariablesConfig>) => void;
4
+ getConfig: () => import("./type").VariablesConfig;
5
5
  };
6
6
  export default _default;
package/lib/app/app.d.ts CHANGED
@@ -47,13 +47,13 @@ declare class App {
47
47
  setConfig: (models: any[]) => void;
48
48
  };
49
49
  request: {
50
- get: (url: string, data: any, config: import("@").RequestSetting | undefined) => Promise<any>;
51
- post: (url: string, data: any, config: import("@").RequestSetting | undefined) => Promise<any>;
52
- put: (url: string, data: any, config: import("@").RequestSetting | undefined) => Promise<any>;
53
- remove: (url: string, data: any, config: import("@").RequestSetting | undefined) => Promise<any>;
54
- custom: (url: string, config: import("@").RequestSetting | undefined) => any;
55
- setConfig: (newConfig: Partial<import("@").RequestConfig>) => void;
56
- getConfig: () => import("@").RequestConfig;
50
+ get: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
51
+ post: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
52
+ put: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
53
+ remove: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
54
+ custom: (url: string, config: import("../request").RequestSetting | undefined) => any;
55
+ setConfig: (newConfig: Partial<import("../request").RequestConfig>) => void;
56
+ getConfig: () => import("../request").RequestConfig;
57
57
  };
58
58
  storage: Storage;
59
59
  menuManager: MenuManager;
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import App, { AppOptions } from "./app";
3
- type AppContextType = {
3
+ declare type AppContextType = {
4
4
  globalData: any;
5
5
  setGlobalData: React.Dispatch<React.SetStateAction<any>>;
6
6
  app: App;
@@ -5,7 +5,7 @@ import { MenuItem } from '../menuManager/index';
5
5
  * 应用接口类型定义
6
6
  * @description 描述应用中单个页面、组件或功能的接口结构
7
7
  */
8
- export type ApplicationInterface = {
8
+ export declare type ApplicationInterface = {
9
9
  page_type: 'low_code' | 'code';
10
10
  page_id: number | string;
11
11
  page_code: string;
@@ -29,7 +29,7 @@ export type ApplicationInterface = {
29
29
  * 应用数据类型定义
30
30
  * @description 描述完整应用的数据结构,包含应用的基本信息、接口、功能等
31
31
  */
32
- export type ApplicationData = {
32
+ export declare type ApplicationData = {
33
33
  /** 应用唯一标识 */
34
34
  app_id: number;
35
35
  /** 应用名称 */
package/lib/aws/index.js CHANGED
@@ -32,6 +32,9 @@ var defaultUploadParams = {
32
32
  // 设置ACL权限为公共读取
33
33
  };
34
34
  var AWS = class {
35
+ s3Client;
36
+ app;
37
+ config;
35
38
  constructor(app, options) {
36
39
  this.app = app;
37
40
  if (options) {
@@ -1,9 +1,9 @@
1
1
  export declare enum CMDCoreEnum {
2
- CMD_CONNECT = "cmd.connect",
3
- CMD_DISCONNECT = "cmd.disconnect",
4
- CMD_RECONNECT = "cmd.reconnect",
5
- CMD_MESSAGE = "cmd.message",
6
- CMD_ERROR = "cmd.error"
2
+ CMD_CONNECT,
3
+ CMD_DISCONNECT,
4
+ CMD_RECONNECT,
5
+ CMD_MESSAGE,
6
+ CMD_ERROR
7
7
  }
8
8
  declare const _default: {
9
9
  CMDCoreEnum: typeof CMDCoreEnum;
package/lib/cmd/const.js CHANGED
@@ -25,11 +25,11 @@ __export(const_exports, {
25
25
  module.exports = __toCommonJS(const_exports);
26
26
  var prefix = "cmd";
27
27
  var CMDCoreEnum = ((CMDCoreEnum2) => {
28
- CMDCoreEnum2[CMDCoreEnum2["CMD_CONNECT"] = `${prefix}.connect`] = "CMD_CONNECT";
29
- CMDCoreEnum2[CMDCoreEnum2["CMD_DISCONNECT"] = `${prefix}.disconnect`] = "CMD_DISCONNECT";
30
- CMDCoreEnum2[CMDCoreEnum2["CMD_RECONNECT"] = `${prefix}.reconnect`] = "CMD_RECONNECT";
31
- CMDCoreEnum2[CMDCoreEnum2["CMD_MESSAGE"] = `${prefix}.message`] = "CMD_MESSAGE";
32
- CMDCoreEnum2[CMDCoreEnum2["CMD_ERROR"] = `${prefix}.error`] = "CMD_ERROR";
28
+ CMDCoreEnum2["CMD_CONNECT"] = `${prefix}.connect`;
29
+ CMDCoreEnum2["CMD_DISCONNECT"] = `${prefix}.disconnect`;
30
+ CMDCoreEnum2["CMD_RECONNECT"] = `${prefix}.reconnect`;
31
+ CMDCoreEnum2["CMD_MESSAGE"] = `${prefix}.message`;
32
+ CMDCoreEnum2["CMD_ERROR"] = `${prefix}.error`;
33
33
  return CMDCoreEnum2;
34
34
  })(CMDCoreEnum || {});
35
35
  var const_default = { CMDCoreEnum };
package/lib/cmd/index.js CHANGED
@@ -36,6 +36,8 @@ module.exports = __toCommonJS(cmd_exports);
36
36
  var import_socket = __toESM(require("../socket"));
37
37
  var import_const = require("./const");
38
38
  var CMD = class {
39
+ app;
40
+ options;
39
41
  constructor(app, options) {
40
42
  this.app = app;
41
43
  this.options = options;
@@ -35,10 +35,8 @@ function getCookie(name) {
35
35
  const ca = document.cookie.split(";");
36
36
  for (let i = 0; i < ca.length; i++) {
37
37
  let c = ca[i];
38
- while (c.charAt(0) === " ")
39
- c = c.substring(1, c.length);
40
- if (c.indexOf(nameEQ) === 0)
41
- return c.substring(nameEQ.length, c.length);
38
+ while (c.charAt(0) === " ") c = c.substring(1, c.length);
39
+ if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
42
40
  }
43
41
  return null;
44
42
  }
package/lib/data/index.js CHANGED
@@ -23,6 +23,9 @@ __export(data_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(data_exports);
25
25
  var Data = class {
26
+ app;
27
+ storage;
28
+ store;
26
29
  constructor(app) {
27
30
  this.app = app;
28
31
  this.storage = app.storage;
@@ -1,6 +1,6 @@
1
1
  import { ModelsState } from "../../models";
2
2
  declare const useStore: <T extends "global", D extends keyof ModelsState[T]>(props: {
3
3
  models: T;
4
- key?: D;
4
+ key?: D | undefined;
5
5
  }) => D extends undefined ? ModelsState[T] : ModelsState[T][D];
6
6
  export default useStore;
@@ -52,6 +52,16 @@ declare class IndexDBManager {
52
52
  private app;
53
53
  private memoryStorage;
54
54
  private timeout;
55
+ private debouncedBuffers;
56
+ private debouncedTimers;
57
+ private debouncedFlushing;
58
+ private debouncedDelay;
59
+ private debouncedBatchSize;
60
+ private debouncedUpdateBuffers;
61
+ private debouncedUpdateTimers;
62
+ private debouncedUpdateFlushing;
63
+ private debouncedUpdateDelay;
64
+ private debouncedUpdateBatchSize;
55
65
  /**
56
66
  * 创建 IndexDBManager 实例
57
67
  * @param {DBOptions} options - 数据库配置选项
@@ -78,6 +88,24 @@ declare class IndexDBManager {
78
88
  * @private
79
89
  */
80
90
  private getMemoryStore;
91
+ /**
92
+ * 防抖合并 add(用于高频写入场景)
93
+ * @param storeName 存储对象名称
94
+ * @param data 数据
95
+ */
96
+ debouncedAdd<T>(storeName: string, data: T): void;
97
+ /**
98
+ * 立即 flush 指定 store 的防抖 add
99
+ */
100
+ flushDebouncedAdd(storeName: string): Promise<void>;
101
+ /**
102
+ * 防抖合并 update(同 key 自动合并)
103
+ */
104
+ debouncedUpdate<T extends Record<string, any>>(storeName: string, data: T): void;
105
+ /**
106
+ * flush 防抖 update
107
+ */
108
+ flushDebouncedUpdate(storeName: string): Promise<void>;
81
109
  /**
82
110
  * 添加数据到指定的存储对象
83
111
  * @param {string} storeName - 存储对象名称
@@ -53,6 +53,24 @@ var IndexDBManager = class _IndexDBManager {
53
53
  memoryStorage = /* @__PURE__ */ new Map();
54
54
  // 操作超时时间(毫秒)
55
55
  timeout = 1e4;
56
+ // ===== 防抖 add 相关 =====
57
+ // 每个 store 一个 buffer
58
+ debouncedBuffers = /* @__PURE__ */ new Map();
59
+ // 每个 store 一个 timer
60
+ debouncedTimers = /* @__PURE__ */ new Map();
61
+ // 正在 flush 的 store
62
+ debouncedFlushing = /* @__PURE__ */ new Set();
63
+ // 防抖时间(ms)
64
+ debouncedDelay = 200;
65
+ // 单次事务最大写入条数
66
+ debouncedBatchSize = 50;
67
+ // ===== 防抖 update 相关 =====
68
+ // 每个 store 一个 Map(key -> data)
69
+ debouncedUpdateBuffers = /* @__PURE__ */ new Map();
70
+ debouncedUpdateTimers = /* @__PURE__ */ new Map();
71
+ debouncedUpdateFlushing = /* @__PURE__ */ new Set();
72
+ debouncedUpdateDelay = 200;
73
+ debouncedUpdateBatchSize = 50;
56
74
  /**
57
75
  * 创建 IndexDBManager 实例
58
76
  * @param {DBOptions} options - 数据库配置选项
@@ -181,6 +199,140 @@ var IndexDBManager = class _IndexDBManager {
181
199
  }
182
200
  return store;
183
201
  }
202
+ /**
203
+ * 防抖合并 add(用于高频写入场景)
204
+ * @param storeName 存储对象名称
205
+ * @param data 数据
206
+ */
207
+ debouncedAdd(storeName, data) {
208
+ if (!this.useIndexDB) {
209
+ const storeConfig = this.stores.find((s) => s.name === storeName);
210
+ const keyPath = (storeConfig == null ? void 0 : storeConfig.keyPath) || "id";
211
+ const key = data[keyPath];
212
+ this.getMemoryStore(storeName).set(key, data);
213
+ return;
214
+ }
215
+ if (!this.db) return;
216
+ if (!this.debouncedBuffers.has(storeName)) {
217
+ this.debouncedBuffers.set(storeName, []);
218
+ }
219
+ this.debouncedBuffers.get(storeName).push(data);
220
+ if (this.debouncedFlushing.has(storeName)) return;
221
+ const oldTimer = this.debouncedTimers.get(storeName);
222
+ if (oldTimer) clearTimeout(oldTimer);
223
+ this.debouncedTimers.set(
224
+ storeName,
225
+ setTimeout(() => {
226
+ this.flushDebouncedAdd(storeName);
227
+ }, this.debouncedDelay)
228
+ );
229
+ }
230
+ /**
231
+ * 立即 flush 指定 store 的防抖 add
232
+ */
233
+ async flushDebouncedAdd(storeName) {
234
+ if (!this.useIndexDB || !this.db) return;
235
+ if (this.debouncedFlushing.has(storeName)) return;
236
+ const buffer = this.debouncedBuffers.get(storeName);
237
+ if (!buffer || buffer.length === 0) return;
238
+ this.debouncedFlushing.add(storeName);
239
+ const uuid = `[ IndexDB ] DEBOUNCED_ADD: - ${storeName} - ${(0, import_dayjs.default)().valueOf()}`;
240
+ try {
241
+ while (buffer.length > 0) {
242
+ const batch = buffer.splice(0, this.debouncedBatchSize);
243
+ await this.db.transaction("rw", this.db.table(storeName), async () => {
244
+ for (const item of batch) {
245
+ await this.add(storeName, item);
246
+ }
247
+ });
248
+ }
249
+ } catch (error) {
250
+ this.app.logger.addLog({
251
+ type: "error",
252
+ title: uuid,
253
+ metadata: {
254
+ msg: "防抖合并 add 失败",
255
+ error: error.message
256
+ }
257
+ });
258
+ } finally {
259
+ this.debouncedFlushing.delete(storeName);
260
+ }
261
+ }
262
+ /**
263
+ * 防抖合并 update(同 key 自动合并)
264
+ */
265
+ debouncedUpdate(storeName, data) {
266
+ if (!this.useIndexDB) {
267
+ const storeConfig2 = this.stores.find((s) => s.name === storeName);
268
+ const keyPath2 = (storeConfig2 == null ? void 0 : storeConfig2.keyPath) || "id";
269
+ const key2 = data[keyPath2];
270
+ this.getMemoryStore(storeName).set(key2, {
271
+ ...this.getMemoryStore(storeName).get(key2),
272
+ ...data
273
+ });
274
+ return;
275
+ }
276
+ if (!this.db) return;
277
+ const storeConfig = this.stores.find((s) => s.name === storeName);
278
+ const keyPath = (storeConfig == null ? void 0 : storeConfig.keyPath) || "id";
279
+ const key = data[keyPath];
280
+ if (key == null) {
281
+ console.warn(`[IndexDB] debouncedUpdate missing keyPath: ${keyPath}`);
282
+ return;
283
+ }
284
+ if (!this.debouncedUpdateBuffers.has(storeName)) {
285
+ this.debouncedUpdateBuffers.set(storeName, /* @__PURE__ */ new Map());
286
+ }
287
+ const storeBuffer = this.debouncedUpdateBuffers.get(storeName);
288
+ storeBuffer.set(key, {
289
+ ...storeBuffer.get(key) || {},
290
+ ...data
291
+ });
292
+ if (this.debouncedUpdateFlushing.has(storeName)) return;
293
+ const oldTimer = this.debouncedUpdateTimers.get(storeName);
294
+ if (oldTimer) clearTimeout(oldTimer);
295
+ this.debouncedUpdateTimers.set(
296
+ storeName,
297
+ setTimeout(() => {
298
+ this.flushDebouncedUpdate(storeName);
299
+ }, this.debouncedUpdateDelay)
300
+ );
301
+ }
302
+ /**
303
+ * flush 防抖 update
304
+ */
305
+ async flushDebouncedUpdate(storeName) {
306
+ if (!this.useIndexDB || !this.db) return;
307
+ if (this.debouncedUpdateFlushing.has(storeName)) return;
308
+ const bufferMap = this.debouncedUpdateBuffers.get(storeName);
309
+ if (!bufferMap || bufferMap.size === 0) return;
310
+ this.debouncedUpdateFlushing.add(storeName);
311
+ const uuid = `[ IndexDB ] DEBOUNCED_UPDATE: - ${storeName} - ${(0, import_dayjs.default)().valueOf()}`;
312
+ try {
313
+ const entries = Array.from(bufferMap.values());
314
+ bufferMap.clear();
315
+ for (let i = 0; i < entries.length; i += this.debouncedUpdateBatchSize) {
316
+ const batch = entries.slice(i, i + this.debouncedUpdateBatchSize);
317
+ await this.db.transaction("rw", this.db.table(storeName), async () => {
318
+ for (const item of batch) {
319
+ await this.update(storeName, item);
320
+ }
321
+ });
322
+ }
323
+ } catch (error) {
324
+ this.app.logger.addLog({
325
+ type: "error",
326
+ title: uuid,
327
+ metadata: {
328
+ msg: "防抖合并 update 失败",
329
+ error: error.message
330
+ }
331
+ });
332
+ } finally {
333
+ this.debouncedUpdateFlushing.delete(storeName);
334
+ }
335
+ }
184
336
  /**
185
337
  * 添加数据到指定的存储对象
186
338
  * @param {string} storeName - 存储对象名称
@@ -223,7 +375,11 @@ var IndexDBManager = class _IndexDBManager {
223
375
  this.app.logger.addLog({
224
376
  type: "error",
225
377
  title: uuid,
226
- metadata: { msg: "添加数据失败", error: error.message }
378
+ metadata: {
379
+ msg: "添加数据失败",
380
+ data,
381
+ error: error.message
382
+ }
227
383
  });
228
384
  throw new Error(error == null ? void 0 : error.message);
229
385
  }