@nktkas/hyperliquid 0.13.2 → 0.14.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 (163) hide show
  1. package/README.md +302 -91
  2. package/esm/mod.d.ts +3 -12
  3. package/esm/mod.d.ts.map +1 -1
  4. package/esm/mod.js +2 -2
  5. package/esm/src/{transports/base.d.ts → base.d.ts} +10 -13
  6. package/esm/src/base.d.ts.map +1 -0
  7. package/esm/src/base.js +14 -0
  8. package/esm/src/clients/event.d.ts +4 -4
  9. package/esm/src/clients/event.d.ts.map +1 -1
  10. package/esm/src/clients/event.js +2 -2
  11. package/esm/src/clients/public.d.ts +109 -6
  12. package/esm/src/clients/public.d.ts.map +1 -1
  13. package/esm/src/clients/public.js +106 -3
  14. package/esm/src/clients/wallet.d.ts +232 -29
  15. package/esm/src/clients/wallet.d.ts.map +1 -1
  16. package/esm/src/clients/wallet.js +836 -220
  17. package/esm/src/signing.d.ts +135 -0
  18. package/esm/src/signing.d.ts.map +1 -0
  19. package/esm/src/signing.js +188 -0
  20. package/esm/src/transports/http/http_transport.d.ts +1 -1
  21. package/esm/src/transports/http/http_transport.d.ts.map +1 -1
  22. package/esm/src/transports/http/http_transport.js +1 -1
  23. package/{script/src/transports/websocket/hyperliquid_event_target.d.ts → esm/src/transports/websocket/_hyperliquid_event_target.d.ts} +7 -15
  24. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -0
  25. package/esm/src/transports/websocket/{hyperliquid_event_target.js → _hyperliquid_event_target.js} +4 -22
  26. package/esm/src/transports/websocket/{reconnecting_websocket.d.ts → _reconnecting_websocket.d.ts} +26 -26
  27. package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -0
  28. package/esm/src/transports/websocket/{reconnecting_websocket.js → _reconnecting_websocket.js} +91 -76
  29. package/esm/src/transports/websocket/{websocket_request_dispatcher.d.ts → _websocket_request_dispatcher.d.ts} +3 -7
  30. package/esm/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +1 -0
  31. package/esm/src/transports/websocket/{websocket_request_dispatcher.js → _websocket_request_dispatcher.js} +3 -7
  32. package/esm/src/transports/websocket/websocket_transport.d.ts +12 -15
  33. package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  34. package/esm/src/transports/websocket/websocket_transport.js +45 -48
  35. package/esm/src/types/exchange/requests.d.ts +172 -20
  36. package/esm/src/types/exchange/requests.d.ts.map +1 -1
  37. package/esm/src/types/exchange/responses.d.ts +32 -32
  38. package/esm/src/types/exchange/responses.d.ts.map +1 -1
  39. package/esm/src/types/explorer/requests.d.ts +12 -12
  40. package/esm/src/types/explorer/requests.d.ts.map +1 -1
  41. package/esm/src/types/explorer/responses.d.ts +36 -1
  42. package/esm/src/types/explorer/responses.d.ts.map +1 -1
  43. package/esm/src/types/info/accounts.d.ts +130 -105
  44. package/esm/src/types/info/accounts.d.ts.map +1 -1
  45. package/esm/src/types/info/assets.d.ts +154 -152
  46. package/esm/src/types/info/assets.d.ts.map +1 -1
  47. package/esm/src/types/info/delegations.d.ts +20 -20
  48. package/esm/src/types/info/delegations.d.ts.map +1 -1
  49. package/esm/src/types/info/orders.d.ts +55 -55
  50. package/esm/src/types/info/orders.d.ts.map +1 -1
  51. package/esm/src/types/info/requests.d.ts +73 -10
  52. package/esm/src/types/info/requests.d.ts.map +1 -1
  53. package/esm/src/types/info/vaults.d.ts +1 -1
  54. package/esm/src/types/info/vaults.d.ts.map +1 -1
  55. package/esm/src/types/mod.d.ts +14 -0
  56. package/esm/src/types/mod.d.ts.map +1 -0
  57. package/esm/src/types/subscriptions/requests.d.ts +1 -1
  58. package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
  59. package/{script/src/types/subscriptions/common.d.ts → esm/src/types/subscriptions/responses.d.ts} +16 -4
  60. package/esm/src/types/subscriptions/responses.d.ts.map +1 -0
  61. package/package.json +20 -4
  62. package/script/mod.d.ts +3 -12
  63. package/script/mod.d.ts.map +1 -1
  64. package/script/mod.js +3 -5
  65. package/script/src/{transports/base.d.ts → base.d.ts} +10 -13
  66. package/script/src/base.d.ts.map +1 -0
  67. package/script/src/{transports/base.js → base.js} +13 -12
  68. package/script/src/clients/event.d.ts +4 -4
  69. package/script/src/clients/event.d.ts.map +1 -1
  70. package/script/src/clients/event.js +2 -2
  71. package/script/src/clients/public.d.ts +109 -6
  72. package/script/src/clients/public.d.ts.map +1 -1
  73. package/script/src/clients/public.js +106 -3
  74. package/script/src/clients/wallet.d.ts +232 -29
  75. package/script/src/clients/wallet.d.ts.map +1 -1
  76. package/script/src/clients/wallet.js +837 -221
  77. package/script/src/signing.d.ts +135 -0
  78. package/script/src/signing.d.ts.map +1 -0
  79. package/script/src/signing.js +203 -0
  80. package/script/src/transports/http/http_transport.d.ts +1 -1
  81. package/script/src/transports/http/http_transport.d.ts.map +1 -1
  82. package/script/src/transports/http/http_transport.js +2 -2
  83. package/{esm/src/transports/websocket/hyperliquid_event_target.d.ts → script/src/transports/websocket/_hyperliquid_event_target.d.ts} +7 -15
  84. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -0
  85. package/script/src/transports/websocket/{hyperliquid_event_target.js → _hyperliquid_event_target.js} +4 -22
  86. package/script/src/transports/websocket/{reconnecting_websocket.d.ts → _reconnecting_websocket.d.ts} +26 -26
  87. package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -0
  88. package/script/src/transports/websocket/{reconnecting_websocket.js → _reconnecting_websocket.js} +94 -78
  89. package/script/src/transports/websocket/{websocket_request_dispatcher.d.ts → _websocket_request_dispatcher.d.ts} +3 -7
  90. package/script/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +1 -0
  91. package/script/src/transports/websocket/{websocket_request_dispatcher.js → _websocket_request_dispatcher.js} +4 -8
  92. package/script/src/transports/websocket/websocket_transport.d.ts +12 -15
  93. package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  94. package/script/src/transports/websocket/websocket_transport.js +51 -54
  95. package/script/src/types/exchange/requests.d.ts +172 -20
  96. package/script/src/types/exchange/requests.d.ts.map +1 -1
  97. package/script/src/types/exchange/responses.d.ts +32 -32
  98. package/script/src/types/exchange/responses.d.ts.map +1 -1
  99. package/script/src/types/explorer/requests.d.ts +12 -12
  100. package/script/src/types/explorer/requests.d.ts.map +1 -1
  101. package/script/src/types/explorer/responses.d.ts +36 -1
  102. package/script/src/types/explorer/responses.d.ts.map +1 -1
  103. package/script/src/types/info/accounts.d.ts +130 -105
  104. package/script/src/types/info/accounts.d.ts.map +1 -1
  105. package/script/src/types/info/assets.d.ts +154 -152
  106. package/script/src/types/info/assets.d.ts.map +1 -1
  107. package/script/src/types/info/delegations.d.ts +20 -20
  108. package/script/src/types/info/delegations.d.ts.map +1 -1
  109. package/script/src/types/info/orders.d.ts +55 -55
  110. package/script/src/types/info/orders.d.ts.map +1 -1
  111. package/script/src/types/info/requests.d.ts +73 -10
  112. package/script/src/types/info/requests.d.ts.map +1 -1
  113. package/script/src/types/info/vaults.d.ts +1 -1
  114. package/script/src/types/info/vaults.d.ts.map +1 -1
  115. package/script/src/types/mod.d.ts +14 -0
  116. package/script/src/types/mod.d.ts.map +1 -0
  117. package/script/src/types/subscriptions/requests.d.ts +1 -1
  118. package/script/src/types/subscriptions/requests.d.ts.map +1 -1
  119. package/{esm/src/types/subscriptions/common.d.ts → script/src/types/subscriptions/responses.d.ts} +16 -4
  120. package/script/src/types/subscriptions/responses.d.ts.map +1 -0
  121. package/esm/src/transports/base.d.ts.map +0 -1
  122. package/esm/src/transports/base.js +0 -14
  123. package/esm/src/transports/websocket/hyperliquid_event_target.d.ts.map +0 -1
  124. package/esm/src/transports/websocket/reconnecting_websocket.d.ts.map +0 -1
  125. package/esm/src/transports/websocket/websocket_request_dispatcher.d.ts.map +0 -1
  126. package/esm/src/types/common.d.ts +0 -3
  127. package/esm/src/types/common.d.ts.map +0 -1
  128. package/esm/src/types/exchange/common.d.ts +0 -36
  129. package/esm/src/types/exchange/common.d.ts.map +0 -1
  130. package/esm/src/types/explorer/common.d.ts +0 -37
  131. package/esm/src/types/explorer/common.d.ts.map +0 -1
  132. package/esm/src/types/explorer/common.js +0 -1
  133. package/esm/src/types/subscriptions/common.d.ts.map +0 -1
  134. package/esm/src/types/subscriptions/common.js +0 -1
  135. package/esm/src/utils/key_sort.d.ts +0 -21
  136. package/esm/src/utils/key_sort.d.ts.map +0 -1
  137. package/esm/src/utils/key_sort.js +0 -124
  138. package/esm/src/utils/signing.d.ts +0 -109
  139. package/esm/src/utils/signing.d.ts.map +0 -1
  140. package/esm/src/utils/signing.js +0 -164
  141. package/script/src/transports/base.d.ts.map +0 -1
  142. package/script/src/transports/websocket/hyperliquid_event_target.d.ts.map +0 -1
  143. package/script/src/transports/websocket/reconnecting_websocket.d.ts.map +0 -1
  144. package/script/src/transports/websocket/websocket_request_dispatcher.d.ts.map +0 -1
  145. package/script/src/types/common.d.ts +0 -3
  146. package/script/src/types/common.d.ts.map +0 -1
  147. package/script/src/types/exchange/common.d.ts +0 -36
  148. package/script/src/types/exchange/common.d.ts.map +0 -1
  149. package/script/src/types/explorer/common.d.ts +0 -37
  150. package/script/src/types/explorer/common.d.ts.map +0 -1
  151. package/script/src/types/explorer/common.js +0 -12
  152. package/script/src/types/subscriptions/common.d.ts.map +0 -1
  153. package/script/src/types/subscriptions/common.js +0 -12
  154. package/script/src/utils/key_sort.d.ts +0 -21
  155. package/script/src/utils/key_sort.d.ts.map +0 -1
  156. package/script/src/utils/key_sort.js +0 -137
  157. package/script/src/utils/signing.d.ts +0 -109
  158. package/script/src/utils/signing.d.ts.map +0 -1
  159. package/script/src/utils/signing.js +0 -182
  160. /package/esm/src/types/{common.js → mod.js} +0 -0
  161. /package/esm/src/types/{exchange/common.js → subscriptions/responses.js} +0 -0
  162. /package/script/src/types/{common.js → mod.js} +0 -0
  163. /package/script/src/types/{exchange/common.js → subscriptions/responses.js} +0 -0
