@pisell/core 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (296) hide show
  1. package/README.md +1 -0
  2. package/es/app/app.d.ts +101 -0
  3. package/es/app/app.js +177 -0
  4. package/es/app/const.d.ts +4 -0
  5. package/es/app/const.js +6 -0
  6. package/es/app/index.d.ts +14 -0
  7. package/es/app/index.js +52 -0
  8. package/es/applicationManager/application.d.ts +197 -0
  9. package/es/applicationManager/application.js +469 -0
  10. package/es/applicationManager/index.d.ts +19 -0
  11. package/es/applicationManager/index.js +206 -0
  12. package/es/aws/index.d.ts +16 -0
  13. package/es/aws/index.js +76 -0
  14. package/es/cmd/const.d.ts +11 -0
  15. package/es/cmd/const.js +13 -0
  16. package/es/cmd/index.d.ts +13 -0
  17. package/es/cmd/index.js +91 -0
  18. package/es/cmd/type.d.ts +5 -0
  19. package/es/cmd/type.js +1 -0
  20. package/es/communicationManager/index.d.ts +59 -0
  21. package/es/communicationManager/index.js +174 -0
  22. package/es/config.d.ts +3 -0
  23. package/es/config.js +14 -0
  24. package/es/cookie/index.d.ts +13 -0
  25. package/es/cookie/index.js +47 -0
  26. package/es/css/global.less +73 -0
  27. package/es/css/index.less +31 -0
  28. package/es/css/variables.css +84 -0
  29. package/es/data/index.d.ts +8 -0
  30. package/es/data/index.js +16 -0
  31. package/es/history/config.d.ts +24 -0
  32. package/es/history/config.js +43 -0
  33. package/es/history/index.d.ts +26 -0
  34. package/es/history/index.js +80 -0
  35. package/es/history/type.d.ts +2 -0
  36. package/es/history/type.js +1 -0
  37. package/es/hooks/index.d.ts +12 -0
  38. package/es/hooks/index.js +13 -0
  39. package/es/hooks/useDelayedValue/index.d.ts +2 -0
  40. package/es/hooks/useDelayedValue/index.js +26 -0
  41. package/es/hooks/useDispatch/index.d.ts +2 -0
  42. package/es/hooks/useDispatch/index.js +2 -0
  43. package/es/hooks/useLowCode/index.d.ts +13 -0
  44. package/es/hooks/useLowCode/index.js +74 -0
  45. package/es/hooks/useStore/index.d.ts +6 -0
  46. package/es/hooks/useStore/index.js +11 -0
  47. package/es/index.d.ts +8 -0
  48. package/es/index.js +10 -0
  49. package/es/indexDB/index.d.ts +296 -0
  50. package/es/indexDB/index.js +1619 -0
  51. package/es/locales/en.d.ts +3 -0
  52. package/es/locales/en.js +5 -0
  53. package/es/locales/index.d.ts +39 -0
  54. package/es/locales/index.js +199 -0
  55. package/es/locales/original.d.ts +3 -0
  56. package/es/locales/original.js +7 -0
  57. package/es/locales/type.d.ts +19 -0
  58. package/es/locales/type.js +1 -0
  59. package/es/locales/zh-CN.d.ts +3 -0
  60. package/es/locales/zh-CN.js +5 -0
  61. package/es/locales/zh-HK.d.ts +3 -0
  62. package/es/locales/zh-HK.js +5 -0
  63. package/es/logger/feishu.d.ts +11 -0
  64. package/es/logger/feishu.js +50 -0
  65. package/es/logger/index.d.ts +135 -0
  66. package/es/logger/index.js +870 -0
  67. package/es/menuManager/hooks.d.ts +17 -0
  68. package/es/menuManager/hooks.js +136 -0
  69. package/es/menuManager/index.d.ts +28 -0
  70. package/es/menuManager/index.js +165 -0
  71. package/es/models/global.d.ts +32 -0
  72. package/es/models/global.js +66 -0
  73. package/es/models/index.d.ts +45 -0
  74. package/es/models/index.js +65 -0
  75. package/es/models/type.d.ts +2 -0
  76. package/es/models/type.js +1 -0
  77. package/es/plugin/index.d.ts +0 -0
  78. package/es/plugin/index.js +0 -0
  79. package/es/pubsub/example.d.ts +5 -0
  80. package/es/pubsub/example.js +92 -0
  81. package/es/pubsub/index.d.ts +73 -0
  82. package/es/pubsub/index.js +166 -0
  83. package/es/render/index.d.ts +0 -0
  84. package/es/render/index.js +0 -0
  85. package/es/request/cache.d.ts +46 -0
  86. package/es/request/cache.js +372 -0
  87. package/es/request/cancelToken.d.ts +38 -0
  88. package/es/request/cancelToken.js +59 -0
  89. package/es/request/config.d.ts +3 -0
  90. package/es/request/config.js +63 -0
  91. package/es/request/constants.d.ts +2 -0
  92. package/es/request/constants.js +6 -0
  93. package/es/request/index.d.ts +24 -0
  94. package/es/request/index.js +267 -0
  95. package/es/request/pisell2Request.d.ts +6 -0
  96. package/es/request/pisell2Request.js +62 -0
  97. package/es/request/type.d.ts +57 -0
  98. package/es/request/type.js +10 -0
  99. package/es/request/utils.d.ts +46 -0
  100. package/es/request/utils.js +147 -0
  101. package/es/routes/config.d.ts +7 -0
  102. package/es/routes/config.js +17 -0
  103. package/es/routes/index.d.ts +28 -0
  104. package/es/routes/index.js +151 -0
  105. package/es/socket/components/SocketMonitorPage.d.ts +6 -0
  106. package/es/socket/components/SocketMonitorPage.js +485 -0
  107. package/es/socket/components/index.d.ts +2 -0
  108. package/es/socket/components/index.js +2 -0
  109. package/es/socket/constants.d.ts +33 -0
  110. package/es/socket/constants.js +39 -0
  111. package/es/socket/events.d.ts +31 -0
  112. package/es/socket/events.js +19 -0
  113. package/es/socket/heartbeat.d.ts +66 -0
  114. package/es/socket/heartbeat.js +184 -0
  115. package/es/socket/index.d.ts +61 -0
  116. package/es/socket/index.js +246 -0
  117. package/es/socket/monitor.d.ts +169 -0
  118. package/es/socket/monitor.js +448 -0
  119. package/es/socket/reconnect.d.ts +61 -0
  120. package/es/socket/reconnect.js +199 -0
  121. package/es/socket/socket.d.ts +130 -0
  122. package/es/socket/socket.js +613 -0
  123. package/es/socket/types.d.ts +85 -0
  124. package/es/socket/types.js +35 -0
  125. package/es/storage/index.d.ts +17 -0
  126. package/es/storage/index.js +46 -0
  127. package/es/tasks/index.d.ts +127 -0
  128. package/es/tasks/index.js +1119 -0
  129. package/es/tasks/scheduledTasksExample.d.ts +61 -0
  130. package/es/tasks/scheduledTasksExample.js +351 -0
  131. package/es/tasks/type.d.ts +100 -0
  132. package/es/tasks/type.js +1 -0
  133. package/es/tasks/useTasks.d.ts +5 -0
  134. package/es/tasks/useTasks.js +25 -0
  135. package/es/type.d.ts +2 -0
  136. package/es/type.js +1 -0
  137. package/es/utils/adaptiveThrottle/index.d.ts +36 -0
  138. package/es/utils/adaptiveThrottle/index.js +136 -0
  139. package/es/variables/VariablesProvider.d.ts +7 -0
  140. package/es/variables/VariablesProvider.js +12 -0
  141. package/es/variables/config.d.ts +3 -0
  142. package/es/variables/config.js +16 -0
  143. package/es/variables/index.d.ts +6 -0
  144. package/es/variables/index.js +5 -0
  145. package/es/variables/type.d.ts +2 -0
  146. package/es/variables/type.js +1 -0
  147. package/es/website/index.d.ts +6 -0
  148. package/es/website/index.js +65 -0
  149. package/lib/app/app.d.ts +101 -0
  150. package/lib/app/app.js +171 -0
  151. package/lib/app/const.d.ts +4 -0
  152. package/lib/app/const.js +33 -0
  153. package/lib/app/index.d.ts +14 -0
  154. package/lib/app/index.js +76 -0
  155. package/lib/applicationManager/application.d.ts +197 -0
  156. package/lib/applicationManager/application.js +280 -0
  157. package/lib/applicationManager/index.d.ts +19 -0
  158. package/lib/applicationManager/index.js +88 -0
  159. package/lib/aws/index.d.ts +16 -0
  160. package/lib/aws/index.js +67 -0
  161. package/lib/cmd/const.d.ts +11 -0
  162. package/lib/cmd/const.js +39 -0
  163. package/lib/cmd/index.d.ts +13 -0
  164. package/lib/cmd/index.js +96 -0
  165. package/lib/cmd/type.d.ts +5 -0
  166. package/lib/cmd/type.js +17 -0
  167. package/lib/communicationManager/index.d.ts +59 -0
  168. package/lib/communicationManager/index.js +102 -0
  169. package/lib/config.d.ts +3 -0
  170. package/lib/config.js +36 -0
  171. package/lib/cookie/index.d.ts +13 -0
  172. package/lib/cookie/index.js +62 -0
  173. package/lib/css/global.less +73 -0
  174. package/lib/css/index.less +31 -0
  175. package/lib/css/variables.css +84 -0
  176. package/lib/data/index.d.ts +8 -0
  177. package/lib/data/index.js +38 -0
  178. package/lib/history/config.d.ts +24 -0
  179. package/lib/history/config.js +41 -0
  180. package/lib/history/index.d.ts +26 -0
  181. package/lib/history/index.js +99 -0
  182. package/lib/history/type.d.ts +2 -0
  183. package/lib/history/type.js +17 -0
  184. package/lib/hooks/index.d.ts +12 -0
  185. package/lib/hooks/index.js +44 -0
  186. package/lib/hooks/useDelayedValue/index.d.ts +2 -0
  187. package/lib/hooks/useDelayedValue/index.js +36 -0
  188. package/lib/hooks/useDispatch/index.d.ts +2 -0
  189. package/lib/hooks/useDispatch/index.js +26 -0
  190. package/lib/hooks/useLowCode/index.d.ts +13 -0
  191. package/lib/hooks/useLowCode/index.js +75 -0
  192. package/lib/hooks/useStore/index.d.ts +6 -0
  193. package/lib/hooks/useStore/index.js +33 -0
  194. package/lib/index.d.ts +8 -0
  195. package/lib/index.js +58 -0
  196. package/lib/indexDB/index.d.ts +296 -0
  197. package/lib/indexDB/index.js +767 -0
  198. package/lib/locales/en.d.ts +3 -0
  199. package/lib/locales/en.js +29 -0
  200. package/lib/locales/index.d.ts +39 -0
  201. package/lib/locales/index.js +159 -0
  202. package/lib/locales/original.d.ts +3 -0
  203. package/lib/locales/original.js +31 -0
  204. package/lib/locales/type.d.ts +19 -0
  205. package/lib/locales/type.js +17 -0
  206. package/lib/locales/zh-CN.d.ts +3 -0
  207. package/lib/locales/zh-CN.js +29 -0
  208. package/lib/locales/zh-HK.d.ts +3 -0
  209. package/lib/locales/zh-HK.js +29 -0
  210. package/lib/logger/feishu.d.ts +11 -0
  211. package/lib/logger/feishu.js +52 -0
  212. package/lib/logger/index.d.ts +135 -0
  213. package/lib/logger/index.js +476 -0
  214. package/lib/menuManager/hooks.d.ts +17 -0
  215. package/lib/menuManager/hooks.js +135 -0
  216. package/lib/menuManager/index.d.ts +28 -0
  217. package/lib/menuManager/index.js +125 -0
  218. package/lib/models/global.d.ts +32 -0
  219. package/lib/models/global.js +62 -0
  220. package/lib/models/index.d.ts +45 -0
  221. package/lib/models/index.js +69 -0
  222. package/lib/models/type.d.ts +2 -0
  223. package/lib/models/type.js +17 -0
  224. package/lib/plugin/index.d.ts +0 -0
  225. package/lib/plugin/index.js +0 -0
  226. package/lib/pubsub/example.d.ts +5 -0
  227. package/lib/pubsub/example.js +61 -0
  228. package/lib/pubsub/index.d.ts +73 -0
  229. package/lib/pubsub/index.js +141 -0
  230. package/lib/render/index.d.ts +0 -0
  231. package/lib/render/index.js +0 -0
  232. package/lib/request/cache.d.ts +46 -0
  233. package/lib/request/cache.js +195 -0
  234. package/lib/request/cancelToken.d.ts +38 -0
  235. package/lib/request/cancelToken.js +59 -0
  236. package/lib/request/config.d.ts +3 -0
  237. package/lib/request/config.js +69 -0
  238. package/lib/request/constants.d.ts +2 -0
  239. package/lib/request/constants.js +34 -0
  240. package/lib/request/index.d.ts +24 -0
  241. package/lib/request/index.js +210 -0
  242. package/lib/request/pisell2Request.d.ts +6 -0
  243. package/lib/request/pisell2Request.js +75 -0
  244. package/lib/request/type.d.ts +57 -0
  245. package/lib/request/type.js +36 -0
  246. package/lib/request/utils.d.ts +46 -0
  247. package/lib/request/utils.js +113 -0
  248. package/lib/routes/config.d.ts +7 -0
  249. package/lib/routes/config.js +50 -0
  250. package/lib/routes/index.d.ts +28 -0
  251. package/lib/routes/index.js +121 -0
  252. package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
  253. package/lib/socket/components/SocketMonitorPage.js +340 -0
  254. package/lib/socket/components/index.d.ts +2 -0
  255. package/lib/socket/components/index.js +39 -0
  256. package/lib/socket/constants.d.ts +33 -0
  257. package/lib/socket/constants.js +62 -0
  258. package/lib/socket/events.d.ts +31 -0
  259. package/lib/socket/events.js +44 -0
  260. package/lib/socket/heartbeat.d.ts +66 -0
  261. package/lib/socket/heartbeat.js +157 -0
  262. package/lib/socket/index.d.ts +61 -0
  263. package/lib/socket/index.js +198 -0
  264. package/lib/socket/monitor.d.ts +169 -0
  265. package/lib/socket/monitor.js +350 -0
  266. package/lib/socket/reconnect.d.ts +61 -0
  267. package/lib/socket/reconnect.js +157 -0
  268. package/lib/socket/socket.d.ts +130 -0
  269. package/lib/socket/socket.js +426 -0
  270. package/lib/socket/types.d.ts +85 -0
  271. package/lib/socket/types.js +36 -0
  272. package/lib/storage/index.d.ts +17 -0
  273. package/lib/storage/index.js +64 -0
  274. package/lib/tasks/index.d.ts +127 -0
  275. package/lib/tasks/index.js +710 -0
  276. package/lib/tasks/scheduledTasksExample.d.ts +61 -0
  277. package/lib/tasks/scheduledTasksExample.js +267 -0
  278. package/lib/tasks/type.d.ts +100 -0
  279. package/lib/tasks/type.js +17 -0
  280. package/lib/tasks/useTasks.d.ts +5 -0
  281. package/lib/tasks/useTasks.js +37 -0
  282. package/lib/type.d.ts +2 -0
  283. package/lib/type.js +17 -0
  284. package/lib/utils/adaptiveThrottle/index.d.ts +36 -0
  285. package/lib/utils/adaptiveThrottle/index.js +121 -0
  286. package/lib/variables/VariablesProvider.d.ts +7 -0
  287. package/lib/variables/VariablesProvider.js +51 -0
  288. package/lib/variables/config.d.ts +3 -0
  289. package/lib/variables/config.js +38 -0
  290. package/lib/variables/index.d.ts +6 -0
  291. package/lib/variables/index.js +29 -0
  292. package/lib/variables/type.d.ts +2 -0
  293. package/lib/variables/type.js +17 -0
  294. package/lib/website/index.d.ts +6 -0
  295. package/lib/website/index.js +75 -0
  296. package/package.json +49 -0
