@tdengine/websocket 3.2.3 → 3.3.0

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 (224) hide show
  1. package/lib/package.json +1 -1
  2. package/lib/src/client/wsClient.d.ts +23 -7
  3. package/lib/src/client/wsClient.d.ts.map +1 -1
  4. package/lib/src/client/wsClient.js +154 -139
  5. package/lib/src/client/wsConnector.d.ts +55 -9
  6. package/lib/src/client/wsConnector.d.ts.map +1 -1
  7. package/lib/src/client/wsConnector.js +519 -100
  8. package/lib/src/client/wsConnectorPool.d.ts +5 -1
  9. package/lib/src/client/wsConnectorPool.d.ts.map +1 -1
  10. package/lib/src/client/wsConnectorPool.js +61 -43
  11. package/lib/src/client/wsEventCallback.d.ts +3 -0
  12. package/lib/src/client/wsEventCallback.d.ts.map +1 -1
  13. package/lib/src/client/wsEventCallback.js +67 -8
  14. package/lib/src/common/addressConnectionTracker.d.ts +11 -0
  15. package/lib/src/common/addressConnectionTracker.d.ts.map +1 -0
  16. package/lib/src/common/addressConnectionTracker.js +53 -0
  17. package/lib/src/common/dsn.d.ts +14 -2
  18. package/lib/src/common/dsn.d.ts.map +1 -1
  19. package/lib/src/common/dsn.js +91 -22
  20. package/lib/src/common/taosResult.d.ts.map +1 -1
  21. package/lib/src/common/taosResult.js +0 -5
  22. package/lib/src/common/urlParser.d.ts +32 -0
  23. package/lib/src/common/urlParser.d.ts.map +1 -0
  24. package/lib/src/common/urlParser.js +201 -0
  25. package/lib/src/common/utils.d.ts +2 -1
  26. package/lib/src/common/utils.d.ts.map +1 -1
  27. package/lib/src/common/utils.js +35 -34
  28. package/lib/src/sql/wsSql.js +2 -2
  29. package/lib/src/stmt/FieldBindParams.d.ts.map +1 -1
  30. package/lib/src/stmt/wsColumnInfo.d.ts.map +1 -1
  31. package/lib/src/stmt/wsParams1.d.ts.map +1 -1
  32. package/lib/src/stmt/wsParams1.js +26 -26
  33. package/lib/src/stmt/wsParams2.d.ts.map +1 -1
  34. package/lib/src/stmt/wsParams2.js +0 -3
  35. package/lib/src/stmt/wsParamsBase.d.ts.map +1 -1
  36. package/lib/src/stmt/wsProto.d.ts.map +1 -1
  37. package/lib/src/stmt/wsProto.js +16 -16
  38. package/lib/src/stmt/wsStmt1.d.ts.map +1 -1
  39. package/lib/src/stmt/wsStmt2.d.ts +12 -4
  40. package/lib/src/stmt/wsStmt2.d.ts.map +1 -1
  41. package/lib/src/stmt/wsStmt2.js +182 -64
  42. package/lib/src/stmt/wsTableInfo.d.ts.map +1 -1
  43. package/lib/src/tmq/config.d.ts +3 -2
  44. package/lib/src/tmq/config.d.ts.map +1 -1
  45. package/lib/src/tmq/config.js +15 -15
  46. package/lib/src/tmq/wsTmq.d.ts +4 -1
  47. package/lib/src/tmq/wsTmq.d.ts.map +1 -1
  48. package/lib/src/tmq/wsTmq.js +50 -27
  49. package/lib/test/bulkPulling/a.test.d.ts +2 -0
  50. package/lib/test/bulkPulling/a.test.d.ts.map +1 -0
  51. package/lib/test/bulkPulling/a.test.js +166 -0
  52. package/lib/test/bulkPulling/dsn.test.js +19 -0
  53. package/lib/test/bulkPulling/retryConfig.test.js +11 -11
  54. package/lib/test/bulkPulling/sql.failover.test.d.ts +2 -0
  55. package/lib/test/bulkPulling/sql.failover.test.d.ts.map +1 -0
  56. package/lib/test/bulkPulling/sql.failover.test.js +338 -0
  57. package/lib/test/bulkPulling/stmt2.failover.test.d.ts +2 -0
  58. package/lib/test/bulkPulling/stmt2.failover.test.d.ts.map +1 -0
  59. package/lib/test/bulkPulling/stmt2.failover.test.js +313 -0
  60. package/lib/test/bulkPulling/stmt2.init.failover.test.d.ts +2 -0
  61. package/lib/test/bulkPulling/stmt2.init.failover.test.d.ts.map +1 -0
  62. package/lib/test/bulkPulling/stmt2.init.failover.test.js +50 -0
  63. package/lib/test/bulkPulling/tmq.failover.test.d.ts +2 -0
  64. package/lib/test/bulkPulling/tmq.failover.test.d.ts.map +1 -0
  65. package/lib/test/bulkPulling/tmq.failover.test.js +404 -0
  66. package/lib/test/bulkPulling/urlParser.test.d.ts +2 -0
  67. package/lib/test/bulkPulling/urlParser.test.d.ts.map +1 -0
  68. package/lib/test/bulkPulling/urlParser.test.js +452 -0
  69. package/lib/test/bulkPulling/wsClient.reconnect.integration.test.js +2 -2
  70. package/lib/test/bulkPulling/wsClient.recovery.test.d.ts +2 -0
  71. package/lib/test/bulkPulling/wsClient.recovery.test.d.ts.map +1 -0
  72. package/lib/test/bulkPulling/wsClient.recovery.test.js +104 -0
  73. package/lib/test/bulkPulling/wsConfig.dsn.test.js +2 -0
  74. package/lib/test/bulkPulling/wsConnector.failover.test.js +396 -27
  75. package/lib/test/bulkPulling/wsConnectorPool.key.test.js +12 -10
  76. package/lib/test/bulkPulling/wsConnectorPool.keyAuth.test.d.ts +2 -0
  77. package/lib/test/bulkPulling/wsConnectorPool.keyAuth.test.d.ts.map +1 -0
  78. package/lib/test/bulkPulling/wsConnectorPool.keyAuth.test.js +28 -0
  79. package/lib/test/bulkPulling/wsProxy.failover.integration.test.d.ts +2 -0
  80. package/lib/test/bulkPulling/wsProxy.failover.integration.test.d.ts.map +1 -0
  81. package/lib/test/bulkPulling/wsProxy.failover.integration.test.js +120 -0
  82. package/lib/test/bulkPulling/wsProxy.failover.test.d.ts +2 -0
  83. package/lib/test/bulkPulling/wsProxy.failover.test.d.ts.map +1 -0
  84. package/lib/test/bulkPulling/wsProxy.failover.test.js +465 -0
  85. package/lib/test/client/wsClient.recovery.test.d.ts +2 -0
  86. package/lib/test/client/wsClient.recovery.test.d.ts.map +1 -0
  87. package/lib/test/client/wsClient.recovery.test.js +122 -0
  88. package/lib/test/client/wsConnectPool.test.d.ts +2 -0
  89. package/lib/test/client/wsConnectPool.test.d.ts.map +1 -0
  90. package/lib/test/client/wsConnectPool.test.js +147 -0
  91. package/lib/test/client/wsConnector.failover.test.d.ts +2 -0
  92. package/lib/test/client/wsConnector.failover.test.d.ts.map +1 -0
  93. package/lib/test/client/wsConnector.failover.test.js +681 -0
  94. package/lib/test/client/wsConnector.leastConnections.test.d.ts +2 -0
  95. package/lib/test/client/wsConnector.leastConnections.test.d.ts.map +1 -0
  96. package/lib/test/client/wsConnector.leastConnections.test.js +71 -0
  97. package/lib/test/client/wsConnectorPool.key.test.d.ts +2 -0
  98. package/lib/test/client/wsConnectorPool.key.test.d.ts.map +1 -0
  99. package/lib/test/client/wsConnectorPool.key.test.js +127 -0
  100. package/lib/test/client/wsEventCallback.test.d.ts +2 -0
  101. package/lib/test/client/wsEventCallback.test.d.ts.map +1 -0
  102. package/lib/test/client/wsEventCallback.test.js +98 -0
  103. package/lib/test/common/addressConnectionTracker.test.d.ts +2 -0
  104. package/lib/test/common/addressConnectionTracker.test.d.ts.map +1 -0
  105. package/lib/test/common/addressConnectionTracker.test.js +74 -0
  106. package/lib/test/common/dsn.test.d.ts +2 -0
  107. package/lib/test/common/dsn.test.d.ts.map +1 -0
  108. package/lib/test/common/dsn.test.js +406 -0
  109. package/lib/test/common/log.test.d.ts +2 -0
  110. package/lib/test/common/log.test.d.ts.map +1 -0
  111. package/lib/test/common/log.test.js +54 -0
  112. package/lib/test/common/utils.test.d.ts +2 -0
  113. package/lib/test/common/utils.test.d.ts.map +1 -0
  114. package/lib/test/common/utils.test.js +13 -0
  115. package/lib/test/common/wsConfig.dsn.test.d.ts +2 -0
  116. package/lib/test/common/wsConfig.dsn.test.d.ts.map +1 -0
  117. package/lib/test/common/wsConfig.dsn.test.js +39 -0
  118. package/lib/test/helpers/utils.d.ts +27 -0
  119. package/lib/test/helpers/utils.d.ts.map +1 -0
  120. package/lib/test/helpers/utils.js +341 -0
  121. package/lib/test/helpers/wsFailoverProxy.d.ts +109 -0
  122. package/lib/test/helpers/wsFailoverProxy.d.ts.map +1 -0
  123. package/lib/test/helpers/wsFailoverProxy.js +420 -0
  124. package/lib/test/helpers/wsProxy.d.ts +110 -0
  125. package/lib/test/helpers/wsProxy.d.ts.map +1 -0
  126. package/lib/test/helpers/wsProxy.js +429 -0
  127. package/lib/test/sql/core/decimal.test.d.ts +2 -0
  128. package/lib/test/sql/core/decimal.test.d.ts.map +1 -0
  129. package/lib/test/sql/core/decimal.test.js +153 -0
  130. package/lib/test/sql/core/queryTables.test.d.ts +2 -0
  131. package/lib/test/sql/core/queryTables.test.d.ts.map +1 -0
  132. package/lib/test/sql/core/queryTables.test.js +506 -0
  133. package/lib/test/sql/core/schemaless.test.d.ts +2 -0
  134. package/lib/test/sql/core/schemaless.test.d.ts.map +1 -0
  135. package/lib/test/sql/core/schemaless.test.js +102 -0
  136. package/lib/test/sql/core/sql.test.d.ts +2 -0
  137. package/lib/test/sql/core/sql.test.d.ts.map +1 -0
  138. package/lib/test/sql/core/sql.test.js +324 -0
  139. package/lib/test/sql/decimal.test.d.ts +2 -0
  140. package/lib/test/sql/decimal.test.d.ts.map +1 -0
  141. package/lib/test/sql/decimal.test.js +153 -0
  142. package/lib/test/sql/failover/sql.failover.test.d.ts +2 -0
  143. package/lib/test/sql/failover/sql.failover.test.d.ts.map +1 -0
  144. package/lib/test/sql/failover/sql.failover.test.js +341 -0
  145. package/lib/test/sql/queryTables.test.d.ts +2 -0
  146. package/lib/test/sql/queryTables.test.d.ts.map +1 -0
  147. package/lib/test/sql/queryTables.test.js +506 -0
  148. package/lib/test/sql/schemaless.test.d.ts +2 -0
  149. package/lib/test/sql/schemaless.test.d.ts.map +1 -0
  150. package/lib/test/sql/schemaless.test.js +102 -0
  151. package/lib/test/sql/sql.failover.test.d.ts +2 -0
  152. package/lib/test/sql/sql.failover.test.d.ts.map +1 -0
  153. package/lib/test/sql/sql.failover.test.js +341 -0
  154. package/lib/test/sql/sql.test.d.ts +2 -0
  155. package/lib/test/sql/sql.test.d.ts.map +1 -0
  156. package/lib/test/sql/sql.test.js +324 -0
  157. package/lib/test/stmt/failover/stmt2.failover.mock.test.d.ts +2 -0
  158. package/lib/test/stmt/failover/stmt2.failover.mock.test.d.ts.map +1 -0
  159. package/lib/test/stmt/failover/stmt2.failover.mock.test.js +341 -0
  160. package/lib/test/stmt/failover/stmt2.failover.test.d.ts +2 -0
  161. package/lib/test/stmt/failover/stmt2.failover.test.d.ts.map +1 -0
  162. package/lib/test/stmt/failover/stmt2.failover.test.js +384 -0
  163. package/lib/test/stmt/stmt1.func.test.d.ts +2 -0
  164. package/lib/test/stmt/stmt1.func.test.d.ts.map +1 -0
  165. package/lib/test/stmt/stmt1.func.test.js +418 -0
  166. package/lib/test/stmt/stmt1.type.test.d.ts +2 -0
  167. package/lib/test/stmt/stmt1.type.test.d.ts.map +1 -0
  168. package/lib/test/stmt/stmt1.type.test.js +399 -0
  169. package/lib/test/stmt/stmt2.failover.mock.test.d.ts +2 -0
  170. package/lib/test/stmt/stmt2.failover.mock.test.d.ts.map +1 -0
  171. package/lib/test/stmt/stmt2.failover.mock.test.js +341 -0
  172. package/lib/test/stmt/stmt2.failover.test.d.ts +2 -0
  173. package/lib/test/stmt/stmt2.failover.test.d.ts.map +1 -0
  174. package/lib/test/stmt/stmt2.failover.test.js +384 -0
  175. package/lib/test/stmt/stmt2.func.test.d.ts +2 -0
  176. package/lib/test/stmt/stmt2.func.test.d.ts.map +1 -0
  177. package/lib/test/stmt/stmt2.func.test.js +537 -0
  178. package/lib/test/stmt/stmt2.type.test.d.ts +2 -0
  179. package/lib/test/stmt/stmt2.type.test.d.ts.map +1 -0
  180. package/lib/test/stmt/stmt2.type.test.js +401 -0
  181. package/lib/test/stmt/v1/stmt1.func.test.d.ts +2 -0
  182. package/lib/test/stmt/v1/stmt1.func.test.d.ts.map +1 -0
  183. package/lib/test/stmt/v1/stmt1.func.test.js +418 -0
  184. package/lib/test/stmt/v1/stmt1.type.test.d.ts +2 -0
  185. package/lib/test/stmt/v1/stmt1.type.test.d.ts.map +1 -0
  186. package/lib/test/stmt/v1/stmt1.type.test.js +399 -0
  187. package/lib/test/stmt/v2/stmt2.func.test.d.ts +2 -0
  188. package/lib/test/stmt/v2/stmt2.func.test.d.ts.map +1 -0
  189. package/lib/test/stmt/v2/stmt2.func.test.js +537 -0
  190. package/lib/test/stmt/v2/stmt2.type.test.d.ts +2 -0
  191. package/lib/test/stmt/v2/stmt2.type.test.d.ts.map +1 -0
  192. package/lib/test/stmt/v2/stmt2.type.test.js +401 -0
  193. package/lib/test/tmq/cloud/cloud.tmq.test.d.ts +2 -0
  194. package/lib/test/tmq/cloud/cloud.tmq.test.d.ts.map +1 -0
  195. package/lib/test/tmq/cloud/cloud.tmq.test.js +84 -0
  196. package/lib/test/tmq/cloud/tmq.cloud.test.d.ts +2 -0
  197. package/lib/test/tmq/cloud/tmq.cloud.test.d.ts.map +1 -0
  198. package/lib/test/tmq/cloud/tmq.cloud.test.js +82 -0
  199. package/lib/test/tmq/core/tmq.config.test.d.ts +2 -0
  200. package/lib/test/tmq/core/tmq.config.test.d.ts.map +1 -0
  201. package/lib/test/tmq/core/tmq.config.test.js +83 -0
  202. package/lib/test/tmq/core/tmq.test.d.ts +2 -0
  203. package/lib/test/tmq/core/tmq.test.d.ts.map +1 -0
  204. package/lib/test/tmq/core/tmq.test.js +513 -0
  205. package/lib/test/tmq/failover/tmq.failover.test.d.ts +2 -0
  206. package/lib/test/tmq/failover/tmq.failover.test.d.ts.map +1 -0
  207. package/lib/test/tmq/failover/tmq.failover.test.js +404 -0
  208. package/lib/test/tmq/tmq.cloud.test.d.ts +2 -0
  209. package/lib/test/tmq/tmq.cloud.test.d.ts.map +1 -0
  210. package/lib/test/tmq/tmq.cloud.test.js +82 -0
  211. package/lib/test/tmq/tmq.config.test.d.ts +2 -0
  212. package/lib/test/tmq/tmq.config.test.d.ts.map +1 -0
  213. package/lib/test/tmq/tmq.config.test.js +94 -0
  214. package/lib/test/tmq/tmq.failover.test.d.ts +2 -0
  215. package/lib/test/tmq/tmq.failover.test.d.ts.map +1 -0
  216. package/lib/test/tmq/tmq.failover.test.js +404 -0
  217. package/lib/test/tmq/tmq.test.d.ts +2 -0
  218. package/lib/test/tmq/tmq.test.d.ts.map +1 -0
  219. package/lib/test/tmq/tmq.test.js +513 -0
  220. package/lib/test/unit/connectionManager.test.d.ts +2 -0
  221. package/lib/test/unit/connectionManager.test.d.ts.map +1 -0
  222. package/lib/test/unit/connectionManager.test.js +91 -0
  223. package/package.json +1 -1
  224. package/readme.md +2 -2
