@pisell/core 1.0.33 → 1.0.35

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 (63) 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 +2 -2
  7. package/es/indexDB/index.js +633 -572
  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/pisell2Request.d.ts +1 -1
  14. package/es/request/type.d.ts +1 -1
  15. package/es/routes/index.d.ts +2 -2
  16. package/es/socket/monitor.js +2 -0
  17. package/es/socket/types.d.ts +4 -3
  18. package/es/tasks/index.d.ts +0 -1
  19. package/es/tasks/index.js +0 -1
  20. package/es/tasks/type.d.ts +4 -4
  21. package/es/variables/index.d.ts +3 -3
  22. package/lib/app/app.d.ts +7 -7
  23. package/lib/app/app.js +21 -51
  24. package/lib/app/index.d.ts +1 -1
  25. package/lib/applicationManager/application.d.ts +2 -2
  26. package/lib/applicationManager/application.js +6 -12
  27. package/lib/applicationManager/index.js +4 -2
  28. package/lib/aws/index.js +0 -3
  29. package/lib/cmd/const.d.ts +5 -5
  30. package/lib/cmd/const.js +5 -5
  31. package/lib/cmd/index.js +0 -2
  32. package/lib/cookie/index.js +4 -2
  33. package/lib/data/index.js +0 -3
  34. package/lib/history/index.js +22 -24
  35. package/lib/hooks/useStore/index.d.ts +1 -1
  36. package/lib/indexDB/index.d.ts +2 -2
  37. package/lib/indexDB/index.js +233 -327
  38. package/lib/locales/index.js +94 -95
  39. package/lib/locales/type.d.ts +3 -3
  40. package/lib/logger/index.d.ts +1 -1
  41. package/lib/logger/index.js +8 -18
  42. package/lib/menuManager/index.js +12 -9
  43. package/lib/models/index.d.ts +4 -4
  44. package/lib/pubsub/index.d.ts +1 -1
  45. package/lib/pubsub/index.js +3 -1
  46. package/lib/request/cache.d.ts +1 -1
  47. package/lib/request/pisell2Request.d.ts +1 -1
  48. package/lib/request/type.d.ts +1 -1
  49. package/lib/routes/index.d.ts +2 -2
  50. package/lib/routes/index.js +1 -3
  51. package/lib/socket/components/SocketMonitorPage.js +12 -6
  52. package/lib/socket/heartbeat.js +5 -10
  53. package/lib/socket/index.js +3 -1
  54. package/lib/socket/monitor.js +26 -26
  55. package/lib/socket/reconnect.js +3 -10
  56. package/lib/socket/socket.js +10 -12
  57. package/lib/socket/types.d.ts +4 -3
  58. package/lib/storage/index.js +24 -25
  59. package/lib/tasks/index.d.ts +0 -1
  60. package/lib/tasks/index.js +329 -334
  61. package/lib/tasks/type.d.ts +4 -4
  62. package/lib/variables/index.d.ts +3 -3
  63. package/package.json +3 -2
@@ -39,15 +39,101 @@ var import_zh_CN = __toESM(require("./zh-CN"));
39
39
  var import_zh_HK = __toESM(require("./zh-HK"));
40
40
  var import_original = __toESM(require("./original"));