@@ -0,0 +1,157 @@
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/socket/heartbeat.ts
20
+ var heartbeat_exports = {};
21
+ __export(heartbeat_exports, {
22
+ HeartbeatManager: () => HeartbeatManager
23
+ });
24
+ module.exports = __toCommonJS(heartbeat_exports);
25
+ var import_constants = require("./constants");
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
+ /**
38
+ * 创建心跳管理器
39
+ * @param options 心跳配置选项
40
+ * @param sendHeartbeat 发送心跳的回调函数
41
+ * @param callbacks 回调函数集合
42
+ */
43
+ constructor(options, sendHeartbeat, callbacks = {}) {
44
+ this.options = {
45
+ ...options,
46
+ interval: Math.max(options.interval, import_constants.MIN_HEARTBEAT_INTERVAL),
47
+ message: options.message || import_constants.DEFAULT_HEARTBEAT_MESSAGE
48
+ };
49
+ this.sendHeartbeat = sendHeartbeat;
50
+ this.onTimeout = callbacks.onTimeout || (() => {
51
+ });
52
+ this.onResponse = callbacks.onResponse || (() => {
53
+ });
54
+ }
55
+ /**
56
+ * 启动心跳检测
57
+ */
58
+ start() {
59
+ if (this.active) {
60
+ return;
61
+ }
62
+ this.active = true;
63
+ this.scheduleHeartbeat();
64
+ }
65
+ /**
66
+ * 停止心跳检测
67
+ */
68
+ stop() {
69
+ this.active = false;
70
+ this.clearTimers();
71
+ }
72
+ /**
73
+ * 重启心跳检测
74
+ */
75
+ restart() {
76
+ this.stop();
77
+ this.start();
78
+ }
79
+ /**
80
+ * 接收到心跳响应
81
+ */
82
+ receiveHeartbeatResponse() {
83
+ this.lastHeartbeatResponse = Date.now();
84
+ if (this.timeoutTimer) {
85
+ clearTimeout(this.timeoutTimer);
86
+ this.timeoutTimer = null;
87
+ }
88
+ this.onResponse();
89
+ }
90
+ /**
91
+ * 获取上次心跳时间
92
+ */
93
+ getLastHeartbeatTime() {
94
+ return this.lastHeartbeatTime;
95
+ }
96
+ /**
97
+ * 获取上次心跳响应时间
98
+ */
99
+ getLastHeartbeatResponseTime() {
100
+ return this.lastHeartbeatResponse;
101
+ }
102
+ /**
103
+ * 获取心跳是否活跃
104
+ */
105
+ isActive() {
106
+ return this.active;
107
+ }
108
+ /**
109
+ * 安排下一次心跳
110
+ */
111
+ scheduleHeartbeat() {
112
+ if (!this.active) {
113
+ return;
114
+ }
115
+ this.clearTimers();
116
+ this.intervalTimer = setInterval(() => {
117
+ this.sendHeartbeatMessage();
118
+ }, this.options.interval);
119
+ this.sendHeartbeatMessage();
120
+ }
121
+ /**
122
+ * 发送心跳消息
123
+ */
124
+ sendHeartbeatMessage() {
125
+ if (!this.active) {
126
+ return;
127
+ }
128
+ this.lastHeartbeatTime = Date.now();
129
+ if (this.timeoutTimer) {
130
+ clearTimeout(this.timeoutTimer);
131
+ this.timeoutTimer = null;
132
+ }
133
+ this.sendHeartbeat(this.options.message);
134
+ this.timeoutTimer = setTimeout(() => {
135
+ if (this.active) {
136
+ this.onTimeout();
137
+ }
138
+ }, this.options.timeout);
139
+ }
140
+ /**
141
+ * 清除所有计时器
142
+ */
143
+ clearTimers() {
144
+ if (this.intervalTimer) {
145
+ clearInterval(this.intervalTimer);
146
+ this.intervalTimer = null;
147
+ }
148
+ if (this.timeoutTimer) {
149
+ clearTimeout(this.timeoutTimer);
150
+ this.timeoutTimer = null;
151
+ }
152
+ }
153
+ };
154
+ // Annotate the CommonJS export names for ESM import in node:
155
+ 0 && (module.exports = {
156
+ HeartbeatManager
157
+ });
@@ -0,0 +1,61 @@
1
+ import { Socket } from './socket';
2
+ import { SocketOptions, SocketStatus, SocketMessage } from './types';
3
+ import { SocketEvents } from './events';
4
+ import { SocketMonitor, SocketMonitorOptions, SocketHistoryItem, SocketStatusItem, SocketStats } from './monitor';
5
+ import * as components from './components';
6
+ /**
7
+ * 创建Socket实例
8
+ * @param url WebSocket连接URL
9
+ * @param options Socket配置选项
10
+ */
11
+ export declare function createSocket(url: string, options?: Partial<Omit<SocketOptions, 'url'>>): Socket;
12
+ declare const _default: {
13
+ /**
14
+ * 创建新的Socket实例
15
+ */
16
+ create: (url: string, options?: Partial<Omit<SocketOptions, "url">>, key?: string | undefined) => Socket;
17
+ /**
18
+ * 获取指定键的Socket实例
19
+ */
20
+ get: (key: string) => Socket | undefined;
21
+ /**
22
+ * 移除Socket实例
23
+ */
24
+ remove: (key: string) => boolean;
25
+ /**
26
+ * 关闭并移除所有Socket实例
27
+ */
28
+ closeAll: () => void;
29
+ /**
30
+ * 检查指定键的Socket是否存在
31
+ */
32
+ has: (key: string) => boolean;
33
+ /**
34
+ * 获取所有Socket标识键
35
+ */
36
+ getKeys: () => string[];
37
+ /**
38
+ * 获取所有Socket实例
39
+ */
40
+ getAllSockets: () => Socket[];
41
+ /**
42
+ * 为指定的Socket启用监控
43
+ */
44
+ enableMonitoring: (key: string, options?: SocketMonitorOptions | undefined) => SocketMonitor | null;
45
+ /**
46
+ * 获取指定Socket的监控器
47
+ */
48
+ getMonitor: (key: string) => SocketMonitor | null;
49
+ /**
50
+ * 获取所有Socket的监控信息
51
+ */
52
+ getAllMonitors: () => Map<string, SocketMonitor | null>;
53
+ /**
54
+ * 监控组件
55
+ */
56
+ components: typeof components;
57
+ };
58
+ export default _default;
59
+ export { Socket, SocketMonitor };
60
+ export type { SocketOptions, SocketMessage, SocketMonitorOptions, SocketHistoryItem, SocketStatusItem, SocketStats };
61
+ export { SocketStatus, SocketEvents };
@@ -0,0 +1,198 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/socket/index.ts
30
+ var socket_exports = {};
31
+ __export(socket_exports, {
32
+ Socket: () => import_socket.Socket,
33
+ SocketEvents: () => import_events.SocketEvents,
34
+ SocketMonitor: () => import_monitor.SocketMonitor,
35
+ SocketStatus: () => import_types.SocketStatus,
36
+ createSocket: () => createSocket,
37
+ default: () => socket_default
38
+ });
39
+ module.exports = __toCommonJS(socket_exports);
40
+ var import_socket = require("./socket");
41
+ var import_types = require("./types");
42
+ var import_events = require("./events");
43
+ var import_monitor = require("./monitor");
44
+ var components = __toESM(require("./components"));
45
+ function createSocket(url, options = {}) {
46
+ return new import_socket.Socket({ url, ...options });
47
+ }
48
+ var SocketFactory = class {
49
+ sockets = /* @__PURE__ */ new Map();
50
+ /**
51
+ * 创建新的Socket实例
52
+ * @param url WebSocket连接URL
53
+ * @param options Socket配置选项
54
+ * @param key 可选的标识键,用于后续获取该Socket实例
55
+ */
56
+ create(url, options = {}, key) {
57
+ const socket = new import_socket.Socket({ url, ...options });
58
+ if (key) {
59
+ this.sockets.set(key, socket);
60
+ }
61
+ return socket;
62
+ }
63
+ /**
64
+ * 获取Socket实例
65
+ * @param key Socket标识键
66
+ */
67
+ get(key) {
68
+ return this.sockets.get(key);
69
+ }
70
+ /**
71
+ * 移除Socket实例
72
+ * @param key Socket标识键
73
+ */
74
+ remove(key) {
75
+ const socket = this.sockets.get(key);
76
+ if (socket) {
77
+ socket.destroy();
78
+ return this.sockets.delete(key);
79
+ }
80
+ return false;
81
+ }
82
+ /**
83
+ * 关闭并移除所有Socket实例
84
+ */
85
+ closeAll() {
86
+ for (const socket of this.sockets.values()) {
87
+ socket.destroy();
88
+ }
89
+ this.sockets.clear();
90
+ }
91
+ /**
92
+ * 检查指定键的Socket是否存在
93
+ * @param key Socket标识键
94
+ */
95
+ has(key) {
96
+ return this.sockets.has(key);
97
+ }
98
+ /**
99
+ * 获取所有Socket实例的标识键
100
+ */
101
+ getKeys() {
102
+ return Array.from(this.sockets.keys());
103
+ }
104
+ /**
105
+ * 获取所有Socket实例
106
+ */
107
+ getAllSockets() {
108
+ return Array.from(this.sockets.values());
109
+ }
110
+ /**
111
+ * 为指定的Socket启用监控
112
+ * @param key Socket标识键
113
+ * @param options 监控配置选项
114
+ */
115
+ enableMonitoring(key, options) {
116
+ const socket = this.get(key);
117
+ if (socket) {
118
+ return socket.enableMonitoring(options);
119
+ }
120
+ return null;
121
+ }
122
+ /**
123
+ * 获取指定Socket的监控器
124
+ * @param key Socket标识键
125
+ */
126
+ getMonitor(key) {
127
+ const socket = this.get(key);
128
+ if (socket) {
129
+ return socket.getMonitor();
130
+ }
131
+ return null;
132
+ }
133
+ /**
134
+ * 获取所有Socket的监控信息
135
+ */
136
+ getAllMonitors() {
137
+ const result = /* @__PURE__ */ new Map();
138
+ for (const [key, socket] of this.sockets.entries()) {
139
+ result.set(key, socket.getMonitor());
140
+ }
141
+ return result;
142
+ }
143
+ };
144
+ var socketFactory = new SocketFactory();
145
+ var socket_default = {
146
+ /**
147
+ * 创建新的Socket实例
148
+ */
149
+ create: socketFactory.create.bind(socketFactory),
150
+ /**
151
+ * 获取指定键的Socket实例
152
+ */
153
+ get: socketFactory.get.bind(socketFactory),
154
+ /**
155
+ * 移除Socket实例
156
+ */
157
+ remove: socketFactory.remove.bind(socketFactory),
158
+ /**
159
+ * 关闭并移除所有Socket实例
160
+ */
161
+ closeAll: socketFactory.closeAll.bind(socketFactory),
162
+ /**
163
+ * 检查指定键的Socket是否存在
164
+ */
165
+ has: socketFactory.has.bind(socketFactory),
166
+ /**
167
+ * 获取所有Socket标识键
168
+ */
169
+ getKeys: socketFactory.getKeys.bind(socketFactory),
170
+ /**
171
+ * 获取所有Socket实例
172
+ */
173
+ getAllSockets: socketFactory.getAllSockets.bind(socketFactory),
174
+ /**
175
+ * 为指定的Socket启用监控
176
+ */
177
+ enableMonitoring: socketFactory.enableMonitoring.bind(socketFactory),
178
+ /**
179
+ * 获取指定Socket的监控器
180
+ */
181
+ getMonitor: socketFactory.getMonitor.bind(socketFactory),
182
+ /**
183
+ * 获取所有Socket的监控信息
184
+ */
185
+ getAllMonitors: socketFactory.getAllMonitors.bind(socketFactory),
186
+ /**
187
+ * 监控组件
188
+ */
189
+ components
190
+ };
191
+ // Annotate the CommonJS export names for ESM import in node:
192
+ 0 && (module.exports = {
193
+ Socket,
194
+ SocketEvents,
195
+ SocketMonitor,
196
+ SocketStatus,
197
+ createSocket
198
+ });
@@ -0,0 +1,169 @@
1
+ import { Socket } from './socket';
2
+ import { SocketMessage, SocketStatus } from './types';
3
+ /**
4
+ * Socket历史消息记录项
5
+ */
6
+ export interface SocketHistoryItem {
7
+ /** 消息ID */
8
+ id: string;
9
+ /** 消息时间戳 */
10
+ timestamp: number;
11
+ /** 消息方向(发送/接收) */
12
+ direction: 'in' | 'out';
13
+ /** 消息内容 */
14
+ message: SocketMessage;
15
+ /** 消息大小(字节) */
16
+ size?: number;
17
+ }
18
+ /**
19
+ * Socket状态记录项
20
+ */
21
+ export interface SocketStatusItem {
22
+ /** 状态变更时间戳 */
23
+ timestamp: number;
24
+ /** 变更前状态 */
25
+ from: SocketStatus;
26
+ /** 变更后状态 */
27
+ to: SocketStatus;
28
+ /** 相关事件(如果有) */
29
+ event?: string;
30
+ /** 附加信息 */
31
+ info?: any;
32
+ }
33
+ /**
34
+ * Socket监控配置选项
35
+ */
36
+ export interface SocketMonitorOptions {
37
+ /** 最大历史消息记录数 */
38
+ maxHistoryItems?: number;
39
+ /** 最大状态变更记录数 */
40
+ maxStatusItems?: number;
41
+ /** 是否记录消息内容 */
42
+ recordMessageContent?: boolean;
43
+ /** 是否自动开始监控 */
44
+ autoStart?: boolean;
45
+ /** 过滤掉的消息类型(不记录) */
46
+ excludeEvents?: string[];
47
+ }
48
+ /**
49
+ * Socket监控统计信息
50
+ */
51
+ export interface SocketStats {
52
+ /** 总发送消息数 */
53
+ totalSent: number;
54
+ /** 总接收消息数 */
55
+ totalReceived: number;
56
+ /** 总发送字节数 */
57
+ bytesSent: number;
58
+ /** 总接收字节数 */
59
+ bytesReceived: number;
60
+ /** 连接次数 */
61
+ connectionCount: number;
62
+ /** 重连次数 */
63
+ reconnectionCount: number;
64
+ /** 错误次数 */
65
+ errorCount: number;
66
+ /** 心跳发送次数 */
67
+ heartbeatCount: number;
68
+ /** 心跳超时次数 */
69
+ heartbeatTimeoutCount: number;
70
+ /** 首次连接时间 */
71
+ firstConnectTime: number | null;
72
+ /** 最后连接时间 */
73
+ lastConnectTime: number | null;
74
+ /** 当前连接持续时间(毫秒,连接状态下有效) */
75
+ currentConnectionDuration: number | null;
76
+ /** 平均消息大小(字节) */
77
+ averageMessageSize: number;
78
+ }
79
+ /**
80
+ * Socket监控器
81
+ * 用于监控Socket的连接状态和消息历史
82
+ */
83
+ export declare class SocketMonitor {
84
+ private socket;
85
+ private options;
86
+ private isMonitoring;
87
+ private messageHistory;
88
+ private statusHistory;
89
+ private stats;
90
+ private connectStartTime;
91
+ private eventHandlers;
92
+ /**
93
+ * 创建Socket监控器
94
+ * @param socket 要监控的Socket实例
95
+ * @param options 监控配置选项
96
+ */
97
+ constructor(socket: Socket, options?: SocketMonitorOptions);
98
+ /**
99
+ * 开始监控
100
+ */
101
+ start(): void;
102
+ /**
103
+ * 停止监控
104
+ */
105
+ stop(): void;
106
+ /**
107
+ * 检查监控器是否处于活跃状态
108
+ */
109
+ isActive(): boolean;
110
+ /**
111
+ * 清除历史记录
112
+ */
113
+ clearHistory(): void;
114
+ /**
115
+ * 重置统计数据
116
+ */
117
+ resetStats(): void;
118
+ /**
119
+ * 获取消息历史记录
120
+ * @param limit 返回的最大记录数
121
+ * @param direction 消息方向过滤
122
+ */
123
+ getMessageHistory(limit?: number, direction?: 'in' | 'out'): SocketHistoryItem[];
124
+ /**
125
+ * 获取状态变更历史
126
+ * @param limit 返回的最大记录数
127
+ */
128
+ getStatusHistory(limit?: number): SocketStatusItem[];
129
+ /**
130
+ * 获取统计信息
131
+ */
132
+ getStats(): SocketStats;
133
+ /**
134
+ * 设置监控事件监听
135
+ */
136
+ private setupEventListeners;
137
+ /**
138
+ * 移除监控事件监听
139
+ */
140
+ private removeEventListeners;
141
+ /**
142
+ * 记录已发送的消息
143
+ */
144
+ private recordMessageSent;
145
+ /**
146
+ * 记录已接收的消息
147
+ */
148
+ private recordMessageReceived;
149
+ /**
150
+ * 记录状态变化
151
+ */
152
+ private recordStatusChange;
153
+ /**
154
+ * 添加消息到历史记录,并控制记录数量
155
+ */
156
+ private addToMessageHistory;
157
+ /**
158
+ * 添加状态到历史记录,并控制记录数量
159
+ */
160
+ private addToStatusHistory;
161
+ /**
162
+ * 更新平均消息大小
163
+ */
164
+ private updateAverageMessageSize;
165
+ /**
166
+ * 释放资源
167
+ */
168
+ destroy(): void;
169
+ }