@pisell/core 1.0.0 → 1.0.1

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 (281) hide show
  1. package/es/app/app.d.ts +122 -0
  2. package/es/app/app.js +166 -0
  3. package/es/app/const.d.ts +4 -0
  4. package/es/app/const.js +6 -0
  5. package/es/app/index.d.ts +14 -0
  6. package/es/app/index.js +54 -0
  7. package/es/applicationManager/application.d.ts +50 -0
  8. package/es/applicationManager/application.js +226 -0
  9. package/es/applicationManager/index.d.ts +13 -0
  10. package/es/applicationManager/index.js +190 -0
  11. package/es/config.d.ts +3 -3
  12. package/es/cookie/index.d.ts +13 -0
  13. package/es/cookie/index.js +47 -0
  14. package/es/css/global.less +73 -0
  15. package/es/css/index.less +31 -0
  16. package/es/css/variables.css +84 -0
  17. package/es/data/index.d.ts +29 -0
  18. package/es/data/index.js +8 -0
  19. package/es/history/config.d.ts +24 -0
  20. package/es/history/config.js +43 -0
  21. package/es/history/index.d.ts +20 -0
  22. package/es/history/index.js +41 -0
  23. package/es/history/type.d.ts +2 -0
  24. package/es/hooks/index.d.ts +12 -0
  25. package/es/hooks/index.js +13 -0
  26. package/es/hooks/useDelayedValue/index.d.ts +2 -0
  27. package/es/hooks/useDelayedValue/index.js +26 -0
  28. package/es/hooks/useDispatch/index.d.ts +2 -0
  29. package/es/hooks/useDispatch/index.js +2 -0
  30. package/es/hooks/useLowCode/index.d.ts +13 -0
  31. package/es/hooks/useLowCode/index.js +74 -0
  32. package/es/hooks/useStore/index.d.ts +6 -0
  33. package/es/hooks/useStore/index.js +11 -0
  34. package/es/index.d.ts +7 -1
  35. package/es/index.js +8 -2
  36. package/es/indexDB/index.d.ts +176 -0
  37. package/es/indexDB/index.js +536 -0
  38. package/es/locales/config.js +10 -8
  39. package/es/locales/en.d.ts +2 -1
  40. package/es/locales/en.js +5 -1
  41. package/es/locales/index.d.ts +44 -1
  42. package/es/locales/index.js +192 -8
  43. package/es/locales/original.d.ts +3 -0
  44. package/es/locales/original.js +7 -0
  45. package/es/locales/type.d.ts +15 -5
  46. package/es/locales/zh-CN.d.ts +2 -1
  47. package/es/locales/zh-CN.js +5 -1
  48. package/es/locales/zh-HK.d.ts +2 -1
  49. package/es/locales/zh-HK.js +5 -1
  50. package/es/logger/feishu.d.ts +11 -0
  51. package/es/logger/feishu.js +50 -0
  52. package/es/logger/index.d.ts +122 -0
  53. package/es/logger/index.js +531 -0
  54. package/es/menuManager/hooks.d.ts +8 -0
  55. package/es/menuManager/hooks.js +138 -0
  56. package/es/menuManager/index.d.ts +28 -0
  57. package/es/menuManager/index.js +142 -0
  58. package/es/models/global.d.ts +32 -0
  59. package/es/models/global.js +65 -0
  60. package/es/models/index.d.ts +45 -0
  61. package/es/models/index.js +66 -0
  62. package/es/models/tasks.d.ts +31 -0
  63. package/es/models/tasks.js +331 -0
  64. package/es/models/tasksUtils.d.ts +65 -0
  65. package/es/models/tasksUtils.js +179 -0
  66. package/es/models/type.d.ts +2 -0
  67. package/es/models/type.js +1 -0
  68. package/es/plugin/index.d.ts +0 -0
  69. package/es/plugin/index.js +0 -0
  70. package/es/pubsub/example.d.ts +5 -0
  71. package/es/pubsub/example.js +92 -0
  72. package/es/pubsub/index.d.ts +63 -0
  73. package/es/pubsub/index.js +144 -0
  74. package/es/request/cache.d.ts +46 -0
  75. package/es/request/cache.js +310 -0
  76. package/es/request/cancelToken.d.ts +38 -0
  77. package/es/request/cancelToken.js +59 -0
  78. package/es/request/config.d.ts +3 -0
  79. package/es/request/config.js +58 -0
  80. package/es/request/constants.d.ts +2 -0
  81. package/es/request/constants.js +6 -0
  82. package/es/request/index.d.ts +24 -0
  83. package/es/request/index.js +175 -0
  84. package/es/request/pisell2Request.d.ts +6 -0
  85. package/es/request/pisell2Request.js +62 -0
  86. package/es/request/type.d.ts +40 -0
  87. package/es/request/type.js +1 -0
  88. package/es/request/utils.d.ts +46 -0
  89. package/es/request/utils.js +145 -0
  90. package/es/routes/config.d.ts +7 -0
  91. package/es/routes/config.js +17 -0
  92. package/es/routes/index.d.ts +28 -0
  93. package/es/routes/index.js +154 -0
  94. package/es/socket/components/SocketMonitorPage.d.ts +6 -0
  95. package/es/socket/components/SocketMonitorPage.js +692 -0
  96. package/es/socket/components/index.d.ts +2 -0
  97. package/es/socket/components/index.js +2 -0
  98. package/es/socket/constants.d.ts +33 -0
  99. package/es/socket/constants.js +39 -0
  100. package/es/socket/events.d.ts +31 -0
  101. package/es/socket/events.js +19 -0
  102. package/es/socket/heartbeat.d.ts +66 -0
  103. package/es/socket/heartbeat.js +185 -0
  104. package/es/socket/index.d.ts +61 -0
  105. package/es/socket/index.js +246 -0
  106. package/es/socket/monitor.d.ts +169 -0
  107. package/es/socket/monitor.js +438 -0
  108. package/es/socket/reconnect.d.ts +61 -0
  109. package/es/socket/reconnect.js +199 -0
  110. package/es/socket/socket.d.ts +129 -0
  111. package/es/socket/socket.js +597 -0
  112. package/es/socket/types.d.ts +84 -0
  113. package/es/socket/types.js +19 -0
  114. package/es/storage/config.d.ts +3 -0
  115. package/es/{date → storage}/config.js +1 -6
  116. package/es/storage/index.d.ts +42 -0
  117. package/es/storage/index.js +62 -0
  118. package/es/storage/type.d.ts +5 -0
  119. package/es/storage/type.js +1 -0
  120. package/es/tasks/index.d.ts +77 -0
  121. package/es/tasks/index.js +719 -0
  122. package/es/tasks/type.d.ts +62 -0
  123. package/es/tasks/type.js +1 -0
  124. package/es/tasks/useTasks.d.ts +4 -0
  125. package/es/tasks/useTasks.js +25 -0
  126. package/es/type.d.ts +1 -1
  127. package/es/variables/VariablesProvider.d.ts +7 -0
  128. package/es/variables/VariablesProvider.js +14 -0
  129. package/es/variables/config.d.ts +3 -0
  130. package/es/{date/index.js → variables/config.js} +8 -14
  131. package/es/variables/index.d.ts +6 -0
  132. package/es/variables/index.js +5 -0
  133. package/es/variables/type.d.ts +2 -0
  134. package/es/variables/type.js +1 -0
  135. package/es/website/index.d.ts +6 -0
  136. package/es/website/index.js +65 -0
  137. package/lib/app/app.d.ts +122 -0
  138. package/lib/app/app.js +128 -0
  139. package/lib/app/const.d.ts +4 -0
  140. package/lib/app/const.js +33 -0
  141. package/lib/app/index.d.ts +14 -0
  142. package/lib/app/index.js +76 -0
  143. package/lib/applicationManager/application.d.ts +50 -0
  144. package/lib/applicationManager/application.js +110 -0
  145. package/lib/applicationManager/index.d.ts +13 -0
  146. package/lib/applicationManager/index.js +76 -0
  147. package/lib/config.d.ts +3 -3
  148. package/lib/cookie/index.d.ts +13 -0
  149. package/lib/cookie/index.js +64 -0
  150. package/lib/css/global.less +73 -0
  151. package/lib/css/index.less +31 -0
  152. package/lib/css/variables.css +84 -0
  153. package/lib/data/index.d.ts +29 -0
  154. package/lib/{date → data}/index.js +19 -20
  155. package/lib/history/config.d.ts +24 -0
  156. package/lib/history/config.js +41 -0
  157. package/lib/history/index.d.ts +20 -0
  158. package/lib/history/index.js +58 -0
  159. package/lib/history/type.d.ts +2 -0
  160. package/lib/history/type.js +17 -0
  161. package/lib/hooks/index.d.ts +12 -0
  162. package/lib/hooks/index.js +44 -0
  163. package/lib/hooks/useDelayedValue/index.d.ts +2 -0
  164. package/lib/hooks/useDelayedValue/index.js +36 -0
  165. package/lib/hooks/useDispatch/index.d.ts +2 -0
  166. package/lib/hooks/useDispatch/index.js +26 -0
  167. package/lib/hooks/useLowCode/index.d.ts +13 -0
  168. package/lib/hooks/useLowCode/index.js +75 -0
  169. package/lib/hooks/useStore/index.d.ts +6 -0
  170. package/lib/hooks/useStore/index.js +33 -0
  171. package/lib/index.d.ts +7 -1
  172. package/lib/index.js +23 -5
  173. package/lib/indexDB/index.d.ts +176 -0
  174. package/lib/indexDB/index.js +287 -0
  175. package/lib/locales/config.js +10 -7
  176. package/lib/locales/en.d.ts +2 -1
  177. package/lib/locales/en.js +5 -1
  178. package/lib/locales/index.d.ts +44 -1
  179. package/lib/locales/index.js +106 -4
  180. package/lib/locales/original.d.ts +3 -0
  181. package/lib/locales/original.js +31 -0
  182. package/lib/locales/type.d.ts +15 -5
  183. package/lib/locales/zh-CN.d.ts +2 -1
  184. package/lib/locales/zh-CN.js +5 -1
  185. package/lib/locales/zh-HK.d.ts +2 -1
  186. package/lib/locales/zh-HK.js +5 -1
  187. package/lib/logger/feishu.d.ts +11 -0
  188. package/lib/logger/feishu.js +52 -0
  189. package/lib/logger/index.d.ts +122 -0
  190. package/lib/logger/index.js +288 -0
  191. package/lib/menuManager/hooks.d.ts +8 -0
  192. package/lib/menuManager/hooks.js +135 -0
  193. package/lib/menuManager/index.d.ts +28 -0
  194. package/lib/menuManager/index.js +110 -0
  195. package/lib/models/global.d.ts +32 -0
  196. package/lib/models/global.js +62 -0
  197. package/lib/models/index.d.ts +45 -0
  198. package/lib/models/index.js +70 -0
  199. package/lib/models/tasks.d.ts +31 -0
  200. package/lib/models/tasks.js +199 -0
  201. package/lib/models/tasksUtils.d.ts +65 -0
  202. package/lib/models/tasksUtils.js +160 -0
  203. package/lib/models/type.d.ts +2 -0
  204. package/lib/models/type.js +17 -0
  205. package/lib/plugin/index.d.ts +0 -0
  206. package/lib/plugin/index.js +0 -0
  207. package/lib/pubsub/example.d.ts +5 -0
  208. package/lib/pubsub/example.js +61 -0
  209. package/lib/pubsub/index.d.ts +63 -0
  210. package/lib/pubsub/index.js +129 -0
  211. package/lib/request/cache.d.ts +46 -0
  212. package/lib/request/cache.js +159 -0
  213. package/lib/request/cancelToken.d.ts +38 -0
  214. package/lib/request/cancelToken.js +59 -0
  215. package/lib/request/config.d.ts +3 -0
  216. package/lib/request/config.js +74 -0
  217. package/lib/request/constants.d.ts +2 -0
  218. package/lib/request/constants.js +34 -0
  219. package/lib/request/index.d.ts +24 -0
  220. package/lib/request/index.js +143 -0
  221. package/lib/request/pisell2Request.d.ts +6 -0
  222. package/lib/request/pisell2Request.js +75 -0
  223. package/lib/request/type.d.ts +40 -0
  224. package/lib/request/type.js +17 -0
  225. package/lib/request/utils.d.ts +46 -0
  226. package/lib/request/utils.js +111 -0
  227. package/lib/routes/config.d.ts +7 -0
  228. package/lib/routes/config.js +50 -0
  229. package/lib/routes/index.d.ts +28 -0
  230. package/lib/routes/index.js +118 -0
  231. package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
  232. package/lib/socket/components/SocketMonitorPage.js +346 -0
  233. package/lib/socket/components/index.d.ts +2 -0
  234. package/lib/socket/components/index.js +39 -0
  235. package/lib/socket/constants.d.ts +33 -0
  236. package/lib/socket/constants.js +62 -0
  237. package/lib/socket/events.d.ts +31 -0
  238. package/lib/socket/events.js +44 -0
  239. package/lib/socket/heartbeat.d.ts +66 -0
  240. package/lib/socket/heartbeat.js +152 -0
  241. package/lib/socket/index.d.ts +61 -0
  242. package/lib/socket/index.js +200 -0
  243. package/lib/socket/monitor.d.ts +169 -0
  244. package/lib/socket/monitor.js +346 -0
  245. package/lib/socket/reconnect.d.ts +61 -0
  246. package/lib/socket/reconnect.js +153 -0
  247. package/lib/socket/socket.d.ts +129 -0
  248. package/lib/socket/socket.js +410 -0
  249. package/lib/socket/types.d.ts +84 -0
  250. package/lib/socket/types.js +36 -0
  251. package/lib/storage/config.d.ts +3 -0
  252. package/lib/{date → storage}/config.js +2 -7
  253. package/lib/storage/index.d.ts +42 -0
  254. package/lib/storage/index.js +66 -0
  255. package/lib/storage/type.d.ts +5 -0
  256. package/lib/storage/type.js +17 -0
  257. package/lib/tasks/index.d.ts +77 -0
  258. package/lib/tasks/index.js +438 -0
  259. package/lib/tasks/type.d.ts +62 -0
  260. package/lib/{date → tasks}/type.js +1 -1
  261. package/lib/tasks/useTasks.d.ts +4 -0
  262. package/lib/tasks/useTasks.js +37 -0
  263. package/lib/type.d.ts +1 -1
  264. package/lib/variables/VariablesProvider.d.ts +7 -0
  265. package/lib/variables/VariablesProvider.js +51 -0
  266. package/lib/variables/config.d.ts +3 -0
  267. package/lib/variables/config.js +38 -0
  268. package/lib/variables/index.d.ts +6 -0
  269. package/lib/variables/index.js +29 -0
  270. package/lib/variables/type.d.ts +2 -0
  271. package/lib/variables/type.js +17 -0
  272. package/lib/website/index.d.ts +6 -0
  273. package/lib/website/index.js +75 -0
  274. package/package.json +13 -3
  275. package/es/date/config.d.ts +0 -3
  276. package/es/date/index.d.ts +0 -7
  277. package/es/date/type.d.ts +0 -7
  278. package/lib/date/config.d.ts +0 -3
  279. package/lib/date/index.d.ts +0 -7
  280. package/lib/date/type.d.ts +0 -7
  281. /package/es/{date → history}/type.js +0 -0
