@nktkas/hyperliquid 0.13.1 → 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.
- package/LICENSE +20 -20
- package/README.md +334 -107
- package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts +9 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.js +2 -0
- package/esm/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.d.ts +3 -1
- package/esm/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.js +1 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts +9 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.js +2 -0
- package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.js +1 -1
- package/{script/deps/jsr.io/@std/encoding/1.0.6 → esm/deps/jsr.io/@std/encoding/1.0.7}/hex.d.ts +3 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/hex.js +1 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +9 -0
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.js +2 -0
- package/esm/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.d.ts +3 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.js +2 -2
- package/esm/mod.d.ts +4 -12
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +2 -2
- package/{script/src/transports → esm/src}/base.d.ts +10 -13
- package/esm/src/base.d.ts.map +1 -0
- package/esm/src/base.js +14 -0
- package/esm/src/clients/event.d.ts +59 -18
- package/esm/src/clients/event.d.ts.map +1 -1
- package/esm/src/clients/event.js +74 -18
- package/esm/src/clients/public.d.ts +348 -53
- package/esm/src/clients/public.d.ts.map +1 -1
- package/esm/src/clients/public.js +349 -50
- package/esm/src/clients/wallet.d.ts +345 -73
- package/esm/src/clients/wallet.d.ts.map +1 -1
- package/esm/src/clients/wallet.js +979 -229
- package/esm/src/signing.d.ts +135 -0
- package/esm/src/signing.d.ts.map +1 -0
- package/esm/src/signing.js +188 -0
- package/esm/src/transports/http/http_transport.d.ts +1 -1
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +1 -1
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +64 -0
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -0
- package/esm/src/transports/websocket/_hyperliquid_event_target.js +52 -0
- package/esm/src/transports/websocket/{reconnecting_websocket.d.ts → _reconnecting_websocket.d.ts} +26 -26
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -0
- package/esm/src/transports/websocket/{reconnecting_websocket.js → _reconnecting_websocket.js} +91 -76
- package/{script/src/transports/websocket/websocket_request_dispatcher.d.ts → esm/src/transports/websocket/_websocket_request_dispatcher.d.ts} +3 -7
- package/esm/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +1 -0
- package/esm/src/transports/websocket/{websocket_request_dispatcher.js → _websocket_request_dispatcher.js} +6 -10
- package/esm/src/transports/websocket/websocket_transport.d.ts +15 -21
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +55 -52
- package/esm/src/types/exchange/requests.d.ts +298 -79
- package/esm/src/types/exchange/requests.d.ts.map +1 -1
- package/esm/src/types/exchange/responses.d.ts +38 -38
- package/esm/src/types/exchange/responses.d.ts.map +1 -1
- package/esm/src/types/explorer/requests.d.ts +23 -10
- package/esm/src/types/explorer/requests.d.ts.map +1 -1
- package/esm/src/types/explorer/responses.d.ts +45 -3
- package/esm/src/types/explorer/responses.d.ts.map +1 -1
- package/esm/src/types/info/accounts.d.ts +279 -189
- package/esm/src/types/info/accounts.d.ts.map +1 -1
- package/esm/src/types/info/assets.d.ts +191 -185
- package/esm/src/types/info/assets.d.ts.map +1 -1
- package/esm/src/types/info/delegations.d.ts +117 -0
- package/esm/src/types/info/delegations.d.ts.map +1 -0
- package/esm/src/types/info/orders.d.ts +94 -94
- package/esm/src/types/info/orders.d.ts.map +1 -1
- package/esm/src/types/info/requests.d.ts +192 -64
- package/esm/src/types/info/requests.d.ts.map +1 -1
- package/esm/src/types/info/vaults.d.ts +42 -85
- package/esm/src/types/info/vaults.d.ts.map +1 -1
- package/esm/src/types/mod.d.ts +14 -0
- package/esm/src/types/mod.d.ts.map +1 -0
- package/esm/src/types/subscriptions/requests.d.ts +11 -1
- package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
- package/{script/src/types/subscriptions/common.d.ts → esm/src/types/subscriptions/responses.d.ts} +18 -3
- package/esm/src/types/subscriptions/responses.d.ts.map +1 -0
- package/package.json +20 -4
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +13 -3
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +23 -13
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +55 -45
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.js +97 -87
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.js +14 -4
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js +288 -278
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.js +238 -228
- package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts +9 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/_types.js +13 -0
- package/script/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.d.ts +3 -1
- package/script/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/concat.js +45 -0
- package/script/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts +9 -0
- package/script/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.7/_types.js +13 -0
- package/script/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.js +39 -0
- package/{esm/deps/jsr.io/@std/encoding/1.0.6 → script/deps/jsr.io/@std/encoding/1.0.7}/hex.d.ts +3 -1
- package/script/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.7/hex.js +123 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +9 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.js +13 -0
- package/script/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.d.ts +3 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.js +250 -0
- package/script/mod.d.ts +4 -12
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +21 -13
- package/{esm/src/transports → script/src}/base.d.ts +10 -13
- package/script/src/base.d.ts.map +1 -0
- package/script/src/base.js +29 -0
- package/script/src/clients/event.d.ts +59 -18
- package/script/src/clients/event.d.ts.map +1 -1
- package/script/src/clients/event.js +551 -485
- package/script/src/clients/public.d.ts +348 -53
- package/script/src/clients/public.d.ts.map +1 -1
- package/script/src/clients/public.js +1017 -708
- package/script/src/clients/wallet.d.ts +345 -73
- package/script/src/clients/wallet.d.ts.map +1 -1
- package/script/src/clients/wallet.js +1737 -977
- package/script/src/signing.d.ts +135 -0
- package/script/src/signing.d.ts.map +1 -0
- package/script/src/signing.js +203 -0
- package/script/src/transports/http/http_transport.d.ts +1 -1
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +174 -164
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +64 -0
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -0
- package/script/src/transports/websocket/_hyperliquid_event_target.js +66 -0
- package/script/src/transports/websocket/{reconnecting_websocket.d.ts → _reconnecting_websocket.d.ts} +26 -26
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -0
- package/script/src/transports/websocket/_reconnecting_websocket.js +400 -0
- package/{esm/src/transports/websocket/websocket_request_dispatcher.d.ts → script/src/transports/websocket/_websocket_request_dispatcher.d.ts} +3 -7
- package/script/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +1 -0
- package/script/src/transports/websocket/_websocket_request_dispatcher.js +212 -0
- package/script/src/transports/websocket/websocket_transport.d.ts +15 -21
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +235 -222
- package/script/src/types/exchange/requests.d.ts +298 -79
- package/script/src/types/exchange/requests.d.ts.map +1 -1
- package/script/src/types/exchange/requests.js +12 -2
- package/script/src/types/exchange/responses.d.ts +38 -38
- package/script/src/types/exchange/responses.d.ts.map +1 -1
- package/script/src/types/exchange/responses.js +12 -2
- package/script/src/types/explorer/requests.d.ts +23 -10
- package/script/src/types/explorer/requests.d.ts.map +1 -1
- package/script/src/types/explorer/requests.js +12 -2
- package/script/src/types/explorer/responses.d.ts +45 -3
- package/script/src/types/explorer/responses.d.ts.map +1 -1
- package/script/src/types/explorer/responses.js +12 -2
- package/script/src/types/info/accounts.d.ts +279 -189
- package/script/src/types/info/accounts.d.ts.map +1 -1
- package/script/src/types/info/accounts.js +12 -2
- package/script/src/types/info/assets.d.ts +191 -185
- package/script/src/types/info/assets.d.ts.map +1 -1
- package/script/src/types/info/assets.js +12 -2
- package/script/src/types/info/delegations.d.ts +117 -0
- package/script/src/types/info/delegations.d.ts.map +1 -0
- package/script/src/types/info/delegations.js +12 -0
- package/script/src/types/info/orders.d.ts +94 -94
- package/script/src/types/info/orders.d.ts.map +1 -1
- package/script/src/types/info/orders.js +12 -2
- package/script/src/types/info/requests.d.ts +192 -64
- package/script/src/types/info/requests.d.ts.map +1 -1
- package/script/src/types/info/requests.js +12 -2
- package/script/src/types/info/vaults.d.ts +42 -85
- package/script/src/types/info/vaults.d.ts.map +1 -1
- package/script/src/types/info/vaults.js +12 -2
- package/script/src/types/mod.d.ts +14 -0
- package/script/src/types/mod.d.ts.map +1 -0
- package/script/src/types/mod.js +12 -0
- package/script/src/types/subscriptions/requests.d.ts +11 -1
- package/script/src/types/subscriptions/requests.d.ts.map +1 -1
- package/script/src/types/subscriptions/requests.js +12 -2
- package/{esm/src/types/subscriptions/common.d.ts → script/src/types/subscriptions/responses.d.ts} +18 -3
- package/script/src/types/subscriptions/responses.d.ts.map +1 -0
- package/script/src/types/subscriptions/responses.js +12 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +0 -1
- package/esm/src/transports/base.d.ts.map +0 -1
- package/esm/src/transports/base.js +0 -14
- package/esm/src/transports/websocket/hyperliquid_event_target.d.ts +0 -66
- package/esm/src/transports/websocket/hyperliquid_event_target.d.ts.map +0 -1
- package/esm/src/transports/websocket/hyperliquid_event_target.js +0 -33
- package/esm/src/transports/websocket/reconnecting_websocket.d.ts.map +0 -1
- package/esm/src/transports/websocket/websocket_request_dispatcher.d.ts.map +0 -1
- package/esm/src/types/common.d.ts +0 -3
- package/esm/src/types/common.d.ts.map +0 -1
- package/esm/src/types/exchange/common.d.ts +0 -36
- package/esm/src/types/exchange/common.d.ts.map +0 -1
- package/esm/src/types/explorer/common.d.ts +0 -37
- package/esm/src/types/explorer/common.d.ts.map +0 -1
- package/esm/src/types/subscriptions/common.d.ts.map +0 -1
- package/esm/src/types/subscriptions/common.js +0 -1
- package/esm/src/utils/key_sort.d.ts +0 -21
- package/esm/src/utils/key_sort.d.ts.map +0 -1
- package/esm/src/utils/key_sort.js +0 -124
- package/esm/src/utils/signing.d.ts +0 -109
- package/esm/src/utils/signing.d.ts.map +0 -1
- package/esm/src/utils/signing.js +0 -164
- package/script/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/bytes/1.0.4/concat.js +0 -35
- package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js +0 -29
- package/script/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.6/hex.js +0 -113
- package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.js +0 -240
- package/script/src/transports/base.d.ts.map +0 -1
- package/script/src/transports/base.js +0 -18
- package/script/src/transports/websocket/hyperliquid_event_target.d.ts +0 -66
- package/script/src/transports/websocket/hyperliquid_event_target.d.ts.map +0 -1
- package/script/src/transports/websocket/hyperliquid_event_target.js +0 -37
- package/script/src/transports/websocket/reconnecting_websocket.d.ts.map +0 -1
- package/script/src/transports/websocket/reconnecting_websocket.js +0 -374
- package/script/src/transports/websocket/websocket_request_dispatcher.d.ts.map +0 -1
- package/script/src/transports/websocket/websocket_request_dispatcher.js +0 -206
- package/script/src/types/common.d.ts +0 -3
- package/script/src/types/common.d.ts.map +0 -1
- package/script/src/types/common.js +0 -2
- package/script/src/types/exchange/common.d.ts +0 -36
- package/script/src/types/exchange/common.d.ts.map +0 -1
- package/script/src/types/exchange/common.js +0 -2
- package/script/src/types/explorer/common.d.ts +0 -37
- package/script/src/types/explorer/common.d.ts.map +0 -1
- package/script/src/types/explorer/common.js +0 -2
- package/script/src/types/subscriptions/common.d.ts.map +0 -1
- package/script/src/types/subscriptions/common.js +0 -2
- package/script/src/utils/key_sort.d.ts +0 -21
- package/script/src/utils/key_sort.d.ts.map +0 -1
- package/script/src/utils/key_sort.js +0 -127
- package/script/src/utils/signing.d.ts +0 -109
- package/script/src/utils/signing.d.ts.map +0 -1
- package/script/src/utils/signing.js +0 -172
- /package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts +0 -0
- /package/esm/src/types/{common.js → info/delegations.js} +0 -0
- /package/esm/src/types/{exchange/common.js → mod.js} +0 -0
- /package/esm/src/types/{explorer/common.js → subscriptions/responses.js} +0 -0
- /package/script/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts +0 -0
|
@@ -1,178 +1,188 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "../../base.js"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HttpTransport = exports.HttpRequestError = void 0;
|
|
13
|
+
const base_js_1 = require("../../base.js");
|
|
11
14
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
+
* Error thrown when an HTTP response is deemed invalid:
|
|
16
|
+
* - Non-200 status code
|
|
17
|
+
* - Unexpected content type
|
|
15
18
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
class HttpRequestError extends base_js_1.TransportError {
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new HTTP request error.
|
|
22
|
+
* @param response - The failed HTTP response.
|
|
23
|
+
* @param responseBody - The raw response body content, if available.
|
|
24
|
+
*/
|
|
25
|
+
constructor(response, responseBody) {
|
|
26
|
+
let message = `HTTP request failed: status ${response.status}`;
|
|
27
|
+
if (responseBody)
|
|
28
|
+
message += `, body "${responseBody}"`;
|
|
29
|
+
super(message);
|
|
30
|
+
Object.defineProperty(this, "response", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
configurable: true,
|
|
33
|
+
writable: true,
|
|
34
|
+
value: response
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(this, "responseBody", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true,
|
|
40
|
+
value: responseBody
|
|
41
|
+
});
|
|
42
|
+
this.name = "HttpRequestError";
|
|
43
|
+
}
|
|
34
44
|
}
|
|
35
|
-
|
|
36
|
-
exports.HttpRequestError = HttpRequestError;
|
|
37
|
-
/**
|
|
38
|
-
* HTTP implementation of the REST transport interface.
|
|
39
|
-
*/
|
|
40
|
-
class HttpTransport {
|
|
45
|
+
exports.HttpRequestError = HttpRequestError;
|
|
41
46
|
/**
|
|
42
|
-
*
|
|
43
|
-
* @param options - Configuration options for the HTTP transport layer.
|
|
47
|
+
* HTTP implementation of the REST transport interface.
|
|
44
48
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
49
|
+
class HttpTransport {
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new HTTP transport instance.
|
|
52
|
+
* @param options - Configuration options for the HTTP transport layer.
|
|
53
|
+
*/
|
|
54
|
+
constructor(options) {
|
|
55
|
+
Object.defineProperty(this, "url", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true,
|
|
58
|
+
writable: true,
|
|
59
|
+
value: void 0
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(this, "timeout", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
configurable: true,
|
|
64
|
+
writable: true,
|
|
65
|
+
value: void 0
|
|
66
|
+
});
|
|
67
|
+
Object.defineProperty(this, "fetchOptions", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
configurable: true,
|
|
70
|
+
writable: true,
|
|
71
|
+
value: void 0
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(this, "onRequest", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
configurable: true,
|
|
76
|
+
writable: true,
|
|
77
|
+
value: void 0
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(this, "onResponse", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
configurable: true,
|
|
82
|
+
writable: true,
|
|
83
|
+
value: void 0
|
|
84
|
+
});
|
|
85
|
+
/** Mapping of endpoint types to their API paths. */
|
|
86
|
+
Object.defineProperty(this, "_endpointPaths", {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
configurable: true,
|
|
89
|
+
writable: true,
|
|
90
|
+
value: {
|
|
91
|
+
info: "/info",
|
|
92
|
+
action: "/exchange",
|
|
93
|
+
explorer: "/explorer",
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
this.url = options?.url ?? "https://api.hyperliquid.xyz";
|
|
97
|
+
this.timeout = options?.timeout === undefined ? 10_000 : options.timeout;
|
|
98
|
+
this.fetchOptions = options?.fetchOptions ?? {};
|
|
99
|
+
this.onRequest = options?.onRequest;
|
|
100
|
+
this.onResponse = options?.onResponse;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Sends a request to the Hyperliquid API via fetch.
|
|
104
|
+
* @param endpoint - The API endpoint to send the request to.
|
|
105
|
+
* @param payload - The payload to send with the request.
|
|
106
|
+
* @param signal - An optional abort signal.
|
|
107
|
+
* @returns A promise that resolves with parsed JSON response body.
|
|
108
|
+
* @throws {HttpRequestError} - Thrown when an HTTP response is deemed invalid.
|
|
109
|
+
* @throws May throw {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch#exceptions | fetch errors}.
|
|
110
|
+
*/
|
|
111
|
+
async request(endpoint, payload, signal) {
|
|
112
|
+
// Construct a Request
|
|
113
|
+
const url = new URL(this._endpointPaths[endpoint], this.url);
|
|
114
|
+
const init = mergeRequestInit({
|
|
115
|
+
body: JSON.stringify(payload),
|
|
116
|
+
headers: {
|
|
117
|
+
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
118
|
+
"Connection": "keep-alive",
|
|
119
|
+
"Content-Type": "application/json",
|
|
120
|
+
},
|
|
121
|
+
keepalive: true,
|
|
122
|
+
method: "POST",
|
|
123
|
+
signal: this.timeout ? AbortSignal.timeout(this.timeout) : undefined,
|
|
124
|
+
}, this.fetchOptions, { signal });
|
|
125
|
+
let request = new Request(url, init);
|
|
126
|
+
// Call the onRequest callback, if provided
|
|
127
|
+
if (this.onRequest) {
|
|
128
|
+
const customRequest = await this.onRequest(request);
|
|
129
|
+
if (customRequest instanceof Request)
|
|
130
|
+
request = customRequest;
|
|
85
131
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
132
|
+
// Send the Request and wait for a Response
|
|
133
|
+
let response = await fetch(request);
|
|
134
|
+
// Call the onResponse callback, if provided
|
|
135
|
+
if (this.onResponse) {
|
|
136
|
+
const customResponse = await this.onResponse(response);
|
|
137
|
+
if (customResponse instanceof Response)
|
|
138
|
+
response = customResponse;
|
|
139
|
+
}
|
|
140
|
+
// Validate the Response
|
|
141
|
+
if (!response.ok || !response.headers.get("Content-Type")?.includes("application/json")) {
|
|
142
|
+
// Unload the response body to prevent memory leaks
|
|
143
|
+
const body = await response.text().catch(() => undefined);
|
|
144
|
+
throw new HttpRequestError(response, body);
|
|
145
|
+
}
|
|
146
|
+
// Parse and return the response body
|
|
147
|
+
return await response.json();
|
|
148
|
+
}
|
|
92
149
|
}
|
|
150
|
+
exports.HttpTransport = HttpTransport;
|
|
93
151
|
/**
|
|
94
|
-
*
|
|
95
|
-
* @param
|
|
96
|
-
* @
|
|
97
|
-
* @param signal - An optional abort signal.
|
|
98
|
-
* @returns A promise that resolves with parsed JSON response body.
|
|
99
|
-
* @throws {HttpRequestError} - Thrown when an HTTP response is deemed invalid.
|
|
100
|
-
* @throws May throw {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch#exceptions | fetch errors}.
|
|
152
|
+
* Merges multiple `HeadersInit` objects into one.
|
|
153
|
+
* @param inits - A list of `HeadersInit` objects to merge.
|
|
154
|
+
* @returns A new `Headers` object that contains all headers from the input objects.
|
|
101
155
|
*/
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const init = mergeRequestInit({
|
|
106
|
-
body: JSON.stringify(payload),
|
|
107
|
-
headers: {
|
|
108
|
-
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
109
|
-
"Connection": "keep-alive",
|
|
110
|
-
"Content-Type": "application/json",
|
|
111
|
-
},
|
|
112
|
-
keepalive: true,
|
|
113
|
-
method: "POST",
|
|
114
|
-
signal: this.timeout ? AbortSignal.timeout(this.timeout) : undefined,
|
|
115
|
-
}, this.fetchOptions, { signal });
|
|
116
|
-
let request = new Request(url, init);
|
|
117
|
-
// Call the onRequest callback, if provided
|
|
118
|
-
if (this.onRequest) {
|
|
119
|
-
const customRequest = await this.onRequest(request);
|
|
120
|
-
if (customRequest instanceof Request)
|
|
121
|
-
request = customRequest;
|
|
122
|
-
}
|
|
123
|
-
// Send the Request and wait for a Response
|
|
124
|
-
let response = await fetch(request);
|
|
125
|
-
// Call the onResponse callback, if provided
|
|
126
|
-
if (this.onResponse) {
|
|
127
|
-
const customResponse = await this.onResponse(response);
|
|
128
|
-
if (customResponse instanceof Response)
|
|
129
|
-
response = customResponse;
|
|
156
|
+
function mergeHeadersInit(...inits) {
|
|
157
|
+
if (inits.length === 0 || inits.length === 1) {
|
|
158
|
+
return new Headers(inits[0]);
|
|
130
159
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
160
|
+
const merged = new Headers();
|
|
161
|
+
for (const headers of inits) {
|
|
162
|
+
const entries = Symbol.iterator in headers ? headers : Object.entries(headers);
|
|
163
|
+
for (const [key, value] of entries) {
|
|
164
|
+
merged.set(key, value);
|
|
165
|
+
}
|
|
136
166
|
}
|
|
137
|
-
|
|
138
|
-
return await response.json();
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
exports.HttpTransport = HttpTransport;
|
|
142
|
-
/**
|
|
143
|
-
* Merges multiple `HeadersInit` objects into one.
|
|
144
|
-
* @param inits - A list of `HeadersInit` objects to merge.
|
|
145
|
-
* @returns A new `Headers` object that contains all headers from the input objects.
|
|
146
|
-
*/
|
|
147
|
-
function mergeHeadersInit(...inits) {
|
|
148
|
-
if (inits.length === 0 || inits.length === 1) {
|
|
149
|
-
return new Headers(inits[0]);
|
|
167
|
+
return merged;
|
|
150
168
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Merges multiple `RequestInit` objects into one.
|
|
171
|
+
* @param inits - A list of `RequestInit` objects to merge.
|
|
172
|
+
* @returns A new `RequestInit` object that contains all properties from the input objects.
|
|
173
|
+
*/
|
|
174
|
+
function mergeRequestInit(...inits) {
|
|
175
|
+
const merged = inits.reduce((acc, init) => ({ ...acc, ...init }), {});
|
|
176
|
+
const headersList = inits.map((init) => init.headers)
|
|
177
|
+
.filter((headers) => typeof headers === "object");
|
|
178
|
+
if (headersList.length > 0) {
|
|
179
|
+
merged.headers = mergeHeadersInit(...headersList);
|
|
156
180
|
}
|
|
181
|
+
const signals = inits.map((init) => init.signal)
|
|
182
|
+
.filter((signal) => signal instanceof AbortSignal);
|
|
183
|
+
if (signals.length > 0) {
|
|
184
|
+
merged.signal = signals.length > 1 ? AbortSignal.any(signals) : signals[0];
|
|
185
|
+
}
|
|
186
|
+
return merged;
|
|
157
187
|
}
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Merges multiple `RequestInit` objects into one.
|
|
162
|
-
* @param inits - A list of `RequestInit` objects to merge.
|
|
163
|
-
* @returns A new `RequestInit` object that contains all properties from the input objects.
|
|
164
|
-
*/
|
|
165
|
-
function mergeRequestInit(...inits) {
|
|
166
|
-
const merged = inits.reduce((acc, init) => ({ ...acc, ...init }), {});
|
|
167
|
-
const headersList = inits.map((init) => init.headers)
|
|
168
|
-
.filter((headers) => typeof headers === "object");
|
|
169
|
-
if (headersList.length > 0) {
|
|
170
|
-
merged.headers = mergeHeadersInit(...headersList);
|
|
171
|
-
}
|
|
172
|
-
const signals = inits.map((init) => init.signal)
|
|
173
|
-
.filter((signal) => signal instanceof AbortSignal);
|
|
174
|
-
if (signals.length > 0) {
|
|
175
|
-
merged.signal = signals.length > 1 ? AbortSignal.any(signals) : signals[0];
|
|
176
|
-
}
|
|
177
|
-
return merged;
|
|
178
|
-
}
|
|
188
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { TypedEventTarget } from "../../../deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js";
|
|
2
|
+
import type { BlockDetails, TxDetails } from "../../types/explorer/responses.js";
|
|
3
|
+
/** Base system events and dynamic channel events for Hyperliquid WebSocket API. */
|
|
4
|
+
interface HyperliquidEventMap {
|
|
5
|
+
/** Subscription created/removed event. */
|
|
6
|
+
subscriptionResponse: CustomEvent<{
|
|
7
|
+
/** Type of subscription operation. */
|
|
8
|
+
method: "subscribe" | "unsubscribe";
|
|
9
|
+
/** Original subscription request. */
|
|
10
|
+
subscription: unknown;
|
|
11
|
+
}>;
|
|
12
|
+
/** Response to post request event. */
|
|
13
|
+
post: CustomEvent<{
|
|
14
|
+
/** Unique request identifier. */
|
|
15
|
+
id: number;
|
|
16
|
+
/** Server response. */
|
|
17
|
+
response:
|
|
18
|
+
/** Response containing requested information. */
|
|
19
|
+
{
|
|
20
|
+
/** Indicates that this is an informational response. */
|
|
21
|
+
type: "info";
|
|
22
|
+
/** Contains the information data. */
|
|
23
|
+
payload: {
|
|
24
|
+
/** Type of information being returned. */
|
|
25
|
+
type: string;
|
|
26
|
+
/** Information specific data. */
|
|
27
|
+
data: unknown;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Response containing action result. */
|
|
31
|
+
| {
|
|
32
|
+
/** Indicates that this is an action response. */
|
|
33
|
+
type: "action";
|
|
34
|
+
/** Contains the action result data. */
|
|
35
|
+
payload: {
|
|
36
|
+
/** Response status indicating success or failure of the action. */
|
|
37
|
+
status: "ok" | "err";
|
|
38
|
+
/** Success data or error message. */
|
|
39
|
+
response: {
|
|
40
|
+
/** Type of operation. */
|
|
41
|
+
type: string;
|
|
42
|
+
/** Specific data for the operation. */
|
|
43
|
+
data?: unknown;
|
|
44
|
+
} | string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
}>;
|
|
48
|
+
/** Error response for message event. */
|
|
49
|
+
error: CustomEvent<string>;
|
|
50
|
+
/** Pong response event. */
|
|
51
|
+
pong: CustomEvent<undefined>;
|
|
52
|
+
/** Block explorer update event. */
|
|
53
|
+
_explorerBlock: CustomEvent<Omit<BlockDetails, "txs">[]>;
|
|
54
|
+
/** Transaction explorer update event. */
|
|
55
|
+
_explorerTxs: CustomEvent<TxDetails[]>;
|
|
56
|
+
/** Subscribed channel event. */
|
|
57
|
+
[key: string]: CustomEvent<unknown>;
|
|
58
|
+
}
|
|
59
|
+
/** Listens for WebSocket messages and sends them as Hyperliquid typed events. */
|
|
60
|
+
export declare class HyperliquidEventTarget extends TypedEventTarget<HyperliquidEventMap> {
|
|
61
|
+
constructor(socket: WebSocket);
|
|
62
|
+
}
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=_hyperliquid_event_target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_hyperliquid_event_target.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/_hyperliquid_event_target.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oEAAoE,CAAC;AACtG,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAUjF,mFAAmF;AACnF,UAAU,mBAAmB;IACzB,0CAA0C;IAC1C,oBAAoB,EAAE,WAAW,CAAC;QAC9B,sCAAsC;QACtC,MAAM,EAAE,WAAW,GAAG,aAAa,CAAC;QACpC,qCAAqC;QACrC,YAAY,EAAE,OAAO,CAAC;KACzB,CAAC,CAAC;IAEH,sCA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ports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "../../../deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HyperliquidEventTarget = void 0;
|
|
13
|
+
const mod_js_1 = require("../../../deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js");
|
|
14
|
+
/** Listens for WebSocket messages and sends them as Hyperliquid typed events. */
|
|
15
|
+
class HyperliquidEventTarget extends mod_js_1.TypedEventTarget {
|
|
16
|
+
constructor(socket) {
|
|
17
|
+
super();
|
|
18
|
+
socket.addEventListener("message", (event) => {
|
|
19
|
+
try {
|
|
20
|
+
const msg = JSON.parse(event.data);
|
|
21
|
+
if (isHyperliquidMsg(msg)) {
|
|
22
|
+
this.dispatchEvent(new CustomEvent(msg.channel, { detail: msg.data }));
|
|
23
|
+
}
|
|
24
|
+
else if (isExplorerBlockMsg(msg)) {
|
|
25
|
+
this.dispatchEvent(new CustomEvent("_explorerBlock", { detail: msg }));
|
|
26
|
+
}
|
|
27
|
+
else if (isExplorerTxsMsg(msg)) {
|
|
28
|
+
this.dispatchEvent(new CustomEvent("_explorerTxs", { detail: msg }));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// Ignore JSON parsing errors
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.HyperliquidEventTarget = HyperliquidEventTarget;
|
|
38
|
+
/** Type guard for Hyperliquid messages. */
|
|
39
|
+
function isHyperliquidMsg(value) {
|
|
40
|
+
return typeof value === "object" && value !== null &&
|
|
41
|
+
"channel" in value && typeof value.channel === "string";
|
|
42
|
+
}
|
|
43
|
+
/** Type guard for explorer block messages. */
|
|
44
|
+
function isExplorerBlockMsg(value) {
|
|
45
|
+
return Array.isArray(value) && value.length > 0 &&
|
|
46
|
+
value.every((block) => typeof block === "object" && block !== null && !Array.isArray(block) &&
|
|
47
|
+
"height" in block && typeof block.height === "number" &&
|
|
48
|
+
"blockTime" in block && typeof block.blockTime === "number" &&
|
|
49
|
+
"hash" in block && typeof block.hash === "string" &&
|
|
50
|
+
"proposer" in block && typeof block.proposer === "string" &&
|
|
51
|
+
"numTxs" in block && typeof block.numTxs === "number");
|
|
52
|
+
}
|
|
53
|
+
/** Type guard for explorer transactions messages. */
|
|
54
|
+
function isExplorerTxsMsg(value) {
|
|
55
|
+
return Array.isArray(value) && value.length > 0 &&
|
|
56
|
+
value.every((tx) => {
|
|
57
|
+
return typeof tx === "object" && tx !== null && !Array.isArray(tx) &&
|
|
58
|
+
"action" in tx && typeof tx.action === "object" && tx.action !== null &&
|
|
59
|
+
"block" in tx && typeof tx.block === "number" &&
|
|
60
|
+
"error" in tx && (typeof tx.error === "string" || tx.error === null) &&
|
|
61
|
+
"hash" in tx && typeof tx.hash === "string" &&
|
|
62
|
+
"time" in tx && typeof tx.time === "number" &&
|
|
63
|
+
"user" in tx && typeof tx.user === "string";
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
package/script/src/transports/websocket/{reconnecting_websocket.d.ts → _reconnecting_websocket.d.ts}
RENAMED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { TransportError } from "../../base.js";
|
|
1
2
|
type MaybePromise<T> = T | Promise<T>;
|
|
2
|
-
/**
|
|
3
|
-
* Configuration options for the `ReconnectingWebSocket`.
|
|
4
|
-
*/
|
|
3
|
+
/** Configuration options for the `ReconnectingWebSocket`. */
|
|
5
4
|
export interface ReconnectingWebSocketOptions {
|
|
6
5
|
/**
|
|
7
6
|
* Maximum number of reconnection attempts.
|
|
@@ -33,15 +32,8 @@ export interface ReconnectingWebSocketOptions {
|
|
|
33
32
|
* @defaultValue `new FIFOMessageBuffer()`
|
|
34
33
|
*/
|
|
35
34
|
messageBuffer?: MessageBufferStrategy;
|
|
36
|
-
/**
|
|
37
|
-
* Custom WebSocket constructor to use.
|
|
38
|
-
* @defaultValue `new WebSocket(url, protocols)`
|
|
39
|
-
*/
|
|
40
|
-
WebSocketConstructor?: typeof WebSocket;
|
|
41
35
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Message buffer strategy interface.
|
|
44
|
-
*/
|
|
36
|
+
/** Message buffer strategy interface. */
|
|
45
37
|
export interface MessageBufferStrategy {
|
|
46
38
|
/** Array of buffered messages. */
|
|
47
39
|
messages: (string | ArrayBufferLike | Blob | ArrayBufferView)[];
|
|
@@ -58,21 +50,27 @@ export interface MessageBufferStrategy {
|
|
|
58
50
|
/** Clear all buffered messages. */
|
|
59
51
|
clear(): void;
|
|
60
52
|
}
|
|
53
|
+
/** Error thrown when reconnection problems occur. */
|
|
54
|
+
export declare class ReconnectingWebSocketError extends TransportError {
|
|
55
|
+
code: "RECONNECTION_LIMIT_REACHED" | "RECONNECTION_STOPPED_BY_USER" | "USER_INITIATED_CLOSE" | "UNKNOWN_ERROR";
|
|
56
|
+
originalError?: unknown | undefined;
|
|
57
|
+
constructor(code: "RECONNECTION_LIMIT_REACHED" | "RECONNECTION_STOPPED_BY_USER" | "USER_INITIATED_CLOSE" | "UNKNOWN_ERROR", originalError?: unknown | undefined);
|
|
58
|
+
}
|
|
61
59
|
/**
|
|
62
60
|
* A WebSocket that automatically reconnects when disconnected.
|
|
63
61
|
* Fully compatible with standard WebSocket API.
|
|
64
62
|
*/
|
|
65
63
|
export declare class ReconnectingWebSocket implements WebSocket {
|
|
66
64
|
/** Controller for handling connection termination */
|
|
67
|
-
protected
|
|
65
|
+
protected _terminationController: AbortController;
|
|
68
66
|
/** WebSocket protocols */
|
|
69
|
-
protected
|
|
67
|
+
protected _protocols?: string | string[];
|
|
70
68
|
/** The underlying WebSocket instance */
|
|
71
|
-
protected
|
|
69
|
+
protected _socket: WebSocket;
|
|
72
70
|
/** Current number of reconnection attempts */
|
|
73
|
-
protected
|
|
71
|
+
protected _reconnectCount: number;
|
|
74
72
|
/** Array of registered event listeners */
|
|
75
|
-
protected
|
|
73
|
+
protected _eventListeners: {
|
|
76
74
|
type: string;
|
|
77
75
|
listener: EventListenerOrEventListenerObject;
|
|
78
76
|
options?: boolean | AddEventListenerOptions;
|
|
@@ -96,23 +94,21 @@ export declare class ReconnectingWebSocket implements WebSocket {
|
|
|
96
94
|
* @param timeout - The connection timeout in ms.
|
|
97
95
|
* @returns A new WebSocket instance.
|
|
98
96
|
*/
|
|
99
|
-
protected
|
|
100
|
-
/**
|
|
101
|
-
|
|
102
|
-
*/
|
|
103
|
-
protected initEventListeners(): void;
|
|
97
|
+
protected _connectWithTimeout(url: string | URL, protocols: string | string[] | undefined, timeout: number): WebSocket;
|
|
98
|
+
/** Initializes the internal event listeners for the WebSocket. */
|
|
99
|
+
protected _initEventListeners(): void;
|
|
104
100
|
/**
|
|
105
101
|
* Clean up internal resources.
|
|
106
102
|
* @param reason - The reason for cleanup.
|
|
107
103
|
*/
|
|
108
|
-
protected
|
|
104
|
+
protected _cleanup(reason: unknown): void;
|
|
109
105
|
/**
|
|
110
106
|
* Check if two event listeners are the same (just like EventTarget).
|
|
111
107
|
* @param a - First event listener configuration.
|
|
112
108
|
* @param b - Second event listener configuration.
|
|
113
109
|
* @returns True if the listeners match.
|
|
114
110
|
*/
|
|
115
|
-
protected
|
|
111
|
+
protected _isListenerMatch(a: {
|
|
116
112
|
type: string;
|
|
117
113
|
listener: EventListenerOrEventListenerObject;
|
|
118
114
|
options?: boolean | AddEventListenerOptions;
|
|
@@ -152,9 +148,13 @@ export declare class ReconnectingWebSocket implements WebSocket {
|
|
|
152
148
|
* @note If the connection is not open, the data will be buffered and sent when the connection is established.
|
|
153
149
|
*/
|
|
154
150
|
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
|
|
155
|
-
addEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: ReconnectingWebSocket, ev: WebSocketEventMap[K]) => any
|
|
156
|
-
|
|
151
|
+
addEventListener<K extends keyof WebSocketEventMap>(type: K, listener: ((this: ReconnectingWebSocket, ev: WebSocketEventMap[K]) => any) | {
|
|
152
|
+
handleEvent: (event: WebSocketEventMap[K]) => any;
|
|
153
|
+
}, options?: boolean | AddEventListenerOptions): void;
|
|
154
|
+
removeEventListener<K extends keyof WebSocketEventMap>(type: K, listener: ((this: ReconnectingWebSocket, ev: WebSocketEventMap[K]) => any) | {
|
|
155
|
+
handleEvent: (event: WebSocketEventMap[K]) => any;
|
|
156
|
+
}, options?: boolean | EventListenerOptions): void;
|
|
157
157
|
dispatchEvent(event: Event): boolean;
|
|
158
158
|
}
|
|
159
159
|
export {};
|
|
160
|
-
//# sourceMappingURL=
|
|
160
|
+
//# sourceMappingURL=_reconnecting_websocket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_reconnecting_websocket.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/_reconnecting_websocket.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEtC,6DAA6D;AAC7D,MAAM,WAAW,4BAA4B;IACzC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAElC;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;IAEvE;;;;;OAKG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,YAAY,CAAC,OAAO,CAAC,CAAC;IAE/D;;;OA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