@@ -5,15 +5,14 @@
5
5
  if (v !== undefined) module.exports = v;
6
6
  }
7
7
  else if (typeof define === "function" && define.amd) {
8
- define(["require", "exports"], factory);
8
+ define(["require", "exports", "../../base.js"], factory);
9
9
  }
10
10
  })(function (require, exports) {
11
11
  "use strict";
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.ReconnectingWebSocket = void 0;
14
- /**
15
- * Simple FIFO (First In, First Out) buffer implementation.
16
- */
13
+ exports.ReconnectingWebSocket = exports.ReconnectingWebSocketError = void 0;
14
+ const base_js_1 = require("../../base.js");
15
+ /** Simple FIFO (First In, First Out) buffer implementation. */
17
16
  class FIFOMessageBuffer {
18
17
  constructor() {
19
18
  Object.defineProperty(this, "messages", {
@@ -33,6 +32,26 @@
33
32
  this.messages = [];
34
33
  }
35
34
  }
35
+ /** Error thrown when reconnection problems occur. */
36
+ class ReconnectingWebSocketError extends base_js_1.TransportError {
37
+ constructor(code, originalError) {
38
+ super(`Error when reconnecting WebSocket: ${code}`);
39
+ Object.defineProperty(this, "code", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: code
44
+ });
45
+ Object.defineProperty(this, "originalError", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: originalError
50
+ });
51
+ this.name = "ReconnectingWebSocketError";
52
+ }
53
+ }
54
+ exports.ReconnectingWebSocketError = ReconnectingWebSocketError;
36
55
  /**
37
56
  * A WebSocket that automatically reconnects when disconnected.
38
57
  * Fully compatible with standard WebSocket API.
@@ -46,35 +65,35 @@
46
65
  */
47
66
  constructor(url, protocols, options) {
48
67
  /** Controller for handling connection termination */
49
- Object.defineProperty(this, "terminationController", {
68
+ Object.defineProperty(this, "_terminationController", {
50
69
  enumerable: true,
51
70
  configurable: true,
52
71
  writable: true,
53
72
  value: new AbortController()
54
73
  });
55
74
  /** WebSocket protocols */
56
- Object.defineProperty(this, "protocols", {
75
+ Object.defineProperty(this, "_protocols", {
57
76
  enumerable: true,
58
77
  configurable: true,
59
78
  writable: true,
60
79
  value: void 0
61
80
  });
62
81
  /** The underlying WebSocket instance */
63
- Object.defineProperty(this, "socket", {
82
+ Object.defineProperty(this, "_socket", {
64
83
  enumerable: true,
65
84
  configurable: true,
66
85
  writable: true,
67
86
  value: void 0
68
87
  });
69
88
  /** Current number of reconnection attempts */
70
- Object.defineProperty(this, "reconnectCount", {
89
+ Object.defineProperty(this, "_reconnectCount", {
71
90
  enumerable: true,
72
91
  configurable: true,
73
92
  writable: true,
74
93
  value: 0
75
94
  });
76
95
  /** Array of registered event listeners */
77
- Object.defineProperty(this, "eventListeners", {
96
+ Object.defineProperty(this, "_eventListeners", {
78
97
  enumerable: true,
79
98
  configurable: true,
80
99
  writable: true,
@@ -92,7 +111,7 @@
92
111
  enumerable: true,
93
112
  configurable: true,
94
113
  writable: true,
95
- value: this.terminationController.signal
114
+ value: this._terminationController.signal
96
115
  });
97
116
  Object.defineProperty(this, "CLOSED", {
98
117
  enumerable: true,
@@ -124,13 +143,12 @@
124
143
  connectionDelay: options?.connectionDelay ?? ((attempt) => Math.min(~~(1 << attempt) * 150, 10_000)),
125
144
  shouldReconnect: options?.shouldReconnect ?? (() => true),
126
145
  messageBuffer: options?.messageBuffer ?? new FIFOMessageBuffer(),
127
- WebSocketConstructor: options?.WebSocketConstructor ?? WebSocket,
128
146
  };
129
- this.protocols = protocols;
130
- this.socket = this.reconnectOptions.connectionTimeout
131
- ? this.connectWithTimeout(url, this.protocols, this.reconnectOptions.connectionTimeout)
132
- : new this.reconnectOptions.WebSocketConstructor(url, this.protocols);
133
- this.initEventListeners();
147
+ this._protocols = protocols;
148
+ this._socket = this.reconnectOptions.connectionTimeout
149
+ ? this._connectWithTimeout(url, this._protocols, this.reconnectOptions.connectionTimeout)
150
+ : new WebSocket(url, this._protocols);
151
+ this._initEventListeners();
134
152
  }
135
153
  /**
136
154
  * Creates a WebSocket connection with timeout.
@@ -139,8 +157,8 @@
139
157
  * @param timeout - The connection timeout in ms.
140
158
  * @returns A new WebSocket instance.
141
159
  */
142
- connectWithTimeout(url, protocols, timeout) {
143
- const socket = new this.reconnectOptions.WebSocketConstructor(url, protocols);
160
+ _connectWithTimeout(url, protocols, timeout) {
161
+ const socket = new WebSocket(url, protocols);
144
162
  const timeoutId = setTimeout(() => {
145
163
  socket.removeEventListener("open", openHandler);
146
164
  socket.removeEventListener("close", closeHandler);
@@ -158,55 +176,53 @@
158
176
  socket.addEventListener("close", closeHandler, { once: true });
159
177
  return socket;
160
178
  }
161
- /**
162
- * Initializes the internal event listeners for the WebSocket.
163
- */
164
- initEventListeners() {
165
- this.socket.addEventListener("open", () => {
179
+ /** Initializes the internal event listeners for the WebSocket. */
180
+ _initEventListeners() {
181
+ this._socket.addEventListener("open", () => {
166
182
  // Reset reconnection count
167
- this.reconnectCount = 0;
183
+ this._reconnectCount = 0;
168
184
  // Send all buffered messages
169
185
  let message;
170
186
  while ((message = this.reconnectOptions.messageBuffer.shift()) !== undefined) {
171
- this.socket.send(message);
187
+ this._socket.send(message);
172
188
  }
173
189
  }, { once: true });
174
- this.socket.addEventListener("close", async (event) => {
190
+ this._socket.addEventListener("close", async (event) => {
175
191
  try {
176
192
  // If the termination signal is already aborted, do not attempt to reconnect
177
193
  if (this.terminationSignal.aborted)
178
194
  return;
179
195
  // Check if reconnection should be attempted
180
- if (++this.reconnectCount > this.reconnectOptions.maxRetries) {
181
- this.cleanup(new Error("RECONNECTION_LIMIT_REACHED", { cause: event }));
196
+ if (++this._reconnectCount > this.reconnectOptions.maxRetries) {
197
+ this._cleanup(new ReconnectingWebSocketError("RECONNECTION_LIMIT_REACHED"));
182
198
  return;
183
199
  }
184
200
  const userDecision = await this.reconnectOptions.shouldReconnect(event);
185
201
  if (this.terminationSignal.aborted)
186
202
  return; // Check again after the await
187
203
  if (!userDecision) {
188
- this.cleanup(new Error("RECONNECTION_STOPPED_BY_USER", { cause: event }));
204
+ this._cleanup(new ReconnectingWebSocketError("RECONNECTION_STOPPED_BY_USER"));
189
205
  return;
190
206
  }
191
207
  // Delay before reconnecting
192
208
  const delay = typeof this.reconnectOptions.connectionDelay === "number"
193
209
  ? this.reconnectOptions.connectionDelay
194
- : await this.reconnectOptions.connectionDelay(this.reconnectCount);
210
+ : await this.reconnectOptions.connectionDelay(this._reconnectCount);
195
211
  if (this.terminationSignal.aborted)
196
212
  return; // Check again after the await
197
213
  await sleep(delay, this.terminationSignal);
198
214
  // Reconnect the socket
199
- this.socket = this.reconnectOptions.connectionTimeout
200
- ? this.connectWithTimeout(this.url, this.protocols, this.reconnectOptions.connectionTimeout)
201
- : new this.reconnectOptions.WebSocketConstructor(this.url, this.protocols);
215
+ this._socket = this.reconnectOptions.connectionTimeout
216
+ ? this._connectWithTimeout(this.url, this._protocols, this.reconnectOptions.connectionTimeout)
217
+ : new WebSocket(this.url, this._protocols);
202
218
  // Reconnect all listeners
203
- this.initEventListeners();
204
- this.eventListeners.forEach(({ type, listenerProxy, options }) => {
205
- this.socket.addEventListener(type, listenerProxy, options);
219
+ this._initEventListeners();
220
+ this._eventListeners.forEach(({ type, listenerProxy, options }) => {
221
+ this._socket.addEventListener(type, listenerProxy, options);
206
222
  });
207
223
  }
208
224
  catch (error) {
209
- this.cleanup(new Error("RECONNECTION_ERROR", { cause: { error, event } }));
225
+ this._cleanup(new ReconnectingWebSocketError("UNKNOWN_ERROR", error));
210
226
  }
211
227
  }, { once: true });
212
228
  }
@@ -214,10 +230,10 @@
214
230
  * Clean up internal resources.
215
231
  * @param reason - The reason for cleanup.
216
232
  */
217
- cleanup(reason) {
218
- this.terminationController.abort(reason);
233
+ _cleanup(reason) {
234
+ this._terminationController.abort(reason);
219
235
  this.reconnectOptions.messageBuffer.clear();
220
- this.eventListeners = [];
236
+ this._eventListeners = [];
221
237
  }
222
238
  /**
223
239
  * Check if two event listeners are the same (just like EventTarget).
@@ -225,79 +241,79 @@
225
241
  * @param b - Second event listener configuration.
226
242
  * @returns True if the listeners match.
227
243
  */
228
- isListenerMatch(a, b) {
244
+ _isListenerMatch(a, b) {
229
245
  const aCapture = Boolean(typeof a.options === "object" ? a.options.capture : a.options);
230
246
  const bCapture = Boolean(typeof b.options === "object" ? b.options.capture : b.options);
231
247
  return a.type === b.type && a.listener === b.listener && aCapture === bCapture;
232
248
  }
233
249
  // WebSocket property implementations
234
250
  get url() {
235
- return this.socket.url;
251
+ return this._socket.url;
236
252
  }
237
253
  get readyState() {
238
- return this.socket.readyState;
254
+ return this._socket.readyState;
239
255
  }
240
256
  get bufferedAmount() {
241
- return this.socket.bufferedAmount;
257
+ return this._socket.bufferedAmount;
242
258
  }
243
259
  get extensions() {
244
- return this.socket.extensions;
260
+ return this._socket.extensions;
245
261
  }
246
262
  get protocol() {
247
- return this.socket.protocol;
263
+ return this._socket.protocol;
248
264
  }
249
265
  get binaryType() {
250
- return this.socket.binaryType;
266
+ return this._socket.binaryType;
251
267
  }
252
268
  set binaryType(value) {
253
- this.socket.binaryType = value;
269
+ this._socket.binaryType = value;
254
270
  }
255
271
  get onclose() {
256
- return this.socket.onclose;
272
+ return this._socket.onclose;
257
273
  }
258
274
  set onclose(value) {
259
- this.socket.onclose = value;
275
+ this._socket.onclose = value;
260
276
  }
261
277
  get onerror() {
262
- return this.socket.onerror;
278
+ return this._socket.onerror;
263
279
  }
264
280
  set onerror(value) {
265
- this.socket.onerror = value;
281
+ this._socket.onerror = value;
266
282
  }
267
283
  get onmessage() {
268
- return this.socket.onmessage;
284
+ return this._socket.onmessage;
269
285
  }
270
286
  set onmessage(value) {
271
- this.socket.onmessage = value;
287
+ this._socket.onmessage = value;
272
288
  }
273
289
  get onopen() {
274
- return this.socket.onopen;
290
+ return this._socket.onopen;
275
291
  }
276
292
  set onopen(value) {
277
- this.socket.onopen = value;
293
+ this._socket.onopen = value;
278
294
  }
279
295
  /**
280
296
  * @param permanently - If true, the connection will be permanently closed. Default is true.
281
297
  */
282
298
  close(code, reason, permanently = true) {
283
299
  if (permanently)
284
- this.cleanup(new Error("USER_INITIATED_CLOSE"));
285
- this.socket.close(code, reason);
300
+ this._cleanup(new ReconnectingWebSocketError("USER_INITIATED_CLOSE"));
301
+ this._socket.close(code, reason);
286
302
  }
287
303
  /**
288
304
  * @note If the connection is not open, the data will be buffered and sent when the connection is established.
289
305
  */
290
306
  send(data) {
291
- if (this.socket.readyState !== WebSocket.OPEN && !this.terminationSignal.aborted) {
307
+ if (this._socket.readyState !== WebSocket.OPEN && !this.terminationSignal.aborted) {
292
308
  this.reconnectOptions.messageBuffer.push(data);
293
309
  }
294
310
  else {
295
- this.socket.send(data);
311
+ this._socket.send(data);
296
312
  }
297
313
  }
298
314
  addEventListener(type, listener, options) {
299
315
  // Check if the listener is already added
300
- const exists = this.eventListeners.some((e) => this.isListenerMatch(e, { type, listener, options }));
316
+ const exists = this._eventListeners.some((e) => this._isListenerMatch(e, { type, listener, options }));
301
317
  if (exists)
302
318
  return;
303
319
  // Wrap the original listener to follow the once option when reconnecting
@@ -312,25 +328,25 @@
312
328
  }
313
329
  finally {
314
330
  if (typeof options === "object" && options.once === true) {
315
- const index = this.eventListeners.findIndex((e) => this.isListenerMatch(e, { type, listener, options }));
331
+ const index = this._eventListeners.findIndex((e) => this._isListenerMatch(e, { type, listener, options }));
316
332
  if (index !== -1)
317
- this.eventListeners.splice(index, 1);
333
+ this._eventListeners.splice(index, 1);
318
334
  }
319
335
  }
320
336
  };
321
- this.eventListeners.push({ type, listener, options, listenerProxy });
322
- this.socket.addEventListener(type, listenerProxy, options);
337
+ this._eventListeners.push({ type, listener, options, listenerProxy });
338
+ this._socket.addEventListener(type, listenerProxy, options);
323
339
  }
324
340
  removeEventListener(type, listener, options) {
325
- const index = this.eventListeners.findIndex((e) => this.isListenerMatch(e, { type, listener, options }));
341
+ const index = this._eventListeners.findIndex((e) => this._isListenerMatch(e, { type, listener, options }));
326
342
  if (index !== -1) {
327
- const { listenerProxy } = this.eventListeners[index];
328
- this.socket.removeEventListener(type, listenerProxy, options);
329
- this.eventListeners.splice(index, 1);
343
+ const { listenerProxy } = this._eventListeners[index];
344
+ this._socket.removeEventListener(type, listenerProxy, options);
345
+ this._eventListeners.splice(index, 1);
330
346
  }
331
347
  }
332
348
  dispatchEvent(event) {
333
- return this.socket.dispatchEvent(event);
349
+ return this._socket.dispatchEvent(event);
334
350
  }
335
351
  }
336
352
  exports.ReconnectingWebSocket = ReconnectingWebSocket;
@@ -366,18 +382,18 @@
366
382
  * @returns A promise that resolves after the specified delay.
367
383
  */
368
384
  function sleep(ms, signal) {
385
+ if (signal?.aborted)
386
+ return Promise.reject(signal.reason);
369
387
  return new Promise((resolve, reject) => {
370
- if (signal?.aborted) {
371
- return reject(signal.reason);
372
- }
373
- const onAbort = function () {
388
+ const onAbort = () => {
374
389
  clearTimeout(timer);
375
- reject(this.reason);
390
+ reject(signal?.reason);
376
391
  };
377
- const timer = setTimeout(() => {
392
+ const onTimeout = () => {
378
393
  signal?.removeEventListener("abort", onAbort);
379
394
  resolve();
380
- }, ms);
395
+ };
396
+ const timer = setTimeout(onTimeout, ms);
381
397
  signal?.addEventListener("abort", onAbort, { once: true });
382
398
  });
383
399
  }
@@ -1,15 +1,11 @@
1
- import { TransportError } from "../base.js";
2
- import type { HyperliquidEventTarget } from "./hyperliquid_event_target.js";
1
+ import { TransportError } from "../../base.js";
2
+ import type { HyperliquidEventTarget } from "./_hyperliquid_event_target.js";
3
3
  /**
4
4
  * Error thrown when a WebSocket request fails:
5
5
  * - When the WebSocket connection is closed
6
6
  * - When the server responds with an error message
7
7
  */
8
8
  export declare class WebSocketRequestError extends TransportError {
9
- /**
10
- * Creates a new WebSocket request error.
11
- * @param message - The error message.
12
- */
13
9
  constructor(message: string);
14
10
  }
15
11
  /**
@@ -60,4 +56,4 @@ export declare class WebSocketRequestDispatcher {
60
56
  */
61
57
  static requestToId(value: unknown): string;
62
58
  }
63
- //# sourceMappingURL=websocket_request_dispatcher.d.ts.map
59
+ //# sourceMappingURL=_websocket_request_dispatcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_websocket_request_dispatcher.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/_websocket_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typeof define === "function" && define.amd) {
7
- define(["require", "exports", "../base.js"], factory);
7
+ define(["require", "exports", "../../base.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.WebSocketRequestDispatcher = exports.WebSocketRequestError = void 0;
13
- const base_js_1 = require("../base.js");
13
+ const base_js_1 = require("../../base.js");
14
14
  /**
15
15
  * Error thrown when a WebSocket request fails:
16
16
  * - When the WebSocket connection is closed
17
17
  * - When the server responds with an error message
18
18
  */
19
19
  class WebSocketRequestError extends base_js_1.TransportError {
20
- /**
21
- * Creates a new WebSocket request error.
22
- * @param message - The error message.
23
- */
24
20
  constructor(message) {
25
21
  super(message);
26
22
  this.name = "WebSocketRequestError";
@@ -117,7 +113,7 @@
117
113
  * @param signal - An optional abort signal.
118
114
  * @returns A promise that resolves with the parsed JSON response body.
119
115
  */
120
- request(method, payload, signal) {
116
+ async request(method, payload, signal) {
121
117
  signal?.throwIfAborted();
122
118
  // Create a request object
123
119
  let id;
@@ -134,7 +130,7 @@
134
130
  this.socket.send(JSON.stringify(request));
135
131
  // Wait for a response
136
132
  let onAbort;
137
- return new Promise((resolve, reject) => {
133
+ return await new Promise((resolve, reject) => {
138
134
  // Add an abort listener
139
135
  onAbort = () => reject(signal?.reason);
140
136
  signal?.addEventListener("abort", onAbort, { once: true });
@@ -1,10 +1,10 @@
1
- import { ReconnectingWebSocket, type ReconnectingWebSocketOptions } from "./reconnecting_websocket.js";
2
- import { HyperliquidEventTarget } from "./hyperliquid_event_target.js";
3
- import { WebSocketRequestDispatcher } from "./websocket_request_dispatcher.js";
4
- import type { IRequestTransport, ISubscriptionTransport, Subscription } from "../base.js";
5
- /**
6
- * Configuration options for the WebSocket transport layer.
7
- */
1
+ import { ReconnectingWebSocket, type ReconnectingWebSocketOptions } from "./_reconnecting_websocket.js";
2
+ import { HyperliquidEventTarget } from "./_hyperliquid_event_target.js";
3
+ import { WebSocketRequestDispatcher, WebSocketRequestError } from "./_websocket_request_dispatcher.js";
4
+ import type { IRequestTransport, ISubscriptionTransport, Subscription } from "../../base.js";
5
+ export { WebSocketRequestError };
6
+ export type { MessageBufferStrategy, ReconnectingWebSocketOptions } from "./_reconnecting_websocket.js";
7
+ /** Configuration options for the WebSocket transport layer. */
8
8
  export interface WebSocketTransportOptions {
9
9
  /**
10
10
  * The WebSocket URL.
@@ -36,12 +36,10 @@ export interface WebSocketTransportOptions {
36
36
  */
37
37
  reconnect?: ReconnectingWebSocketOptions;
38
38
  }
39
- /**
40
- * WebSocket implementation of the REST and Subscription transport interfaces.
41
- */
39
+ /** WebSocket implementation of the REST and Subscription transport interfaces. */
42
40
  export declare class WebSocketTransport implements IRequestTransport, ISubscriptionTransport {
43
41
  /** The interval timer ID for keep-alive messages. */
44
- protected _keepAliveTimer: number | undefined;
42
+ protected _keepAliveTimer: number | null;
45
43
  /** The WebSocket request dispatcher instance. */
46
44
  protected _wsRequester: WebSocketRequestDispatcher;
47
45
  /** The Hyperliquid event target instance. */
@@ -53,10 +51,7 @@ export declare class WebSocketTransport implements IRequestTransport, ISubscript
53
51
  * and a map of listeners to their metadata (channel + unsubscribe function).
54
52
  */
55
53
  protected _subscriptions: Map<string, {
56
- listeners: Map<(data: CustomEvent) => void, {
57
- channel: string;
58
- unsubscribe: (signal?: AbortSignal) => Promise<void>;
59
- }>;
54
+ listeners: Map<(data: CustomEvent) => void, (signal?: AbortSignal) => Promise<void>>;
60
55
  requestPromise: Promise<unknown>;
61
56
  }>;
62
57
  /**
@@ -110,5 +105,7 @@ export declare class WebSocketTransport implements IRequestTransport, ISubscript
110
105
  * @returns A promise that resolves when the connection is fully closed.
111
106
  */
112
107
  close(signal?: AbortSignal): Promise<void>;
108
+ /** Combines a timeout with an optional abort signal. */
109
+ protected _combineTimeoutWithSignal(timeout?: number | null, signal?: AbortSignal): AbortSignal | undefined;
113
110
  }
114
111
  //# sourceMappingURL=websocket_transport.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"websocket_transport.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/websocket_transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,KAAK,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AACvG,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1F;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACtC;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAEnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAExB;;;OAGG;IACH,SAAS,CAAC,EAAE;QACR;;;;WAIG;QACH,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAC5B,CAAC;IAEF;;OAEG;IACH,SAAS,CAAC,EAAE,4BAA4B,CAAC;CAC5C;AAED;;GAEG;AACH,qBAAa,kBAAmB,YAAW,iBAAiB,EAAE,sBAAsB;IAChF,qDAAqD;IACrD,SAAS,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;IAE9C,iDAAiD;IACjD,SAAS,CAAC,YAAY,EAAE,0BAA0B,CAAC;IAEnD,6CAA6C;IAC7C,SAAS,CAAC,SAAS,EAAE,sBAAsB,CAAC;IAE5C;;;;;OAKG;IACH,SAAS,CAAC,cAAc,EAAE,GAAG,CACzB,MAAM,EACN;QACI,SAAS,EAAE,GAAG,CACV,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,EAC3B;YACI,OAAO,EAAE,MAAM,CAAC;YAChB,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;SACxD,CACJ,CAAC;QACF,cAAc,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;KACpC,CACJ,CAAa;IAEd;;;OAGG;IACH,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB,yCAAyC;IACzC,QAAQ,CAAC,SAAS,EAAE;QAChB;;;WAGG;QACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;KACpC,CAAC;IAEF,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;IAEvC;;;OAGG;gBACS,OAAO,CAAC,EAAE,yBAAyB;IAwC/C;;;;;;;;OAQG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAevG;;;;;;;OAOG;IACG,SAAS,CACX,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,EACrC,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,YAAY,CAAC;IAwExB;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAuB1C;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAoB7C"}
1
+ {"version":3,"file":"websocket_transport.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/websocket_transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,KAAK,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AACxG,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AACvG,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,YAAY,EAAE,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