41
41
  var Locales = class {
42
- app;
43
- // 当前语言 本地语言 > 英文语言包
44
- locale = import_en.default.locale;
45
- // 语言包
46
- library = [import_original.default, import_en.default, import_zh_CN.default, import_zh_HK.default].reduce((pre, cur) => {
47
- pre[cur.locale] = cur;
48
- return pre;
49
- }, {});
50
42
  constructor(app, options) {
43
+ // 当前语言 本地语言 > 英文语言包
44
+ this.locale = import_en.default.locale;
45
+ // 语言包
46
+ this.library = [import_original.default, import_en.default, import_zh_CN.default, import_zh_HK.default].reduce((pre, cur) => {
47
+ pre[cur.locale] = cur;
48
+ return pre;
49
+ }, {});
50
+ this.getLocale = () => {
51
+ return this.locale;
52
+ };
53
+ this.getCurrentTexts = (locale) => {
54
+ return this.library[locale || this.locale].translations;
55
+ };
56
+ this.setLocale = (locale, reload = false) => {
57
+ this.locale = locale;
58
+ if (reload) {
59
+ window.location.reload();
60
+ return;
61
+ }
62
+ };
63
+ this.getText = (id, locale) => {
64
+ var _a;
65
+ return ((_a = this.getCurrentTexts(locale)) == null ? void 0 : _a[id]) || id;
66
+ };
67
+ this.isCN = () => {
68
+ let locale = this.getLocale();
69
+ return locale === "zh-CN" || locale === "zh-HK";
70
+ };
71
+ this.loadLibraryByUrl = async (urls) => {
72
+ try {
73
+ let fetchList = urls.map((item) => {
74
+ if (typeof item === "string") {
75
+ return fetch(item);
76
+ }
77
+ if (typeof item === "function") {
78
+ return item();
79
+ }
80
+ if (typeof item === "object" && item !== null && "locale" in item) {
81
+ return Promise.resolve(item);
82
+ }
83
+ return item;
84
+ });
85
+ let res = await Promise.all(fetchList);
86
+ let library = { ...this.library };
87
+ for (const item of res) {
88
+ const _item = item instanceof Response ? await item.json() : item;
89
+ library = {
90
+ ...library,
91
+ [_item.locale]: import_lodash.default.mergeWith(library[_item.locale] || {}, _item)
92
+ };
93
+ }
94
+ this.library = library;
95
+ return library;
96
+ } catch (err) {
97
+ console.log(err);
98
+ throw err;
99
+ }
100
+ };
101
+ this.loadLibrary = (urls) => {
102
+ return this.loadLibraryByUrl(urls);
103
+ };
104
+ this.translation = (text, locale) => {
105
+ if (!text) {
106
+ return "";
107
+ }
108
+ if ((0, import_utils.isString)(text) || (0, import_utils.isNumber)(text)) {
109
+ return text;
110
+ }
111
+ let primary = locale || this.getLocale();
112
+ if (typeof text === "string") {
113
+ return text;
114
+ }
115
+ return text[primary] || text["original"] || text["en"] || text["zh-CN"] || text["zh-HK"];
116
+ };
117
+ this.getLibraryByData = (data) => {
118
+ return data.reduce((pre, next) => {
119
+ return {
120
+ ...pre,
121
+ [next.locale]: next
122
+ };
123
+ }, {});
124
+ };
125
+ this.createTextsByLibrary = (id, library) => {
126
+ const _library = library || this.library;
127
+ return Object.keys(_library).reduce((pre, next) => {
128
+ var _a;
129
+ let _pre = { ...pre };
130
+ let cur = (_a = _library[next].translations) == null ? void 0 : _a[id];
131
+ if (cur) {
132
+ _pre[_library[next].locale] = cur;
133
+ }
134
+ return _pre;
135
+ }, {});
136
+ };
51
137
  this.app = app;
52
138
  this.locale = (options == null ? void 0 : options.locale) || this.app.storage.getStorage("locale") || import_en.default.locale;
53
139
  this.library = (options == null ? void 0 : options.library) || [import_original.default, import_en.default, import_zh_CN.default, import_zh_HK.default].reduce((pre, cur) => {
@@ -55,57 +141,6 @@ var Locales = class {
55
141
  return pre;
56
142
  }, {});
57
143
  }
58
- getLocale = () => {
59
- return this.locale;
60
- };
61
- getCurrentTexts = (locale) => {
62
- return this.library[locale || this.locale].translations;
63
- };
64
- setLocale = (locale, reload = false) => {
65
- this.locale = locale;
66
- if (reload) {
67
- window.location.reload();
68
- return;
69
- }
70
- };
71
- getText = (id, locale) => {
72
- var _a;
73
- return ((_a = this.getCurrentTexts(locale)) == null ? void 0 : _a[id]) || id;
74
- };
75
- isCN = () => {
76
- let locale = this.getLocale();
77
- return locale === "zh-CN" || locale === "zh-HK";
78
- };
79
- loadLibraryByUrl = async (urls) => {
80
- try {
81
- let fetchList = urls.map((item) => {
82
- if (typeof item === "string") {
83
- return fetch(item);
84
- }
85
- if (typeof item === "function") {
86
- return item();
87
- }
88
- if (typeof item === "object" && item !== null && "locale" in item) {
89
- return Promise.resolve(item);
90
- }
91
- return item;
92
- });
93
- let res = await Promise.all(fetchList);
94
- let library = { ...this.library };
95
- for (const item of res) {
96
- const _item = item instanceof Response ? await item.json() : item;
97
- library = {
98
- ...library,
99
- [_item.locale]: import_lodash.default.mergeWith(library[_item.locale] || {}, _item)
100
- };
101
- }
102
- this.library = library;
103
- return library;
104
- } catch (err) {
105
- console.log(err);
106
- throw err;
107
- }
108
- };
109
144
  loadLibraryByItems(libraryList) {
110
145
  let library = { ...this.library };
111
146
  libraryList.forEach((item) => {
@@ -116,42 +151,6 @@ var Locales = class {
116
151
  });
117
152
  this.library = library;
118
153
  }
119
- loadLibrary = (urls) => {
120
- return this.loadLibraryByUrl(urls);
121
- };
122
- translation = (text, locale) => {
123
- if (!text) {
124
- return "";
125
- }
126
- if ((0, import_utils.isString)(text) || (0, import_utils.isNumber)(text)) {
127
- return text;
128
- }
129
- let primary = locale || this.getLocale();
130
- if (typeof text === "string") {
131
- return text;
132
- }
133
- return text[primary] || text["original"] || text["en"] || text["zh-CN"] || text["zh-HK"];
134
- };
135
- getLibraryByData = (data) => {
136
- return data.reduce((pre, next) => {
137
- return {
138
- ...pre,
139
- [next.locale]: next
140
- };
141
- }, {});
142
- };
143
- createTextsByLibrary = (id, library) => {
144
- const _library = library || this.library;
145
- return Object.keys(_library).reduce((pre, next) => {
146
- var _a;
147
- let _pre = { ...pre };
148
- let cur = (_a = _library[next].translations) == null ? void 0 : _a[id];
149
- if (cur) {
150
- _pre[_library[next].locale] = cur;
151
- }
152
- return _pre;
153
- }, {});
154
- };
155
154
  };
156
155
  // Annotate the CommonJS export names for ESM import in node:
157
156
  0 && (module.exports = {
@@ -1,5 +1,5 @@
1
- export declare type Locale = 'original' | 'en' | 'zh-CN' | 'zh-HK' | string;
2
- export declare type MultiLanguage = {
1
+ export type Locale = 'original' | 'en' | 'zh-CN' | 'zh-HK' | string;
2
+ export 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 declare type LoadLibraryByUrlParams = (string | Promise<LibraryItem> | (() => Promise<LibraryItem>) | LibraryItem)[];
19
+ export type LoadLibraryByUrlParams = (string | Promise<LibraryItem> | (() => Promise<LibraryItem>) | LibraryItem)[];
@@ -1,5 +1,5 @@
1
1
  import App from "../app";
2
- export declare type LogConsoleType = "info" | "warning" | "error" | "debug";
2
+ export type LogConsoleType = "info" | "warning" | "error" | "debug";
3
3
  /**
4
4
  * 日志项接口
5
5
  */
@@ -35,24 +35,6 @@ module.exports = __toCommonJS(logger_exports);
35
35
  var import_dayjs = __toESM(require("dayjs"));
36
36
  var import_feishu = require("./feishu");
37
37
  var LoggerManager = class {
38
- // 私有属性
39
- logBuffer = [];
40
- // 日志缓冲区
41
- timer = null;
42
- // 定时器
43
- checkInterval;
44
- // 检查间隔时间(毫秒)
45
- prefix = "app";
46
- // 日志文件前缀
47
- metadata;
48
- db = null;
49
- // IndexDB 实例
50
- app;
51
- feishuConfig;
52
- retentionDays;
53
- // 日志保留天数
54
- metadataFunction;
55
- status = "running";
56
38
  // 日志管理器状态
57
39
  /**
58
40
  * 构造函数
@@ -60,6 +42,14 @@ var LoggerManager = class {
60
42
  * @param checkInterval 检查间隔时间,默认5分钟
61
43
  */
62
44
  constructor(app, options) {
45
+ // 私有属性
46
+ this.logBuffer = [];
47
+ // 日志缓冲区
48
+ this.timer = null;
49
+ // 检查间隔时间(毫秒)
50
+ this.prefix = "app";
51
+ this.db = null;
52
+ this.status = "running";
63
53
  this.prefix = (options == null ? void 0 : options.prefix) || "app";
64
54
  this.checkInterval = (options == null ? void 0 : options.checkInterval) || 5 * 60 * 1e3;
65
55
  this.app = app;
@@ -24,12 +24,11 @@ __export(menuManager_exports, {
24
24
  module.exports = __toCommonJS(menuManager_exports);
25
25
  var import_hooks = require("./hooks");
26
26
  var MenuManager = class {
27
- menuItems = [];
28
- menuMaps = {};
29
- app;
30
- useMenu = import_hooks.useMenu;
31
- MenuProvider = import_hooks.MenuProvider;
32
27
  constructor(items, app) {
28
+ this.menuItems = [];
29
+ this.menuMaps = {};
30
+ this.useMenu = import_hooks.useMenu;
31
+ this.MenuProvider = import_hooks.MenuProvider;
33
32
  this.app = app;
34
33
  this.set(items);
35
34
  }
@@ -86,7 +85,8 @@ var MenuManager = class {
86
85
  }
87
86
  if (item.children) {
88
87
  const found = this.findMenuItemByPath(item.children, path);
89
- if (found) return found;
88
+ if (found)
89
+ return found;
90
90
  }
91
91
  }
92
92
  return null;
@@ -94,10 +94,12 @@ var MenuManager = class {
94
94
  // 查找给定key的父级菜单key
95
95
  findParent(items, key, parent = null) {
96
96
  for (const item of items) {
97
- if (item.key === key) return parent;
97
+ if (item.key === key)
98
+ return parent;
98
99
  if (item.children) {
99
100
  const found = this.findParent(item.children, key, item);
100
- if (found) return found;
101
+ if (found)
102
+ return found;
101
103
  }
102
104
  }
103
105
  return null;
@@ -113,7 +115,8 @@ var MenuManager = class {
113
115
  }
114
116
  if (item.children) {
115
117
  const found = this.findMenuItemByKey(item.children, key);
116
- if (found) return found;
118
+ if (found)
119
+ return found;
117
120
  }
118
121
  }
119
122
  return null;
@@ -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
- declare type ModalsType = (typeof models[number]);
4
+ 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 declare type ModelsNames = ModalsType['namespace'];
14
- export declare type ModelsState = {
13
+ export type ModelsNames = ModalsType['namespace'];
14
+ export type ModelsState = {
15
15
  [K in (ModalsType['namespace'])]: Extract<ModalsType, {
16
16
  namespace: K;
17
17
  }>['state'];
@@ -25,7 +25,7 @@ export declare 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 | undefined) => D extends undefined ? ModelsState[T] : ModelsState[T][D];
28
+ declare const getDataByModel: <T extends "global", D extends keyof ModelsState[T]>(model: string, key?: D) => 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
- declare type EventCallback = (...args: any[]) => void;
5
+ type EventCallback = (...args: any[]) => void;
6
6
  interface EventSubscription {
7
7
  unsubscribe: () => void;
8
8
  }
@@ -24,7 +24,9 @@ __export(pubsub_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(pubsub_exports);
26
26
  var PubSub = class {
27
- events = /* @__PURE__ */ new Map();
27
+ constructor() {
28
+ this.events = /* @__PURE__ */ new Map();
29
+ }
28
30
  /**
29
31
  * 订阅事件
30
32
  * @param event 事件名称
@@ -1,5 +1,5 @@
1
1
  import { CacheProps } from './type';
2
- export declare type CacheType = 'memory' | 'storage' | 'indexDB';
2
+ export type CacheType = 'memory' | 'storage' | 'indexDB';
3
3
  /**
4
4
  * @title: 设置缓存
5
5
  * @description:
@@ -1,4 +1,4 @@
1
- declare type RequestMethod = any;
1
+ type RequestMethod = any;
2
2
  declare const pisell2Get: RequestMethod;
3
3
  declare const pisell2Post: RequestMethod;
4
4
  declare const pisell2Put: RequestMethod;
@@ -26,7 +26,7 @@ export declare enum RequestModeENUM {
26
26
  REMOTE_LOCAL = "remote_local",
27
27
  OS_SERVER = "os_server"
28
28
  }
29
- export declare type RequestModeType = RequestModeENUM.LOCAL | RequestModeENUM.REMOTE | RequestModeENUM.LOCAL_REMOTE | RequestModeENUM.REMOTE_LOCAL | RequestModeENUM.OS_SERVER;
29
+ export type RequestModeType = RequestModeENUM.LOCAL | RequestModeENUM.REMOTE | RequestModeENUM.LOCAL_REMOTE | RequestModeENUM.REMOTE_LOCAL | RequestModeENUM.OS_SERVER;
30
30
  export interface CacheProps {
31
31
  key?: string;
32
32
  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 | React.ReactFragment | JSX.Element | null | undefined;
23
+ renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | 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
  }
@@ -35,10 +35,8 @@ module.exports = __toCommonJS(routes_exports);
35
35
  var import_react = __toESM(require("react"));
36
36
  var import_react_router_dom = require("react-router-dom");
37
37
  var RouterManager = class {
38
- routes = {};
39
- options;
40
- app;
41
38
  constructor(options = {}, app) {
39
+ this.routes = {};
42
40
  this.options = options;
43
41
  this.app = app;
44
42
  this.routes = options.routes || {};
@@ -36,12 +36,14 @@ var import_react = __toESM(require("react"));
36
36
  var import__ = __toESM(require("../index"));
37
37
  var import__2 = require("../index");
38
38
  var formatTime = (timestamp) => {
39
- if (timestamp === null) return "无";
39
+ if (timestamp === null)
40
+ return "无";
40
41
  const date = new Date(timestamp);
41
42
  return date.toLocaleString();
42
43
  };
43
44
  var formatDuration = (ms) => {
44
- if (ms === null) return "无";
45
+ if (ms === null)
46
+ return "无";
45
47
  const seconds = Math.floor(ms / 1e3);
46
48
  const minutes = Math.floor(seconds / 60);
47
49
  const hours = Math.floor(minutes / 60);
@@ -50,7 +52,8 @@ var formatDuration = (ms) => {
50
52
  return `${hours}小时 ${remainingMinutes}分钟 ${remainingSeconds}秒`;
51
53
  };
52
54
  var formatBytes = (bytes) => {
53
- if (bytes === 0) return "0 B";
55
+ if (bytes === 0)
56
+ return "0 B";
54
57
  const units = ["B", "KB", "MB", "GB", "TB"];
55
58
  const i = Math.floor(Math.log(bytes) / Math.log(1024));
56
59
  return `${(bytes / Math.pow(1024, i)).toFixed(2)} ${units[i]}`;
@@ -90,12 +93,15 @@ var SocketMonitorPage = () => {
90
93
  }
91
94
  }, [selectedKey]);
92
95
  const loadSocketData = (0, import_react.useCallback)(() => {
93
- if (!selectedKey) return;
96
+ if (!selectedKey)
97
+ return;
94
98
  const socketInstance = import__.default.get(selectedKey);
95
- if (!socketInstance) return;
99
+ if (!socketInstance)
100
+ return;
96
101
  setCurrentSocket(socketInstance);
97
102
  const monitor = socketInstance.getMonitor() || socketInstance.enableMonitoring();
98
- if (!monitor) return;
103
+ if (!monitor)
104
+ return;
99
105
  setStats(monitor.getStats());
100
106
  const direction = messageFilter === "all" ? void 0 : messageFilter === "in" ? "in" : "out";
101
107
  setMessageHistory(monitor.getMessageHistory(50, direction));
@@ -24,16 +24,6 @@ __export(heartbeat_exports, {
24
24
  module.exports = __toCommonJS(heartbeat_exports);
25
25
  var import_constants = require("./constants");
26
26
  var HeartbeatManager = class {
27
- options;
28
- intervalTimer = null;
29
- timeoutTimer = null;
30
- lastHeartbeatTime = 0;
31
- lastHeartbeatResponse = 0;
32
- active = false;
33
- // 心跳回调函数
34
- sendHeartbeat;
35
- onTimeout;
36
- onResponse;
37
27
  /**
38
28
  * 创建心跳管理器
39
29
  * @param options 心跳配置选项
@@ -41,6 +31,11 @@ var HeartbeatManager = class {
41
31
  * @param callbacks 回调函数集合
42
32
  */
43
33
  constructor(options, sendHeartbeat, callbacks = {}) {
34
+ this.intervalTimer = null;
35
+ this.timeoutTimer = null;
36
+ this.lastHeartbeatTime = 0;
37
+ this.lastHeartbeatResponse = 0;
38
+ this.active = false;
44
39
  this.options = {
45
40
  ...options,
46
41
  interval: Math.max(options.interval, import_constants.MIN_HEARTBEAT_INTERVAL),
@@ -46,7 +46,9 @@ function createSocket(url, options = {}) {
46
46
  return new import_socket.Socket({ url, ...options });
47
47
  }
48
48
  var SocketFactory = class {
49
- sockets = /* @__PURE__ */ new Map();
49
+ constructor() {
50
+ this.sockets = /* @__PURE__ */ new Map();
51
+ }
50
52
  /**
51
53
  * 创建新的Socket实例
52
54
  * @param url WebSocket连接URL
@@ -25,38 +25,36 @@ module.exports = __toCommonJS(monitor_exports);
25
25
  var import_events = require("./events");
26
26
  var import_types = require("./types");
27
27
  var SocketMonitor = class {
28
- socket;
29
- options;
30
- isMonitoring = false;
31
- // 历史记录存储
32
- messageHistory = [];
33
- statusHistory = [];
34
- // 统计数据
35
- stats = {
36
- totalSent: 0,
37
- totalReceived: 0,
38
- bytesSent: 0,
39
- bytesReceived: 0,
40
- connectionCount: 0,
41
- reconnectionCount: 0,
42
- errorCount: 0,
43
- heartbeatCount: 0,
44
- heartbeatTimeoutCount: 0,
45
- firstConnectTime: null,
46
- lastConnectTime: null,
47
- currentConnectionDuration: null,
48
- averageMessageSize: 0
49
- };
50
- // 用于计算连接持续时间
51
- connectStartTime = null;
52
- // 事件句柄映射
53
- eventHandlers = /* @__PURE__ */ new Map();
54
28
  /**
55
29
  * 创建Socket监控器
56
30
  * @param socket 要监控的Socket实例
57
31
  * @param options 监控配置选项
58
32
  */
59
33
  constructor(socket, options = {}) {
34
+ this.isMonitoring = false;
35
+ // 历史记录存储
36
+ this.messageHistory = [];
37
+ this.statusHistory = [];
38
+ // 统计数据
39
+ this.stats = {
40
+ totalSent: 0,
41
+ totalReceived: 0,
42
+ bytesSent: 0,
43
+ bytesReceived: 0,
44
+ connectionCount: 0,
45
+ reconnectionCount: 0,
46
+ errorCount: 0,
47
+ heartbeatCount: 0,
48
+ heartbeatTimeoutCount: 0,
49
+ firstConnectTime: null,
50
+ lastConnectTime: null,
51
+ currentConnectionDuration: null,
52
+ averageMessageSize: 0
53
+ };
54
+ // 用于计算连接持续时间
55
+ this.connectStartTime = null;
56
+ // 事件句柄映射
57
+ this.eventHandlers = /* @__PURE__ */ new Map();
60
58
  this.socket = socket;
61
59
  this.options = {
62
60
  maxHistoryItems: 100,
@@ -263,6 +261,7 @@ var SocketMonitor = class {
263
261
  id: message.id || `out_${Date.now()}`,
264
262
  timestamp: Date.now(),
265
263
  direction: "out",
264
+ //@ts-ignore
266
265
  message: this.options.recordMessageContent ? message : { event: message.event },
267
266
  size
268
267
  });
@@ -284,6 +283,7 @@ var SocketMonitor = class {
284
283
  id: message.id || `in_${Date.now()}`,
285
284
  timestamp: Date.now(),
286
285
  direction: "in",
286
+ //@ts-ignore
287
287
  message: this.options.recordMessageContent ? message : { event: message.event },
288
288
  size
289
289
  });
@@ -24,16 +24,6 @@ __export(reconnect_exports, {
24
24
  module.exports = __toCommonJS(reconnect_exports);
25
25
  var import_constants = require("./constants");
26
26
  var ReconnectManager = class {
27
- options;
28
- attempts = 0;
29
- timer = null;
30
- isReconnecting = false;
31
- // 重连回调函数
32
- reconnectCallback;
33
- onAttempt;
34
- onSuccess;
35
- onFail;
36
- onMaxAttemptsExceeded;
37
27
  /**
38
28
  * 创建重连管理器实例
39
29
  * @param options 重连配置
@@ -41,6 +31,9 @@ var ReconnectManager = class {
41
31
  * @param callbacks 回调函数集合
42
32
  */
43
33
  constructor(options, reconnectCallback, callbacks = {}) {
34
+ this.attempts = 0;
35
+ this.timer = null;
36
+ this.isReconnecting = false;
44
37
  this.options = {
45
38
  ...options,
46
39
  delay: Math.max(options.delay, import_constants.MIN_RECONNECTION_DELAY)
@@ -30,23 +30,21 @@ var import_reconnect = require("./reconnect");
30
30
  var import_monitor = require("./monitor");
31
31
  var import_app = require("../app");
32
32
  var Socket = class {
33
- ws = null;
34
- url;
35
- options;
36
- status = import_types.SocketStatus.CLOSED;
37
- eventHandlers = {};
38
- // 心跳和重连管理器
39
- heartbeatManager = null;
40
- reconnectManager = null;
41
- // 监控器
42
- monitor = null;
43
- // 消息ID计数器
44
- messageIdCounter = 0;
45
33
  /**
46
34
  * 创建Socket实例
47
35
  * @param options Socket配置选项
48
36
  */
49
37
  constructor(options) {
38
+ this.ws = null;
39
+ this.status = import_types.SocketStatus.CLOSED;
40
+ this.eventHandlers = {};
41
+ // 心跳和重连管理器
42
+ this.heartbeatManager = null;
43
+ this.reconnectManager = null;
44
+ // 监控器
45
+ this.monitor = null;
46
+ // 消息ID计数器
47
+ this.messageIdCounter = 0;
50
48
  this.url = options.url;
51
49
  this.options = {
52
50
  ...import_constants.DEFAULT_SOCKET_OPTIONS,
@@ -38,13 +38,14 @@ export declare enum SocketStatus {
38
38
  /**
39
39
  * Socket消息格式
40
40
  */
41
- export interface SocketMessage<T = any> {
41
+ export interface SocketMessage {
42
42
  /** 事件类型 */
43
43
  type: string;
44
44
  /** 消息数据 */
45
- data?: T;
45
+ data?: any;
46
46
  /** 消息ID */
47
47
  id?: string;
48
+ event?: any;
48
49
  }
49
50
  /**
50
51
  * 心跳配置选项
@@ -75,7 +76,7 @@ export interface ReconnectOptions {
75
76
  /**
76
77
  * 事件处理函数类型
77
78
  */
78
- export declare type EventHandler = (...args: any[]) => void;
79
+ export type EventHandler = (...args: any[]) => void;
79
80
  /**
80
81
  * 事件处理函数映射
81
82
  */