@@ -0,0 +1,62 @@
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/constants.ts
20
+ var constants_exports = {};
21
+ __export(constants_exports, {
22
+ DEFAULT_HEARTBEAT_MESSAGE: () => DEFAULT_HEARTBEAT_MESSAGE,
23
+ DEFAULT_HEARTBEAT_RESPONSE: () => DEFAULT_HEARTBEAT_RESPONSE,
24
+ DEFAULT_SOCKET_OPTIONS: () => DEFAULT_SOCKET_OPTIONS,
25
+ MIN_HEARTBEAT_INTERVAL: () => MIN_HEARTBEAT_INTERVAL,
26
+ MIN_RECONNECTION_DELAY: () => MIN_RECONNECTION_DELAY,
27
+ WS_STATUS_MAP: () => WS_STATUS_MAP
28
+ });
29
+ module.exports = __toCommonJS(constants_exports);
30
+ var DEFAULT_SOCKET_OPTIONS = {
31
+ autoConnect: true,
32
+ reconnection: true,
33
+ reconnectionAttempts: Infinity,
34
+ reconnectionDelay: 1e3,
35
+ reconnectionDelayMax: 5e3,
36
+ heartbeat: true,
37
+ heartbeatInterval: 3e4,
38
+ heartbeatTimeout: 1e4,
39
+ timeout: 2e4
40
+ };
41
+ var DEFAULT_HEARTBEAT_MESSAGE = {
42
+ type: "ping"
43
+ };
44
+ var DEFAULT_HEARTBEAT_RESPONSE = "pong";
45
+ var MIN_HEARTBEAT_INTERVAL = 1e3;
46
+ var MIN_RECONNECTION_DELAY = 500;
47
+ var WS_STATUS_MAP = {
48
+ 0: "连接中",
49
+ 1: "已连接",
50
+ 2: "关闭中",
51
+ 3: "已关闭",
52
+ 4: "重连中"
53
+ };
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ DEFAULT_HEARTBEAT_MESSAGE,
57
+ DEFAULT_HEARTBEAT_RESPONSE,
58
+ DEFAULT_SOCKET_OPTIONS,
59
+ MIN_HEARTBEAT_INTERVAL,
60
+ MIN_RECONNECTION_DELAY,
61
+ WS_STATUS_MAP
62
+ });
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Socket标准事件类型
3
+ */
4
+ export declare enum SocketEvents {
5
+ /** 连接成功事件 */
6
+ CONNECT = "connect",
7
+ /** 连接断开事件 */
8
+ DISCONNECT = "disconnect",
9
+ /** 连接错误事件 */
10
+ ERROR = "error",
11
+ /** 接收消息事件 */
12
+ MESSAGE = "message",
13
+ /** 发送消息事件 */
14
+ SEND = "send",
15
+ /** 重连中事件 */
16
+ RECONNECTING = "reconnecting",
17
+ /** 重连尝试事件 */
18
+ RECONNECT_ATTEMPT = "reconnect_attempt",
19
+ /** 重连成功事件 */
20
+ RECONNECT = "reconnect",
21
+ /** 重连失败事件 */
22
+ RECONNECT_ERROR = "reconnect_error",
23
+ /** 重连次数超限 */
24
+ RECONNECT_FAILED = "reconnect_failed",
25
+ /** 心跳发送事件 */
26
+ HEARTBEAT = "heartbeat",
27
+ /** 心跳响应事件 */
28
+ HEARTBEAT_RESPONSE = "heartbeat_response",
29
+ /** 心跳超时事件 */
30
+ HEARTBEAT_TIMEOUT = "heartbeat_timeout"
31
+ }
@@ -0,0 +1,44 @@
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/events.ts
20
+ var events_exports = {};
21
+ __export(events_exports, {
22
+ SocketEvents: () => SocketEvents
23
+ });
24
+ module.exports = __toCommonJS(events_exports);
25
+ var SocketEvents = /* @__PURE__ */ ((SocketEvents2) => {
26
+ SocketEvents2["CONNECT"] = "connect";
27
+ SocketEvents2["DISCONNECT"] = "disconnect";
28
+ SocketEvents2["ERROR"] = "error";
29
+ SocketEvents2["MESSAGE"] = "message";
30
+ SocketEvents2["SEND"] = "send";
31
+ SocketEvents2["RECONNECTING"] = "reconnecting";
32
+ SocketEvents2["RECONNECT_ATTEMPT"] = "reconnect_attempt";
33
+ SocketEvents2["RECONNECT"] = "reconnect";
34
+ SocketEvents2["RECONNECT_ERROR"] = "reconnect_error";
35
+ SocketEvents2["RECONNECT_FAILED"] = "reconnect_failed";
36
+ SocketEvents2["HEARTBEAT"] = "heartbeat";
37
+ SocketEvents2["HEARTBEAT_RESPONSE"] = "heartbeat_response";
38
+ SocketEvents2["HEARTBEAT_TIMEOUT"] = "heartbeat_timeout";
39
+ return SocketEvents2;
40
+ })(SocketEvents || {});
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ SocketEvents
44
+ });
@@ -0,0 +1,66 @@
1
+ import { HeartbeatOptions, SocketMessage } from "./types";
2
+ /**
3
+ * Socket心跳管理器
4
+ * 处理WebSocket连接的心跳检测
5
+ */
6
+ export declare class HeartbeatManager {
7
+ private options;
8
+ private intervalTimer;
9
+ private timeoutTimer;
10
+ private lastHeartbeatTime;
11
+ private lastHeartbeatResponse;
12
+ private active;
13
+ private sendHeartbeat;
14
+ private onTimeout;
15
+ private onResponse;
16
+ /**
17
+ * 创建心跳管理器
18
+ * @param options 心跳配置选项
19
+ * @param sendHeartbeat 发送心跳的回调函数
20
+ * @param callbacks 回调函数集合
21
+ */
22
+ constructor(options: HeartbeatOptions, sendHeartbeat: (msg: SocketMessage) => void, callbacks?: {
23
+ onTimeout?: () => void;
24
+ onResponse?: () => void;
25
+ });
26
+ /**
27
+ * 启动心跳检测
28
+ */
29
+ start(): void;
30
+ /**
31
+ * 停止心跳检测
32
+ */
33
+ stop(): void;
34
+ /**
35
+ * 重启心跳检测
36
+ */
37
+ restart(): void;
38
+ /**
39
+ * 接收到心跳响应
40
+ */
41
+ receiveHeartbeatResponse(): void;
42
+ /**
43
+ * 获取上次心跳时间
44
+ */
45
+ getLastHeartbeatTime(): number;
46
+ /**
47
+ * 获取上次心跳响应时间
48
+ */
49
+ getLastHeartbeatResponseTime(): number;
50
+ /**
51
+ * 获取心跳是否活跃
52
+ */
53
+ isActive(): boolean;
54
+ /**
55
+ * 安排下一次心跳
56
+ */
57
+ private scheduleHeartbeat;
58
+ /**
59
+ * 发送心跳消息
60
+ */
61
+ private sendHeartbeatMessage;
62
+ /**
63
+ * 清除所有计时器
64
+ */
65
+ private clearTimers;
66
+ }
@@ -0,0 +1,152 @@
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
+ /**
28
+ * 创建心跳管理器
29
+ * @param options 心跳配置选项
30
+ * @param sendHeartbeat 发送心跳的回调函数
31
+ * @param callbacks 回调函数集合
32
+ */
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;
39
+ this.options = {
40
+ ...options,
41
+ interval: Math.max(options.interval, import_constants.MIN_HEARTBEAT_INTERVAL),
42
+ message: options.message || import_constants.DEFAULT_HEARTBEAT_MESSAGE
43
+ };
44
+ this.sendHeartbeat = sendHeartbeat;
45
+ this.onTimeout = callbacks.onTimeout || (() => {
46
+ });
47
+ this.onResponse = callbacks.onResponse || (() => {
48
+ });
49
+ }
50
+ /**
51
+ * 启动心跳检测
52
+ */
53
+ start() {
54
+ if (this.active) {
55
+ return;
56
+ }
57
+ this.active = true;
58
+ this.scheduleHeartbeat();
59
+ }
60
+ /**
61
+ * 停止心跳检测
62
+ */
63
+ stop() {
64
+ this.active = false;
65
+ this.clearTimers();
66
+ }
67
+ /**
68
+ * 重启心跳检测
69
+ */
70
+ restart() {
71
+ this.stop();
72
+ this.start();
73
+ }
74
+ /**
75
+ * 接收到心跳响应
76
+ */
77
+ receiveHeartbeatResponse() {
78
+ this.lastHeartbeatResponse = Date.now();
79
+ if (this.timeoutTimer) {
80
+ clearTimeout(this.timeoutTimer);
81
+ this.timeoutTimer = null;
82
+ }
83
+ this.onResponse();
84
+ }
85
+ /**
86
+ * 获取上次心跳时间
87
+ */
88
+ getLastHeartbeatTime() {
89
+ return this.lastHeartbeatTime;
90
+ }
91
+ /**
92
+ * 获取上次心跳响应时间
93
+ */
94
+ getLastHeartbeatResponseTime() {
95
+ return this.lastHeartbeatResponse;
96
+ }
97
+ /**
98
+ * 获取心跳是否活跃
99
+ */
100
+ isActive() {
101
+ return this.active;
102
+ }
103
+ /**
104
+ * 安排下一次心跳
105
+ */
106
+ scheduleHeartbeat() {
107
+ if (!this.active) {
108
+ return;
109
+ }
110
+ this.clearTimers();
111
+ this.intervalTimer = setInterval(() => {
112
+ this.sendHeartbeatMessage();
113
+ }, this.options.interval);
114
+ this.sendHeartbeatMessage();
115
+ }
116
+ /**
117
+ * 发送心跳消息
118
+ */
119
+ sendHeartbeatMessage() {
120
+ if (!this.active) {
121
+ return;
122
+ }
123
+ this.lastHeartbeatTime = Date.now();
124
+ if (this.timeoutTimer) {
125
+ clearTimeout(this.timeoutTimer);
126
+ this.timeoutTimer = null;
127
+ }
128
+ this.sendHeartbeat(this.options.message);
129
+ this.timeoutTimer = setTimeout(() => {
130
+ if (this.active) {
131
+ this.onTimeout();
132
+ }
133
+ }, this.options.timeout);
134
+ }
135
+ /**
136
+ * 清除所有计时器
137
+ */
138
+ clearTimers() {
139
+ if (this.intervalTimer) {
140
+ clearInterval(this.intervalTimer);
141
+ this.intervalTimer = null;
142
+ }
143
+ if (this.timeoutTimer) {
144
+ clearTimeout(this.timeoutTimer);
145
+ this.timeoutTimer = null;
146
+ }
147
+ }
148
+ };
149
+ // Annotate the CommonJS export names for ESM import in node:
150
+ 0 && (module.exports = {
151
+ HeartbeatManager
152
+ });
@@ -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,200 @@
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
+ constructor() {
50
+ this.sockets = /* @__PURE__ */ new Map();
51
+ }
52
+ /**
53
+ * 创建新的Socket实例
54
+ * @param url WebSocket连接URL
55
+ * @param options Socket配置选项
56
+ * @param key 可选的标识键,用于后续获取该Socket实例
57
+ */
58
+ create(url, options = {}, key) {
59
+ const socket = new import_socket.Socket({ url, ...options });
60
+ if (key) {
61
+ this.sockets.set(key, socket);
62
+ }
63
+ return socket;
64
+ }
65
+ /**
66
+ * 获取Socket实例
67
+ * @param key Socket标识键
68
+ */
69
+ get(key) {
70
+ return this.sockets.get(key);
71
+ }
72
+ /**
73
+ * 移除Socket实例
74
+ * @param key Socket标识键
75
+ */
76
+ remove(key) {
77
+ const socket = this.sockets.get(key);
78
+ if (socket) {
79
+ socket.destroy();
80
+ return this.sockets.delete(key);
81
+ }
82
+ return false;
83
+ }
84
+ /**
85
+ * 关闭并移除所有Socket实例
86
+ */
87
+ closeAll() {
88
+ for (const socket of this.sockets.values()) {
89
+ socket.destroy();
90
+ }
91
+ this.sockets.clear();
92
+ }
93
+ /**
94
+ * 检查指定键的Socket是否存在
95
+ * @param key Socket标识键
96
+ */
97
+ has(key) {
98
+ return this.sockets.has(key);
99
+ }
100
+ /**
101
+ * 获取所有Socket实例的标识键
102
+ */
103
+ getKeys() {
104
+ return Array.from(this.sockets.keys());
105
+ }
106
+ /**
107
+ * 获取所有Socket实例
108
+ */
109
+ getAllSockets() {
110
+ return Array.from(this.sockets.values());
111
+ }
112
+ /**
113
+ * 为指定的Socket启用监控
114
+ * @param key Socket标识键
115
+ * @param options 监控配置选项
116
+ */
117
+ enableMonitoring(key, options) {
118
+ const socket = this.get(key);
119
+ if (socket) {
120
+ return socket.enableMonitoring(options);
121
+ }
122
+ return null;
123
+ }
124
+ /**
125
+ * 获取指定Socket的监控器
126
+ * @param key Socket标识键
127
+ */
128
+ getMonitor(key) {
129
+ const socket = this.get(key);
130
+ if (socket) {
131
+ return socket.getMonitor();
132
+ }
133
+ return null;
134
+ }
135
+ /**
136
+ * 获取所有Socket的监控信息
137
+ */
138
+ getAllMonitors() {
139
+ const result = /* @__PURE__ */ new Map();
140
+ for (const [key, socket] of this.sockets.entries()) {
141
+ result.set(key, socket.getMonitor());
142
+ }
143
+ return result;
144
+ }
145
+ };
146
+ var socketFactory = new SocketFactory();
147
+ var socket_default = {
148
+ /**
149
+ * 创建新的Socket实例
150
+ */
151
+ create: socketFactory.create.bind(socketFactory),
152
+ /**
153
+ * 获取指定键的Socket实例
154
+ */
155
+ get: socketFactory.get.bind(socketFactory),
156
+ /**
157
+ * 移除Socket实例
158
+ */
159
+ remove: socketFactory.remove.bind(socketFactory),
160
+ /**
161
+ * 关闭并移除所有Socket实例
162
+ */
163
+ closeAll: socketFactory.closeAll.bind(socketFactory),
164
+ /**
165
+ * 检查指定键的Socket是否存在
166
+ */
167
+ has: socketFactory.has.bind(socketFactory),
168
+ /**
169
+ * 获取所有Socket标识键
170
+ */
171
+ getKeys: socketFactory.getKeys.bind(socketFactory),
172
+ /**
173
+ * 获取所有Socket实例
174
+ */
175
+ getAllSockets: socketFactory.getAllSockets.bind(socketFactory),
176
+ /**
177
+ * 为指定的Socket启用监控
178
+ */
179
+ enableMonitoring: socketFactory.enableMonitoring.bind(socketFactory),
180
+ /**
181
+ * 获取指定Socket的监控器
182
+ */
183
+ getMonitor: socketFactory.getMonitor.bind(socketFactory),
184
+ /**
185
+ * 获取所有Socket的监控信息
186
+ */
187
+ getAllMonitors: socketFactory.getAllMonitors.bind(socketFactory),
188
+ /**
189
+ * 监控组件
190
+ */
191
+ components
192
+ };
193
+ // Annotate the CommonJS export names for ESM import in node:
194
+ 0 && (module.exports = {
195
+ Socket,
196
+ SocketEvents,
197
+ SocketMonitor,
198
+ SocketStatus,
199
+ createSocket
200
+ });