@@ -0,0 +1,452 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const urlParser_1 = require("../../src/common/urlParser");
4
+ describe("urlParser", () => {
5
+ describe("parseMultiHostUrl", () => {
6
+ test("single host with port", () => {
7
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@localhost:6041");
8
+ expect(result.scheme).toBe("ws");
9
+ expect(result.username).toBe("root");
10
+ expect(result.password).toBe("taosdata");
11
+ expect(result.hosts).toEqual([{ host: "localhost", port: 6041 }]);
12
+ expect(result.database).toBe("");
13
+ expect(result.params.size).toBe(0);
14
+ });
15
+ test("single host with database", () => {
16
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@localhost:6041/power");
17
+ expect(result.scheme).toBe("ws");
18
+ expect(result.username).toBe("root");
19
+ expect(result.password).toBe("taosdata");
20
+ expect(result.hosts).toEqual([{ host: "localhost", port: 6041 }]);
21
+ expect(result.database).toBe("power");
22
+ expect(result.params.size).toBe(0);
23
+ });
24
+ test("multiple hosts", () => {
25
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@host1:6041,host2:6042,host3:6043/mydb");
26
+ expect(result.scheme).toBe("ws");
27
+ expect(result.username).toBe("root");
28
+ expect(result.password).toBe("taosdata");
29
+ expect(result.hosts).toHaveLength(3);
30
+ expect(result.hosts[0]).toEqual({ host: "host1", port: 6041 });
31
+ expect(result.hosts[1]).toEqual({ host: "host2", port: 6042 });
32
+ expect(result.hosts[2]).toEqual({ host: "host3", port: 6043 });
33
+ expect(result.database).toBe("mydb");
34
+ expect(result.params.size).toBe(0);
35
+ });
36
+ test("IPv6 address in brackets", () => {
37
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@[::1]:6041,host2:6042/db");
38
+ expect(result.scheme).toBe("ws");
39
+ expect(result.username).toBe("root");
40
+ expect(result.password).toBe("taosdata");
41
+ expect(result.hosts).toHaveLength(2);
42
+ expect(result.hosts[0]).toEqual({ host: "[::1]", port: 6041 });
43
+ expect(result.hosts[1]).toEqual({ host: "host2", port: 6042 });
44
+ expect(result.database).toBe("db");
45
+ expect(result.params.size).toBe(0);
46
+ });
47
+ test("multiple IPv6 addresses", () => {
48
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@[::1]:6041,[fe80::1]:6042");
49
+ expect(result.scheme).toBe("ws");
50
+ expect(result.username).toBe("root");
51
+ expect(result.password).toBe("taosdata");
52
+ expect(result.hosts).toHaveLength(2);
53
+ expect(result.hosts[0]).toEqual({ host: "[::1]", port: 6041 });
54
+ expect(result.hosts[1]).toEqual({ host: "[fe80::1]", port: 6042 });
55
+ expect(result.database).toBe("");
56
+ expect(result.params.size).toBe(0);
57
+ });
58
+ test("wss scheme", () => {
59
+ const result = (0, urlParser_1.parseMultiHostUrl)("wss://root:taosdata@localhost:6041");
60
+ expect(result.scheme).toBe("wss");
61
+ expect(result.username).toBe("root");
62
+ expect(result.password).toBe("taosdata");
63
+ expect(result.hosts).toEqual([{ host: "localhost", port: 6041 }]);
64
+ expect(result.database).toBe("");
65
+ expect(result.params.size).toBe(0);
66
+ });
67
+ test("query parameters", () => {
68
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@host1:6041/db?retries=5&retry_backoff_ms=300&timezone=UTC");
69
+ expect(result.scheme).toBe("ws");
70
+ expect(result.username).toBe("root");
71
+ expect(result.password).toBe("taosdata");
72
+ expect(result.hosts).toEqual([{ host: "host1", port: 6041 }]);
73
+ expect(result.database).toBe("db");
74
+ expect(result.params.get("retries")).toBe("5");
75
+ expect(result.params.get("retry_backoff_ms")).toBe("300");
76
+ expect(result.params.get("timezone")).toBe("UTC");
77
+ });
78
+ test("deduplicates hosts", () => {
79
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@host1:6041,host2:6042,host1:6041");
80
+ expect(result.scheme).toBe("ws");
81
+ expect(result.username).toBe("root");
82
+ expect(result.password).toBe("taosdata");
83
+ expect(result.hosts).toHaveLength(2);
84
+ expect(result.hosts[0]).toEqual({ host: "host1", port: 6041 });
85
+ expect(result.hosts[1]).toEqual({ host: "host2", port: 6042 });
86
+ expect(result.database).toBe("");
87
+ expect(result.params.size).toBe(0);
88
+ });
89
+ test("no user info", () => {
90
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://host1:6041?token=mytoken");
91
+ expect(result.scheme).toBe("ws");
92
+ expect(result.username).toBe("");
93
+ expect(result.password).toBe("");
94
+ expect(result.hosts).toEqual([{ host: "host1", port: 6041 }]);
95
+ expect(result.database).toBe("");
96
+ expect(result.params.get("token")).toBe("mytoken");
97
+ });
98
+ test("username only (no password)", () => {
99
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root@host1:6041");
100
+ expect(result.scheme).toBe("ws");
101
+ expect(result.username).toBe("root");
102
+ expect(result.password).toBe("");
103
+ expect(result.hosts).toEqual([{ host: "host1", port: 6041 }]);
104
+ expect(result.database).toBe("");
105
+ expect(result.params.size).toBe(0);
106
+ });
107
+ test("host without port uses default 6041", () => {
108
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@myhost");
109
+ expect(result.scheme).toBe("ws");
110
+ expect(result.username).toBe("root");
111
+ expect(result.password).toBe("taosdata");
112
+ expect(result.hosts).toEqual([{ host: "myhost", port: 6041 }]);
113
+ expect(result.database).toBe("");
114
+ expect(result.params.size).toBe(0);
115
+ });
116
+ test("complex URL with all features", () => {
117
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://user:p%40ss@host1:6041,host2:6042,[::1]:6043/testdb?retries=5&retry_backoff_ms=100&retry_backoff_max_ms=5000&resend_write=true&token=abc");
118
+ expect(result.scheme).toBe("ws");
119
+ expect(result.username).toBe("user");
120
+ expect(result.password).toBe("p%40ss");
121
+ expect(result.hosts).toHaveLength(3);
122
+ expect(result.hosts[0]).toEqual({ host: "host1", port: 6041 });
123
+ expect(result.hosts[1]).toEqual({ host: "host2", port: 6042 });
124
+ expect(result.hosts[2]).toEqual({ host: "[::1]", port: 6043 });
125
+ expect(result.database).toBe("testdb");
126
+ expect(result.params.get("retries")).toBe("5");
127
+ expect(result.params.get("retry_backoff_ms")).toBe("100");
128
+ expect(result.params.get("retry_backoff_max_ms")).toBe("5000");
129
+ expect(result.params.get("resend_write")).toBe("true");
130
+ expect(result.params.get("token")).toBe("abc");
131
+ });
132
+ // Additional normal test cases
133
+ test("empty password with colon", () => {
134
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:@localhost:6041");
135
+ expect(result.scheme).toBe("ws");
136
+ expect(result.username).toBe("root");
137
+ expect(result.password).toBe("");
138
+ expect(result.hosts).toEqual([{ host: "localhost", port: 6041 }]);
139
+ expect(result.database).toBe("");
140
+ expect(result.params.size).toBe(0);
141
+ });
142
+ test("database with special characters", () => {
143
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@localhost:6041/test_db-123");
144
+ expect(result.scheme).toBe("ws");
145
+ expect(result.username).toBe("root");
146
+ expect(result.password).toBe("taosdata");
147
+ expect(result.hosts).toEqual([{ host: "localhost", port: 6041 }]);
148
+ expect(result.database).toBe("test_db-123");
149
+ expect(result.params.size).toBe(0);
150
+ });
151
+ test("empty database path with slash", () => {
152
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@localhost:6041/");
153
+ expect(result.scheme).toBe("ws");
154
+ expect(result.username).toBe("root");
155
+ expect(result.password).toBe("taosdata");
156
+ expect(result.hosts).toEqual([{ host: "localhost", port: 6041 }]);
157
+ expect(result.database).toBe("");
158
+ expect(result.params.size).toBe(0);
159
+ });
160
+ test("multiple hosts without ports use default", () => {
161
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@host1,host2,host3");
162
+ expect(result.scheme).toBe("ws");
163
+ expect(result.username).toBe("root");
164
+ expect(result.password).toBe("taosdata");
165
+ expect(result.hosts).toHaveLength(3);
166
+ expect(result.hosts[0]).toEqual({ host: "host1", port: 6041 });
167
+ expect(result.hosts[1]).toEqual({ host: "host2", port: 6041 });
168
+ expect(result.hosts[2]).toEqual({ host: "host3", port: 6041 });
169
+ expect(result.database).toBe("");
170
+ expect(result.params.size).toBe(0);
171
+ });
172
+ test("IPv6 without port uses default", () => {
173
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@[::1]");
174
+ expect(result.scheme).toBe("ws");
175
+ expect(result.username).toBe("root");
176
+ expect(result.password).toBe("taosdata");
177
+ expect(result.hosts).toEqual([{ host: "[::1]", port: 6041 }]);
178
+ expect(result.database).toBe("");
179
+ expect(result.params.size).toBe(0);
180
+ });
181
+ test("scheme is case insensitive", () => {
182
+ const result = (0, urlParser_1.parseMultiHostUrl)("WS://root:taosdata@localhost:6041");
183
+ expect(result.scheme).toBe("ws");
184
+ expect(result.username).toBe("root");
185
+ expect(result.password).toBe("taosdata");
186
+ expect(result.hosts).toEqual([{ host: "localhost", port: 6041 }]);
187
+ expect(result.database).toBe("");
188
+ expect(result.params.size).toBe(0);
189
+ });
190
+ test("WSS scheme is case insensitive", () => {
191
+ const result = (0, urlParser_1.parseMultiHostUrl)("WSS://root:taosdata@localhost:6041");
192
+ expect(result.scheme).toBe("wss");
193
+ expect(result.username).toBe("root");
194
+ expect(result.password).toBe("taosdata");
195
+ expect(result.hosts).toEqual([{ host: "localhost", port: 6041 }]);
196
+ expect(result.database).toBe("");
197
+ expect(result.params.size).toBe(0);
198
+ });
199
+ test("single query parameter", () => {
200
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@localhost:6041?token=abc123");
201
+ expect(result.scheme).toBe("ws");
202
+ expect(result.username).toBe("root");
203
+ expect(result.password).toBe("taosdata");
204
+ expect(result.hosts).toEqual([{ host: "localhost", port: 6041 }]);
205
+ expect(result.database).toBe("");
206
+ expect(result.params.size).toBe(1);
207
+ expect(result.params.get("token")).toBe("abc123");
208
+ });
209
+ test("database with query parameters", () => {
210
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@localhost:6041/mydb?timezone=UTC");
211
+ expect(result.scheme).toBe("ws");
212
+ expect(result.username).toBe("root");
213
+ expect(result.password).toBe("taosdata");
214
+ expect(result.hosts).toEqual([{ host: "localhost", port: 6041 }]);
215
+ expect(result.database).toBe("mydb");
216
+ expect(result.params.get("timezone")).toBe("UTC");
217
+ });
218
+ test("full IPv6 address (not abbreviated)", () => {
219
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:6041");
220
+ expect(result.scheme).toBe("ws");
221
+ expect(result.username).toBe("root");
222
+ expect(result.password).toBe("taosdata");
223
+ expect(result.hosts).toEqual([{ host: "[2001:0db8:85a3:0000:0000:8a2e:0370:7334]", port: 6041 }]);
224
+ expect(result.database).toBe("");
225
+ expect(result.params.size).toBe(0);
226
+ });
227
+ test("full IPv6 address without port uses default", () => {
228
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:");
229
+ expect(result.scheme).toBe("ws");
230
+ expect(result.username).toBe("root");
231
+ expect(result.password).toBe("taosdata");
232
+ expect(result.hosts).toEqual([{ host: "[2001:0db8:85a3:0000:0000:8a2e:0370:7334]", port: 6041 }]);
233
+ expect(result.database).toBe("");
234
+ expect(result.params.size).toBe(0);
235
+ });
236
+ test("no username only password", () => {
237
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://:pass@localhost:6041");
238
+ expect(result.scheme).toBe("ws");
239
+ expect(result.username).toBe("");
240
+ expect(result.password).toBe("pass");
241
+ expect(result.hosts).toEqual([{ host: "localhost", port: 6041 }]);
242
+ expect(result.database).toBe("");
243
+ expect(result.params.size).toBe(0);
244
+ });
245
+ test("no username only password with database", () => {
246
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://:taosdata@localhost:6041/mydb");
247
+ expect(result.scheme).toBe("ws");
248
+ expect(result.username).toBe("");
249
+ expect(result.password).toBe("taosdata");
250
+ expect(result.hosts).toEqual([{ host: "localhost", port: 6041 }]);
251
+ expect(result.database).toBe("mydb");
252
+ expect(result.params.size).toBe(0);
253
+ });
254
+ test("empty port uses default 6041", () => {
255
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@host1:");
256
+ expect(result.scheme).toBe("ws");
257
+ expect(result.username).toBe("root");
258
+ expect(result.password).toBe("taosdata");
259
+ expect(result.hosts).toEqual([{ host: "host1", port: 6041 }]);
260
+ expect(result.database).toBe("");
261
+ expect(result.params.size).toBe(0);
262
+ });
263
+ test("IPv4 with empty port uses default 6041", () => {
264
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@127.0.1.0:");
265
+ expect(result.scheme).toBe("ws");
266
+ expect(result.username).toBe("root");
267
+ expect(result.password).toBe("taosdata");
268
+ expect(result.hosts).toEqual([{ host: "127.0.1.0", port: 6041 }]);
269
+ expect(result.database).toBe("");
270
+ expect(result.params.size).toBe(0);
271
+ });
272
+ test("multiple hosts with empty ports use default", () => {
273
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@host1:,host2:,127.0.0.1:");
274
+ expect(result.scheme).toBe("ws");
275
+ expect(result.username).toBe("root");
276
+ expect(result.password).toBe("taosdata");
277
+ expect(result.hosts).toHaveLength(3);
278
+ expect(result.hosts[0]).toEqual({ host: "host1", port: 6041 });
279
+ expect(result.hosts[1]).toEqual({ host: "host2", port: 6041 });
280
+ expect(result.hosts[2]).toEqual({ host: "127.0.0.1", port: 6041 });
281
+ expect(result.database).toBe("");
282
+ expect(result.params.size).toBe(0);
283
+ });
284
+ // Boundary test cases
285
+ test("port boundary - minimum valid port 1", () => {
286
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@localhost:1");
287
+ expect(result.scheme).toBe("ws");
288
+ expect(result.username).toBe("root");
289
+ expect(result.password).toBe("taosdata");
290
+ expect(result.hosts).toEqual([{ host: "localhost", port: 1 }]);
291
+ expect(result.database).toBe("");
292
+ expect(result.params.size).toBe(0);
293
+ });
294
+ test("port boundary - maximum valid port 65535", () => {
295
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@localhost:65535");
296
+ expect(result.scheme).toBe("ws");
297
+ expect(result.username).toBe("root");
298
+ expect(result.password).toBe("taosdata");
299
+ expect(result.hosts).toEqual([{ host: "localhost", port: 65535 }]);
300
+ expect(result.database).toBe("");
301
+ expect(result.params.size).toBe(0);
302
+ });
303
+ test("very long username", () => {
304
+ const longUsername = "a".repeat(100);
305
+ const result = (0, urlParser_1.parseMultiHostUrl)(`ws://${longUsername}:pass@localhost:6041`);
306
+ expect(result.scheme).toBe("ws");
307
+ expect(result.username).toBe(longUsername);
308
+ expect(result.password).toBe("pass");
309
+ expect(result.hosts).toEqual([{ host: "localhost", port: 6041 }]);
310
+ expect(result.database).toBe("");
311
+ expect(result.params.size).toBe(0);
312
+ });
313
+ test("very long password", () => {
314
+ const longPassword = "p".repeat(100);
315
+ const result = (0, urlParser_1.parseMultiHostUrl)(`ws://user:${longPassword}@localhost:6041`);
316
+ expect(result.scheme).toBe("ws");
317
+ expect(result.username).toBe("user");
318
+ expect(result.password).toBe(longPassword);
319
+ expect(result.hosts).toEqual([{ host: "localhost", port: 6041 }]);
320
+ expect(result.database).toBe("");
321
+ expect(result.params.size).toBe(0);
322
+ });
323
+ test("many hosts", () => {
324
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@h1:6041,h2:6042,h3:6043,h4:6044,h5:6045,h6:6046,h7:6047,h8:6048");
325
+ expect(result.scheme).toBe("ws");
326
+ expect(result.username).toBe("root");
327
+ expect(result.password).toBe("taosdata");
328
+ expect(result.hosts).toHaveLength(8);
329
+ expect(result.database).toBe("");
330
+ expect(result.params.size).toBe(0);
331
+ });
332
+ test("many query parameters", () => {
333
+ const result = (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@localhost:6041?p1=v1&p2=v2&p3=v3&p4=v4&p5=v5");
334
+ expect(result.scheme).toBe("ws");
335
+ expect(result.username).toBe("root");
336
+ expect(result.password).toBe("taosdata");
337
+ expect(result.hosts).toEqual([{ host: "localhost", port: 6041 }]);
338
+ expect(result.database).toBe("");
339
+ expect(result.params.size).toBe(5);
340
+ expect(result.params.get("p1")).toBe("v1");
341
+ expect(result.params.get("p5")).toBe("v5");
342
+ });
343
+ // Exception test cases
344
+ test("empty URL throws", () => {
345
+ expect(() => (0, urlParser_1.parseMultiHostUrl)("")).toThrow("URL must not be empty");
346
+ });
347
+ test("whitespace only URL throws", () => {
348
+ expect(() => (0, urlParser_1.parseMultiHostUrl)(" ")).toThrow("URL must not be empty");
349
+ });
350
+ test("invalid scheme throws", () => {
351
+ expect(() => (0, urlParser_1.parseMultiHostUrl)("http://host:6041")).toThrow("Invalid URL scheme");
352
+ });
353
+ test("missing scheme throws", () => {
354
+ expect(() => (0, urlParser_1.parseMultiHostUrl)("root:taosdata@host:6041")).toThrow("Invalid URL scheme");
355
+ });
356
+ test("unclosed IPv6 bracket throws", () => {
357
+ expect(() => (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@[::1:6041")).toThrow("Unclosed bracket");
358
+ });
359
+ test("invalid port throws", () => {
360
+ expect(() => (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@host1:abc")).toThrow("Invalid port");
361
+ });
362
+ test("port out of range throws", () => {
363
+ expect(() => (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@host1:70000")).toThrow("Invalid port");
364
+ });
365
+ test("port zero throws", () => {
366
+ expect(() => (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@host1:0")).toThrow("Invalid port");
367
+ });
368
+ test("negative port throws", () => {
369
+ expect(() => (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@host1:-1")).toThrow("Invalid port");
370
+ });
371
+ test("port with spaces throws", () => {
372
+ expect(() => (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@host1:60 41")).toThrow("Invalid port");
373
+ });
374
+ test("IPv6 with unclosed bracket in middle of host list throws", () => {
375
+ expect(() => (0, urlParser_1.parseMultiHostUrl)("ws://root:taosdata@host1:6041,[::1:6042,host2:6043")).toThrow("Unclosed bracket");
376
+ });
377
+ });
378
+ describe("buildHostUrl", () => {
379
+ test("builds single host URL with /ws path", () => {
380
+ const parsed = {
381
+ hosts: [{ host: "host1", port: 6041 }],
382
+ scheme: "ws",
383
+ username: "root",
384
+ password: "taosdata",
385
+ database: "mydb",
386
+ params: new Map([["timezone", "UTC"]]),
387
+ };
388
+ const url = (0, urlParser_1.buildHostUrl)(parsed, parsed.hosts[0]);
389
+ expect(url.origin).toBe("ws://host1:6041");
390
+ expect(url.pathname).toBe("/ws");
391
+ expect(url.username).toBe("root");
392
+ expect(url.password).toBe("taosdata");
393
+ expect(url.searchParams.get("timezone")).toBe("UTC");
394
+ });
395
+ test("excludes retry params from URL", () => {
396
+ const parsed = {
397
+ hosts: [{ host: "host1", port: 6041 }],
398
+ scheme: "ws",
399
+ username: "root",
400
+ password: "taosdata",
401
+ database: "",
402
+ params: new Map([
403
+ ["retries", "5"],
404
+ ["retry_backoff_ms", "200"],
405
+ ["timezone", "UTC"],
406
+ ]),
407
+ };
408
+ const url = (0, urlParser_1.buildHostUrl)(parsed, parsed.hosts[0]);
409
+ expect(url.searchParams.has("retries")).toBe(false);
410
+ expect(url.searchParams.has("retry_backoff_ms")).toBe(false);
411
+ expect(url.searchParams.get("timezone")).toBe("UTC");
412
+ });
413
+ test("adds extra params", () => {
414
+ const parsed = {
415
+ hosts: [{ host: "host1", port: 6041 }],
416
+ scheme: "wss",
417
+ username: "",
418
+ password: "",
419
+ database: "",
420
+ params: new Map(),
421
+ };
422
+ const extras = new Map([["token", "abc123"]]);
423
+ const url = (0, urlParser_1.buildHostUrl)(parsed, parsed.hosts[0], extras);
424
+ expect(url.searchParams.get("token")).toBe("abc123");
425
+ expect(url.protocol).toBe("wss:");
426
+ });
427
+ });
428
+ describe("extractRetryOptions", () => {
429
+ test("extracts all retry params", () => {
430
+ const params = new Map([
431
+ ["retries", "5"],
432
+ ["retry_backoff_ms", "300"],
433
+ ["retry_backoff_max_ms", "5000"],
434
+ ["resend_write", "true"],
435
+ ]);
436
+ const opts = (0, urlParser_1.extractRetryOptions)(params);
437
+ expect(opts.retries).toBe(5);
438
+ expect(opts.retryBackoffMs).toBe(300);
439
+ expect(opts.retryBackoffMaxMs).toBe(5000);
440
+ expect(opts.resendWrite).toBe(true);
441
+ });
442
+ test("returns empty object for no params", () => {
443
+ const opts = (0, urlParser_1.extractRetryOptions)(new Map());
444
+ expect(opts.retries).toBeUndefined();
445
+ expect(opts.retryBackoffMs).toBeUndefined();
446
+ });
447
+ test("resend_write false values", () => {
448
+ expect((0, urlParser_1.extractRetryOptions)(new Map([["resend_write", "false"]])).resendWrite).toBe(false);
449
+ expect((0, urlParser_1.extractRetryOptions)(new Map([["resend_write", "0"]])).resendWrite).toBe(false);
450
+ });
451
+ });
452
+ });
@@ -118,7 +118,7 @@ describe("WsClient reconnect integration", () => {
118
118
  { disconnectOnActions: ["insert"] },
119
119
  {},
120
120
  ]);
121
- const dsn = (0, dsn_1.parse)("ws://root:taosdata@host1:6041,host2:6042/mydb?timezone=UTC&retries=0&retry_backoff_ms=1");
121
+ const dsn = (0, dsn_1.parse)("ws://root:taosdata@host1:6041,host2:6042/mydb?timezone=UTC&retries=1&retry_backoff_ms=1");
122
122
  const client = new wsClient_1.WsClient(dsn, 1000);
123
123
  await client.connect("mydb");
124
124
  await client.setOptionConnection(constant_1.TSDB_OPTION_CONNECTION.TSDB_OPTION_CONNECTION_TIMEZONE, "UTC");
@@ -148,7 +148,7 @@ describe("WsClient reconnect integration", () => {
148
148
  },
149
149
  {},
150
150
  ]);
151
- const dsn = (0, dsn_1.parse)("ws://root:taosdata@host1:6041,host2:6042/mydb?retries=0&retry_backoff_ms=1");
151
+ const dsn = (0, dsn_1.parse)("ws://root:taosdata@host1:6041,host2:6042/mydb?retries=1&retry_backoff_ms=1");
152
152
  const client = new wsClient_1.WsClient(dsn, 1000);
153
153
  await client.connect("mydb");
154
154
  const pending = client.exec(JSON.stringify({
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=wsClient.recovery.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wsClient.recovery.test.d.ts","sourceRoot":"","sources":["../../../test/bulkPulling/wsClient.recovery.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const websocket_1 = require("websocket");
4
+ const wsClient_1 = require("../../src/client/wsClient");
5
+ const wsConnectorPool_1 = require("../../src/client/wsConnectorPool");
6
+ const dsn_1 = require("../../src/common/dsn");
7
+ const wsError_1 = require("../../src/common/wsError");
8
+ function createMockConnector() {
9
+ return {
10
+ readyState: jest.fn(() => websocket_1.w3cwebsocket.OPEN),
11
+ ready: jest.fn(async () => { }),
12
+ setSessionRecoveryHook: jest.fn(),
13
+ sendMsgDirect: jest.fn(async (_message) => ({
14
+ msg: { code: 0, message: "" }
15
+ })),
16
+ sendMsg: jest.fn(async () => ({ msg: { code: 0, message: "" } })),
17
+ sendMsgNoResp: jest.fn(async () => { }),
18
+ };
19
+ }
20
+ describe("WsClient recovery hook", () => {
21
+ afterEach(() => {
22
+ jest.restoreAllMocks();
23
+ });
24
+ test("uses dsn endpoint when creating connection", async () => {
25
+ const dsn = (0, dsn_1.parse)("ws://root:taosdata@localhost:6041");
26
+ dsn.endpoint = dsn_1.WS_TMQ_ENDPOINT;
27
+ const connector = createMockConnector();
28
+ const getConnectionSpy = jest
29
+ .spyOn(wsConnectorPool_1.WebSocketConnectionPool.instance(), "getConnection")
30
+ .mockResolvedValue(connector);
31
+ const client = new wsClient_1.WsClient(dsn, 4321);
32
+ await client.ready();
33
+ expect(getConnectionSpy).toHaveBeenCalledWith(dsn, 4321);
34
+ });
35
+ test("runs custom recovery hook without sql conn recovery on tmq path", async () => {
36
+ const dsn = (0, dsn_1.parse)("ws://root:taosdata@localhost:6041");
37
+ dsn.endpoint = dsn_1.WS_TMQ_ENDPOINT;
38
+ const connector = createMockConnector();
39
+ jest
40
+ .spyOn(wsConnectorPool_1.WebSocketConnectionPool.instance(), "getConnection")
41
+ .mockResolvedValue(connector);
42
+ const customRecoveryHook = jest.fn(async () => { });
43
+ const client = new wsClient_1.WsClient(dsn, 5000);
44
+ client.setSessionRecoveryHook(customRecoveryHook);
45
+ await client.ready();
46
+ const hookCalls = connector.setSessionRecoveryHook.mock.calls;
47
+ const hook = hookCalls[hookCalls.length - 1]?.[0];
48
+ expect(hook).toBeTruthy();
49
+ await hook();
50
+ expect(connector.sendMsgDirect).not.toHaveBeenCalled();
51
+ expect(customRecoveryHook).toHaveBeenCalledTimes(1);
52
+ });
53
+ test("keeps sql conn recovery and then runs custom recovery on sql endpoint", async () => {
54
+ const dsn = (0, dsn_1.parse)("ws://root:taosdata@localhost:6041");
55
+ const connector = createMockConnector();
56
+ const callOrder = [];
57
+ connector.sendMsgDirect.mockImplementation(async (message) => {
58
+ const action = JSON.parse(message).action;
59
+ callOrder.push(action);
60
+ return { msg: { code: 0, message: "" } };
61
+ });
62
+ jest
63
+ .spyOn(wsConnectorPool_1.WebSocketConnectionPool.instance(), "getConnection")
64
+ .mockResolvedValue(connector);
65
+ const client = new wsClient_1.WsClient(dsn, 5000);
66
+ client._connectedDatabase = "db_recovery";
67
+ client.setSessionRecoveryHook(async () => {
68
+ callOrder.push("custom");
69
+ });
70
+ await client.ready();
71
+ const hookCalls = connector.setSessionRecoveryHook.mock.calls;
72
+ const hook = hookCalls[hookCalls.length - 1]?.[0];
73
+ expect(hook).toBeTruthy();
74
+ await hook();
75
+ expect(connector.sendMsgDirect).toHaveBeenCalledTimes(1);
76
+ const firstCall = connector.sendMsgDirect.mock.calls[0];
77
+ const connMsg = JSON.parse(firstCall[0]);
78
+ expect(connMsg.action).toBe("conn");
79
+ expect(connMsg.args.db).toBe("db_recovery");
80
+ expect(callOrder).toEqual(["conn", "custom"]);
81
+ });
82
+ test("throws WebSocketQueryError when sql recovery direct call fails", async () => {
83
+ const dsn = (0, dsn_1.parse)("ws://root:taosdata@localhost:6041");
84
+ const connector = createMockConnector();
85
+ connector.sendMsgDirect.mockResolvedValue({
86
+ msg: {
87
+ code: 9001,
88
+ message: "conn failed",
89
+ },
90
+ });
91
+ jest
92
+ .spyOn(wsConnectorPool_1.WebSocketConnectionPool.instance(), "getConnection")
93
+ .mockResolvedValue(connector);
94
+ const customRecoveryHook = jest.fn(async () => { });
95
+ const client = new wsClient_1.WsClient(dsn, 5000);
96
+ client.setSessionRecoveryHook(customRecoveryHook);
97
+ await client.ready();
98
+ const hookCalls = connector.setSessionRecoveryHook.mock.calls;
99
+ const hook = hookCalls[hookCalls.length - 1]?.[0];
100
+ expect(hook).toBeTruthy();
101
+ await expect(hook()).rejects.toBeInstanceOf(wsError_1.WebSocketQueryError);
102
+ expect(customRecoveryHook).not.toHaveBeenCalled();
103
+ });
104
+ });
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const config_1 = require("../../src/common/config");
4
4
  const utils_1 = require("../../src/common/utils");
5
+ const dsn_1 = require("../../src/common/dsn");
5
6
  describe("WSConfig to Dsn conversion", () => {
6
7
  test("parses multi-address dsn and keeps connector-level params", () => {
7
8
  const conf = new config_1.WSConfig("ws://root:taosdata@host1:6041,host2:6042/mydb?retries=5&retry_backoff_ms=120&timezone=UTC");
@@ -12,6 +13,7 @@ describe("WSConfig to Dsn conversion", () => {
12
13
  { host: "host2", port: 6042 },
13
14
  ]);
14
15
  expect(dsn.database).toBe("mydb");
16
+ expect(dsn.endpoint).toBe(dsn_1.WS_SQL_ENDPOINT);
15
17
  expect(dsn.params.get("retries")).toBe("5");
16
18
  expect(dsn.params.get("retry_backoff_ms")).toBe("120");
17
19
  expect(dsn.params.get("timezone")).toBe("UTC");