@nktkas/hyperliquid 0.19.2 → 0.20.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/README.md +21 -29
- package/esm/_dnt.polyfills.d.ts +20 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +12 -0
- package/esm/mod.d.ts +3 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +2 -0
- package/esm/src/base.d.ts +1 -47
- package/esm/src/base.d.ts.map +1 -1
- package/esm/src/base.js +1 -8
- package/esm/src/clients/event.d.ts +2 -3
- package/esm/src/clients/event.d.ts.map +1 -1
- package/esm/src/clients/event.js +49 -57
- package/esm/src/clients/public.d.ts +24 -5
- package/esm/src/clients/public.d.ts.map +1 -1
- package/esm/src/clients/public.js +23 -7
- package/esm/src/clients/wallet.d.ts +12 -13
- package/esm/src/clients/wallet.d.ts.map +1 -1
- package/esm/src/clients/wallet.js +55 -265
- package/esm/src/signing.d.ts +5 -0
- package/esm/src/signing.d.ts.map +1 -1
- package/esm/src/signing.js +24 -5
- package/esm/src/transports/base.d.ts +49 -0
- package/esm/src/transports/base.d.ts.map +1 -0
- package/esm/src/transports/base.js +8 -0
- package/esm/src/transports/http/http_transport.d.ts +8 -5
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +15 -62
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +36 -39
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts +18 -25
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.js +80 -179
- package/{script/src/transports/websocket/_websocket_request_dispatcher.d.ts → esm/src/transports/websocket/_websocket_async_request.d.ts} +14 -18
- package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -0
- package/esm/src/transports/websocket/{_websocket_request_dispatcher.js → _websocket_async_request.js} +41 -74
- package/esm/src/transports/websocket/websocket_transport.d.ts +38 -28
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +61 -76
- package/esm/src/types/info/assets.d.ts +0 -48
- package/esm/src/types/info/assets.d.ts.map +1 -1
- package/esm/src/types/info/markets.d.ts +52 -0
- package/esm/src/types/info/markets.d.ts.map +1 -0
- package/esm/src/types/info/markets.js +1 -0
- package/esm/src/types/info/requests.d.ts +9 -0
- package/esm/src/types/info/requests.d.ts.map +1 -1
- package/esm/src/types/mod.d.ts +4 -0
- package/esm/src/types/mod.d.ts.map +1 -1
- package/esm/src/types/mod.js +3 -1
- package/package.json +12 -9
- package/script/_dnt.polyfills.d.ts +20 -0
- package/script/_dnt.polyfills.d.ts.map +1 -0
- package/script/_dnt.polyfills.js +23 -0
- package/script/mod.d.ts +3 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +3 -1
- package/script/src/base.d.ts +1 -47
- package/script/src/base.d.ts.map +1 -1
- package/script/src/base.js +2 -10
- package/script/src/clients/event.d.ts +2 -3
- package/script/src/clients/event.d.ts.map +1 -1
- package/script/src/clients/event.js +49 -57
- package/script/src/clients/public.d.ts +24 -5
- package/script/src/clients/public.d.ts.map +1 -1
- package/script/src/clients/public.js +23 -7
- package/script/src/clients/wallet.d.ts +12 -13
- package/script/src/clients/wallet.d.ts.map +1 -1
- package/script/src/clients/wallet.js +55 -265
- package/script/src/signing.d.ts +5 -0
- package/script/src/signing.d.ts.map +1 -1
- package/script/src/signing.js +75 -56
- package/script/src/transports/base.d.ts +49 -0
- package/script/src/transports/base.d.ts.map +1 -0
- package/script/src/transports/base.js +22 -0
- package/script/src/transports/http/http_transport.d.ts +8 -5
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +16 -63
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +36 -39
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts +18 -25
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.js +81 -180
- package/{esm/src/transports/websocket/_websocket_request_dispatcher.d.ts → script/src/transports/websocket/_websocket_async_request.d.ts} +14 -18
- package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -0
- package/script/src/transports/websocket/{_websocket_request_dispatcher.js → _websocket_async_request.js} +44 -77
- package/script/src/transports/websocket/websocket_transport.d.ts +38 -28
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +63 -78
- package/script/src/types/info/assets.d.ts +0 -48
- package/script/src/types/info/assets.d.ts.map +1 -1
- package/script/src/types/info/markets.d.ts +52 -0
- package/script/src/types/info/markets.d.ts.map +1 -0
- package/script/{deps/jsr.io/@noble/hashes/1.8.0/src/crypto.js → src/types/info/markets.js} +0 -2
- package/script/src/types/info/requests.d.ts +9 -0
- package/script/src/types/info/requests.d.ts.map +1 -1
- package/script/src/types/mod.d.ts +4 -0
- package/script/src/types/mod.d.ts.map +1 -1
- package/script/src/types/mod.js +25 -22
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts +0 -55
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts.map +0 -1
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.js +0 -66
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.d.ts +0 -2
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.d.ts.map +0 -1
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.js +0 -1
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts +0 -53
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts.map +0 -1
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.js +0 -294
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts +0 -161
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts.map +0 -1
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/utils.js +0 -280
- package/esm/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +0 -1
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts +0 -55
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts.map +0 -1
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.js +0 -99
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.d.ts +0 -2
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.d.ts.map +0 -1
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts +0 -53
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts.map +0 -1
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.js +0 -309
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts +0 -161
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts.map +0 -1
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/utils.js +0 -322
- package/script/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +0 -1
package/script/src/signing.js
CHANGED
|
@@ -1,59 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This module contains functions for generating Hyperliquid transaction signatures
|
|
3
|
-
* and interfaces to various wallet implementations.
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* import { signL1Action } from "@nktkas/hyperliquid/signing";
|
|
7
|
-
*
|
|
8
|
-
* const action = {
|
|
9
|
-
* type: "cancel",
|
|
10
|
-
* cancels: [{ a: 0, o: 12345 }],
|
|
11
|
-
* };
|
|
12
|
-
* const nonce = Date.now();
|
|
13
|
-
*
|
|
14
|
-
* const signature = await signL1Action({
|
|
15
|
-
* wallet,
|
|
16
|
-
* action,
|
|
17
|
-
* nonce,
|
|
18
|
-
* isTestnet: true, // Change to false for mainnet
|
|
19
|
-
* });
|
|
20
|
-
* ```
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* import { signUserSignedAction } from "@nktkas/hyperliquid/signing";
|
|
24
|
-
*
|
|
25
|
-
* const action = {
|
|
26
|
-
* type: "approveAgent",
|
|
27
|
-
* hyperliquidChain: "Testnet", // "Mainnet" or "Testnet"
|
|
28
|
-
* signatureChainId: "0x66eee",
|
|
29
|
-
* nonce: Date.now(),
|
|
30
|
-
* agentAddress: "0x...",
|
|
31
|
-
* agentName: "Agent",
|
|
32
|
-
* };
|
|
33
|
-
*
|
|
34
|
-
* const signature = await signUserSignedAction({
|
|
35
|
-
* wallet,
|
|
36
|
-
* action,
|
|
37
|
-
* types: {
|
|
38
|
-
* "HyperliquidTransaction:ApproveAgent": [
|
|
39
|
-
* { name: "hyperliquidChain", type: "string" },
|
|
40
|
-
* { name: "agentAddress", type: "address" },
|
|
41
|
-
* { name: "agentName", type: "string" },
|
|
42
|
-
* { name: "nonce", type: "uint64" },
|
|
43
|
-
* ],
|
|
44
|
-
* },
|
|
45
|
-
* chainId: parseInt(action.signatureChainId, 16),
|
|
46
|
-
* });
|
|
47
|
-
* ```
|
|
48
|
-
* @module
|
|
49
|
-
*/
|
|
50
1
|
(function (factory) {
|
|
51
2
|
if (typeof module === "object" && typeof module.exports === "object") {
|
|
52
3
|
var v = factory(require, exports);
|
|
53
4
|
if (v !== undefined) module.exports = v;
|
|
54
5
|
}
|
|
55
6
|
else if (typeof define === "function" && define.amd) {
|
|
56
|
-
define(["require", "exports", "../
|
|
7
|
+
define(["require", "exports", "../_dnt.polyfills.js", "@noble/hashes/sha3", "../deps/jsr.io/@std/msgpack/1.0.3/encode.js", "../deps/jsr.io/@std/encoding/1.0.10/hex.js", "../deps/jsr.io/@std/bytes/1.0.6/concat.js"], factory);
|
|
57
8
|
}
|
|
58
9
|
})(function (require, exports) {
|
|
59
10
|
"use strict";
|
|
@@ -67,7 +18,59 @@
|
|
|
67
18
|
exports.isAbstractEthersV5Signer = isAbstractEthersV5Signer;
|
|
68
19
|
exports.isAbstractExtendedViemWalletClient = isAbstractExtendedViemWalletClient;
|
|
69
20
|
exports.isAbstractWindowEthereum = isAbstractWindowEthereum;
|
|
70
|
-
|
|
21
|
+
/**
|
|
22
|
+
* This module contains functions for generating Hyperliquid transaction signatures
|
|
23
|
+
* and interfaces to various wallet implementations.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { signL1Action } from "@nktkas/hyperliquid/signing";
|
|
28
|
+
*
|
|
29
|
+
* const action = {
|
|
30
|
+
* type: "cancel",
|
|
31
|
+
* cancels: [{ a: 0, o: 12345 }],
|
|
32
|
+
* };
|
|
33
|
+
* const nonce = Date.now();
|
|
34
|
+
*
|
|
35
|
+
* const signature = await signL1Action({
|
|
36
|
+
* wallet,
|
|
37
|
+
* action,
|
|
38
|
+
* nonce,
|
|
39
|
+
* isTestnet: true, // Change to false for mainnet
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { signUserSignedAction } from "@nktkas/hyperliquid/signing";
|
|
45
|
+
*
|
|
46
|
+
* const action = {
|
|
47
|
+
* type: "approveAgent",
|
|
48
|
+
* hyperliquidChain: "Testnet", // "Mainnet" or "Testnet"
|
|
49
|
+
* signatureChainId: "0x66eee",
|
|
50
|
+
* nonce: Date.now(),
|
|
51
|
+
* agentAddress: "0x...",
|
|
52
|
+
* agentName: "Agent",
|
|
53
|
+
* };
|
|
54
|
+
*
|
|
55
|
+
* const signature = await signUserSignedAction({
|
|
56
|
+
* wallet,
|
|
57
|
+
* action,
|
|
58
|
+
* types: {
|
|
59
|
+
* "HyperliquidTransaction:ApproveAgent": [
|
|
60
|
+
* { name: "hyperliquidChain", type: "string" },
|
|
61
|
+
* { name: "agentAddress", type: "address" },
|
|
62
|
+
* { name: "agentName", type: "string" },
|
|
63
|
+
* { name: "nonce", type: "uint64" },
|
|
64
|
+
* ],
|
|
65
|
+
* },
|
|
66
|
+
* chainId: parseInt(action.signatureChainId, 16),
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @module
|
|
71
|
+
*/
|
|
72
|
+
require("../_dnt.polyfills.js");
|
|
73
|
+
const sha3_1 = require("@noble/hashes/sha3");
|
|
71
74
|
const encode_js_1 = require("../deps/jsr.io/@std/msgpack/1.0.3/encode.js");
|
|
72
75
|
const hex_js_1 = require("../deps/jsr.io/@std/encoding/1.0.10/hex.js");
|
|
73
76
|
const concat_js_1 = require("../deps/jsr.io/@std/bytes/1.0.6/concat.js");
|
|
@@ -88,14 +91,28 @@
|
|
|
88
91
|
const nonceBytes = new Uint8Array(8);
|
|
89
92
|
new DataView(nonceBytes.buffer).setBigUint64(0, BigInt(nonce));
|
|
90
93
|
// 3. Vault address
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
let vaultMarker;
|
|
95
|
+
let vaultBytes;
|
|
96
|
+
if (vaultAddress) {
|
|
97
|
+
vaultMarker = Uint8Array.of(1);
|
|
98
|
+
vaultBytes = (0, hex_js_1.decodeHex)(vaultAddress.slice(2));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
vaultMarker = new Uint8Array(1);
|
|
102
|
+
vaultBytes = new Uint8Array();
|
|
103
|
+
}
|
|
93
104
|
// 4. Expires after
|
|
94
|
-
|
|
95
|
-
|
|
105
|
+
let expiresMarker;
|
|
106
|
+
let expiresBytes;
|
|
96
107
|
if (expiresAfter !== undefined) {
|
|
108
|
+
expiresMarker = new Uint8Array(1);
|
|
109
|
+
expiresBytes = new Uint8Array(8);
|
|
97
110
|
new DataView(expiresBytes.buffer).setBigUint64(0, BigInt(expiresAfter));
|
|
98
111
|
}
|
|
112
|
+
else {
|
|
113
|
+
expiresMarker = new Uint8Array();
|
|
114
|
+
expiresBytes = new Uint8Array();
|
|
115
|
+
}
|
|
99
116
|
// Create a keccak256 hash
|
|
100
117
|
const chunks = [
|
|
101
118
|
actionBytes,
|
|
@@ -106,7 +123,7 @@
|
|
|
106
123
|
expiresBytes,
|
|
107
124
|
];
|
|
108
125
|
const bytes = (0, concat_js_1.concat)(chunks);
|
|
109
|
-
const hash = (0,
|
|
126
|
+
const hash = (0, sha3_1.keccak_256)(bytes);
|
|
110
127
|
return `0x${(0, hex_js_1.encodeHex)(hash)}`;
|
|
111
128
|
}
|
|
112
129
|
/** Layer to make {@link https://jsr.io/@std/msgpack | @std/msgpack} compatible with {@link https://github.com/msgpack/msgpack-javascript | @msgpack/msgpack}. */
|
|
@@ -188,6 +205,7 @@
|
|
|
188
205
|
* Sign a user-signed action.
|
|
189
206
|
*
|
|
190
207
|
* Note: Signature generation depends on the order of types.
|
|
208
|
+
*
|
|
191
209
|
* @param args - Arguments for signing the action.
|
|
192
210
|
* @returns The signature components r, s, and v.
|
|
193
211
|
* @example
|
|
@@ -243,6 +261,7 @@
|
|
|
243
261
|
* Sign a multi-signature action.
|
|
244
262
|
*
|
|
245
263
|
* Note: Signature generation depends on the order of the action keys.
|
|
264
|
+
*
|
|
246
265
|
* @param args - Arguments for signing the action.
|
|
247
266
|
* @returns The signature components r, s, and v.
|
|
248
267
|
* @example
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { HyperliquidError } from "../base.js";
|
|
2
|
+
/**
|
|
3
|
+
* Interface representing a REST transport.
|
|
4
|
+
*
|
|
5
|
+
* Handles communication with Hyperliquid API endpoints.
|
|
6
|
+
*
|
|
7
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint | Info endpoint}
|
|
8
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint | Exchange endpoint}
|
|
9
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/post-requests | Websocket post requests}
|
|
10
|
+
*/
|
|
11
|
+
export interface IRequestTransport extends Partial<AsyncDisposable> {
|
|
12
|
+
/**
|
|
13
|
+
* Sends a request to the Hyperliquid API.
|
|
14
|
+
* @param endpoint - The API endpoint to send the request to.
|
|
15
|
+
* @param payload - The payload to send with the request.
|
|
16
|
+
* @param signal - An ptional abort signal.
|
|
17
|
+
* @returns A promise that resolves with parsed JSON response body.
|
|
18
|
+
*/
|
|
19
|
+
request<T>(endpoint: "info" | "exchange" | "explorer", payload: unknown, signal?: AbortSignal): Promise<T>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Interface representing an event subscription transport.
|
|
23
|
+
* Handles WebSocket subscriptions for real-time updates.
|
|
24
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Websocket subscriptions}
|
|
25
|
+
*/
|
|
26
|
+
export interface ISubscriptionTransport extends Partial<AsyncDisposable> {
|
|
27
|
+
/**
|
|
28
|
+
* Subscribes to a Hyperliquid event channel.
|
|
29
|
+
* @param channel - The event channel to listen to.
|
|
30
|
+
* @param payload - The payload to send with the subscription request.
|
|
31
|
+
* @param listener - The function to call when the event is dispatched.
|
|
32
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
33
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
34
|
+
*/
|
|
35
|
+
subscribe<T>(channel: string, payload: unknown, listener: (data: CustomEvent<T>) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
36
|
+
}
|
|
37
|
+
/** Controls event subscription lifecycle. */
|
|
38
|
+
export interface Subscription {
|
|
39
|
+
/**
|
|
40
|
+
* Unsubscribes from the event and sends an unsubscribe request to the server.
|
|
41
|
+
* @param signal - An optional abort signal for canceling the unsubscribe request.
|
|
42
|
+
*/
|
|
43
|
+
unsubscribe(signal?: AbortSignal): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
/** Base class for all transport-related errors. */
|
|
46
|
+
export declare class TransportError extends HyperliquidError {
|
|
47
|
+
constructor(message?: string);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/src/transports/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAkB,SAAQ,OAAO,CAAC,eAAe,CAAC;IAC/D;;;;;;OAMG;IACH,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC9G;AAED;;;;GAIG;AACH,MAAM,WAAW,sBAAuB,SAAQ,OAAO,CAAC,eAAe,CAAC;IACpE;;;;;;;OAOG;IACH,SAAS,CAAC,CAAC,EACP,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,EACxC,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,YAAY,CAAC,CAAC;CAC5B;AAED,6CAA6C;AAC7C,MAAM,WAAW,YAAY;IACzB;;;OAGG;IACH,WAAW,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpD;AAED,mDAAmD;AACnD,qBAAa,cAAe,SAAQ,gBAAgB;gBACpC,OAAO,CAAC,EAAE,MAAM;CAI/B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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.TransportError = void 0;
|
|
13
|
+
const base_js_1 = require("../base.js");
|
|
14
|
+
/** Base class for all transport-related errors. */
|
|
15
|
+
class TransportError extends base_js_1.HyperliquidError {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "TransportError";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.TransportError = TransportError;
|
|
22
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { MaybePromise } from "../../base.js";
|
|
2
|
+
import { type IRequestTransport, TransportError } from "../base.js";
|
|
2
3
|
/**
|
|
3
4
|
* Error thrown when an HTTP response is deemed invalid:
|
|
4
5
|
* - Non-200 status code
|
|
@@ -22,12 +23,14 @@ export interface HttpTransportOptions {
|
|
|
22
23
|
*/
|
|
23
24
|
isTestnet?: boolean;
|
|
24
25
|
/**
|
|
25
|
-
* Request timeout in ms.
|
|
26
|
-
* Set to `null` to disable.
|
|
26
|
+
* Request timeout in ms. Set to `null` to disable.
|
|
27
27
|
* @defaultValue `10_000`
|
|
28
28
|
*/
|
|
29
29
|
timeout?: number | null;
|
|
30
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Custom server to use for API requests.
|
|
32
|
+
* @defaultValue `https://api.hyperliquid.xyz` for mainnet and `https://api.hyperliquid-testnet.xyz` for testnet.
|
|
33
|
+
*/
|
|
31
34
|
server?: {
|
|
32
35
|
mainnet?: {
|
|
33
36
|
api?: string | URL;
|
|
@@ -84,6 +87,6 @@ export declare class HttpTransport implements IRequestTransport, HttpTransportOp
|
|
|
84
87
|
* @throws {HttpRequestError} - Thrown when an HTTP response is deemed invalid.
|
|
85
88
|
* @throws May throw {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch#exceptions | fetch errors}.
|
|
86
89
|
*/
|
|
87
|
-
request(endpoint: "info" | "exchange" | "explorer", payload: unknown, signal?: AbortSignal): Promise<
|
|
90
|
+
request<T>(endpoint: "info" | "exchange" | "explorer", payload: unknown, signal?: AbortSignal): Promise<T>;
|
|
88
91
|
}
|
|
89
92
|
//# sourceMappingURL=http_transport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http_transport.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/http/http_transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"http_transport.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/http/http_transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,KAAK,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEpE;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,cAAc;IAM7B,QAAQ,EAAE,QAAQ;IAAS,YAAY,CAAC,EAAE,MAAM;IALnE;;;;OAIG;gBACgB,QAAQ,EAAE,QAAQ,EAAS,YAAY,CAAC,EAAE,MAAM,YAAA;CAOtE;AAED,0DAA0D;AAC1D,MAAM,WAAW,oBAAoB;IACjC;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAExB;;;OAGG;IACH,MAAM,CAAC,EAAE;QACL,OAAO,CAAC,EAAE;YAAE,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;YAAC,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE,CAAC;QACrD,OAAO,CAAC,EAAE;YAAE,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;YAAC,GAAG,CA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AAC,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;CAuDnH"}
|
|
@@ -4,19 +4,21 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "
|
|
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.HttpTransport = exports.HttpRequestError = void 0;
|
|
13
|
-
const base_js_1 = require("
|
|
13
|
+
const base_js_1 = require("../base.js");
|
|
14
14
|
/**
|
|
15
15
|
* Error thrown when an HTTP response is deemed invalid:
|
|
16
16
|
* - Non-200 status code
|
|
17
17
|
* - Unexpected content type
|
|
18
18
|
*/
|
|
19
19
|
class HttpRequestError extends base_js_1.TransportError {
|
|
20
|
+
response;
|
|
21
|
+
responseBody;
|
|
20
22
|
/**
|
|
21
23
|
* Creates a new HTTP request error.
|
|
22
24
|
* @param response - The failed HTTP response.
|
|
@@ -27,65 +29,25 @@
|
|
|
27
29
|
if (responseBody)
|
|
28
30
|
message += `, body "${responseBody}"`;
|
|
29
31
|
super(message);
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
});
|
|
32
|
+
this.response = response;
|
|
33
|
+
this.responseBody = responseBody;
|
|
42
34
|
this.name = "HttpRequestError";
|
|
43
35
|
}
|
|
44
36
|
}
|
|
45
37
|
exports.HttpRequestError = HttpRequestError;
|
|
46
38
|
/** HTTP implementation of the REST transport interface. */
|
|
47
39
|
class HttpTransport {
|
|
40
|
+
isTestnet;
|
|
41
|
+
timeout;
|
|
42
|
+
server;
|
|
43
|
+
fetchOptions;
|
|
44
|
+
onRequest;
|
|
45
|
+
onResponse;
|
|
48
46
|
/**
|
|
49
47
|
* Creates a new HTTP transport instance.
|
|
50
48
|
* @param options - Configuration options for the HTTP transport layer.
|
|
51
49
|
*/
|
|
52
50
|
constructor(options) {
|
|
53
|
-
Object.defineProperty(this, "isTestnet", {
|
|
54
|
-
enumerable: true,
|
|
55
|
-
configurable: true,
|
|
56
|
-
writable: true,
|
|
57
|
-
value: void 0
|
|
58
|
-
});
|
|
59
|
-
Object.defineProperty(this, "timeout", {
|
|
60
|
-
enumerable: true,
|
|
61
|
-
configurable: true,
|
|
62
|
-
writable: true,
|
|
63
|
-
value: void 0
|
|
64
|
-
});
|
|
65
|
-
Object.defineProperty(this, "server", {
|
|
66
|
-
enumerable: true,
|
|
67
|
-
configurable: true,
|
|
68
|
-
writable: true,
|
|
69
|
-
value: void 0
|
|
70
|
-
});
|
|
71
|
-
Object.defineProperty(this, "fetchOptions", {
|
|
72
|
-
enumerable: true,
|
|
73
|
-
configurable: true,
|
|
74
|
-
writable: true,
|
|
75
|
-
value: void 0
|
|
76
|
-
});
|
|
77
|
-
Object.defineProperty(this, "onRequest", {
|
|
78
|
-
enumerable: true,
|
|
79
|
-
configurable: true,
|
|
80
|
-
writable: true,
|
|
81
|
-
value: void 0
|
|
82
|
-
});
|
|
83
|
-
Object.defineProperty(this, "onResponse", {
|
|
84
|
-
enumerable: true,
|
|
85
|
-
configurable: true,
|
|
86
|
-
writable: true,
|
|
87
|
-
value: void 0
|
|
88
|
-
});
|
|
89
51
|
this.isTestnet = options?.isTestnet ?? false;
|
|
90
52
|
this.timeout = options?.timeout === undefined ? 10_000 : options.timeout;
|
|
91
53
|
this.server = {
|
|
@@ -118,7 +80,6 @@
|
|
|
118
80
|
body: JSON.stringify(payload),
|
|
119
81
|
headers: {
|
|
120
82
|
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
121
|
-
"Connection": "keep-alive",
|
|
122
83
|
"Content-Type": "application/json",
|
|
123
84
|
},
|
|
124
85
|
keepalive: true,
|
|
@@ -157,29 +118,21 @@
|
|
|
157
118
|
}
|
|
158
119
|
}
|
|
159
120
|
exports.HttpTransport = HttpTransport;
|
|
160
|
-
/**
|
|
161
|
-
* Merges multiple `HeadersInit` objects into one.
|
|
162
|
-
* @param inits - A list of `HeadersInit` objects to merge.
|
|
163
|
-
* @returns A new `Headers` object that contains all headers from the input objects.
|
|
164
|
-
*/
|
|
121
|
+
/** Merges multiple {@linkcode HeadersInit} into one {@linkcode Headers}. */
|
|
165
122
|
function mergeHeadersInit(...inits) {
|
|
166
123
|
if (inits.length === 0 || inits.length === 1) {
|
|
167
124
|
return new Headers(inits[0]);
|
|
168
125
|
}
|
|
169
126
|
const merged = new Headers();
|
|
170
127
|
for (const headers of inits) {
|
|
171
|
-
const
|
|
172
|
-
for (const [key, value] of
|
|
128
|
+
const iterator = Symbol.iterator in headers ? headers : Object.entries(headers);
|
|
129
|
+
for (const [key, value] of iterator) {
|
|
173
130
|
merged.set(key, value);
|
|
174
131
|
}
|
|
175
132
|
}
|
|
176
133
|
return merged;
|
|
177
134
|
}
|
|
178
|
-
/**
|
|
179
|
-
* Merges multiple `RequestInit` objects into one.
|
|
180
|
-
* @param inits - A list of `RequestInit` objects to merge.
|
|
181
|
-
* @returns A new `RequestInit` object that contains all properties from the input objects.
|
|
182
|
-
*/
|
|
135
|
+
/** Merges multiple {@linkcode RequestInit} into one {@linkcode RequestInit}. */
|
|
183
136
|
function mergeRequestInit(...inits) {
|
|
184
137
|
const merged = inits.reduce((acc, init) => ({ ...acc, ...init }), {});
|
|
185
138
|
const headersList = inits.map((init) => init.headers)
|
|
@@ -1,51 +1,48 @@
|
|
|
1
1
|
import { TypedEventTarget } from "../../../deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js";
|
|
2
2
|
import type { BlockDetails, TxDetails } from "../../types/explorer/responses.js";
|
|
3
3
|
import type { BaseExchangeResponse } from "../../types/exchange/responses.js";
|
|
4
|
+
/** Response to subscribe to or unsubscribe from an event. */
|
|
5
|
+
interface SubscriptionResponse {
|
|
6
|
+
/** Type of subscription operation. */
|
|
7
|
+
method: "subscribe" | "unsubscribe";
|
|
8
|
+
/** Original subscription request. */
|
|
9
|
+
subscription: unknown;
|
|
10
|
+
}
|
|
11
|
+
/** Response to post request. */
|
|
12
|
+
interface PostResponse {
|
|
13
|
+
/** Unique request identifier. */
|
|
14
|
+
id: number;
|
|
15
|
+
/** Server response. */
|
|
16
|
+
response:
|
|
17
|
+
/** Response containing requested information. */
|
|
18
|
+
{
|
|
19
|
+
/** Indicates that this is an informational response. */
|
|
20
|
+
type: "info";
|
|
21
|
+
/** Contains the information data. */
|
|
22
|
+
payload: {
|
|
23
|
+
/** Type of information being returned. */
|
|
24
|
+
type: string;
|
|
25
|
+
/** Information specific data. */
|
|
26
|
+
data: unknown;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** Response containing action result. */
|
|
30
|
+
| {
|
|
31
|
+
/** Indicates that this is an action response. */
|
|
32
|
+
type: "action";
|
|
33
|
+
/** Action result. */
|
|
34
|
+
payload: BaseExchangeResponse;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
4
37
|
/** Base system events and dynamic channel events for Hyperliquid WebSocket API. */
|
|
5
38
|
interface HyperliquidEventMap {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/** Type of subscription operation. */
|
|
9
|
-
method: "subscribe" | "unsubscribe";
|
|
10
|
-
/** Original subscription request. */
|
|
11
|
-
subscription: unknown;
|
|
12
|
-
}>;
|
|
13
|
-
/** Response to post request event. */
|
|
14
|
-
post: CustomEvent<{
|
|
15
|
-
/** Unique request identifier. */
|
|
16
|
-
id: number;
|
|
17
|
-
/** Server response. */
|
|
18
|
-
response:
|
|
19
|
-
/** Response containing requested information. */
|
|
20
|
-
{
|
|
21
|
-
/** Indicates that this is an informational response. */
|
|
22
|
-
type: "info";
|
|
23
|
-
/** Contains the information data. */
|
|
24
|
-
payload: {
|
|
25
|
-
/** Type of information being returned. */
|
|
26
|
-
type: string;
|
|
27
|
-
/** Information specific data. */
|
|
28
|
-
data: unknown;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
/** Response containing action result. */
|
|
32
|
-
| {
|
|
33
|
-
/** Indicates that this is an action response. */
|
|
34
|
-
type: "action";
|
|
35
|
-
/** Action result. */
|
|
36
|
-
payload: BaseExchangeResponse;
|
|
37
|
-
};
|
|
38
|
-
}>;
|
|
39
|
-
/** Error response for message event. */
|
|
39
|
+
subscriptionResponse: CustomEvent<SubscriptionResponse>;
|
|
40
|
+
post: CustomEvent<PostResponse>;
|
|
40
41
|
error: CustomEvent<string>;
|
|
41
|
-
/** Pong response event. */
|
|
42
42
|
pong: CustomEvent<undefined>;
|
|
43
|
-
/** Block explorer update event. */
|
|
44
43
|
_explorerBlock: CustomEvent<Omit<BlockDetails, "txs">[]>;
|
|
45
|
-
/** Transaction explorer update event. */
|
|
46
44
|
_explorerTxs: CustomEvent<TxDetails[]>;
|
|
47
|
-
|
|
48
|
-
[key: string]: CustomEvent<unknown>;
|
|
45
|
+
[key: string]: CustomEvent<any>;
|
|
49
46
|
}
|
|
50
47
|
/** Listens for WebSocket messages and sends them as Hyperliquid typed events. */
|
|
51
48
|
export declare class HyperliquidEventTarget extends TypedEventTarget<HyperliquidEventMap> {
|
|
@@ -1 +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;AACjF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAU9E,
|
|
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;AACjF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAU9E,6DAA6D;AAC7D,UAAU,oBAAoB;IAC1B,sCAAsC;IACtC,MAAM,EAAE,WAAW,GAAG,aAAa,CAAC;IACpC,qCAAqC;IACrC,YAAY,EAAE,OAAO,CAAC;CACzB;AAED,gCAAgC;AAChC,UAAU,YAAY;IAClB,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,uBAAuB;IACvB,QAAQ;IACJ,iDAAiD;IAC/C;QACE,wDAAwD;QACxD,IAAI,EAAE,MAAM,CAAC;QACb,qCAAqC;QACrC,OAAO,EAAE;YACL,0CAA0C;YAC1C,IAAI,EAAE,MAAM,CAAC;YACb,iCAAiC;YACjC,IAAI,EAAE,OAAO,CAAC;SACjB,CAAC;KACL;IACD,yCAAyC;OACvC;QACE,iDAAiD;QACjD,IAAI,EAAE,QAAQ,CAAC;QACf,qBAAqB;QACrB,OAAO,EAAE,oBAAoB,CAAC;KACjC,CAAC;CACT;AAED,mFAAmF;AACnF,UAAU,mBAAmB;IACzB,oBAAoB,EAAE,WAAW,CAAC,oBAAoB,CAAC,CAAC;IACxD,IAAI,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;IAChC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC3B,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAC7B,cAAc,EAAE,WAAW,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;IACzD,YAAY,EAAE,WAAW,CAAC,SAAS,EAAE,CAAC,CAAC;IAEvC,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;CACnC;AAED,iFAAiF;AACjF,qBAAa,sBAAuB,SAAQ,gBAAgB,CAAC,mBAAmB,CAAC;gBACjE,MAAM,EAAE,SAAS;CAiBhC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { MaybePromise } from "../../base.js";
|
|
2
|
+
import { TransportError } from "../base.js";
|
|
2
3
|
/** Configuration options for the `ReconnectingWebSocket`. */
|
|
3
4
|
export interface ReconnectingWebSocketOptions {
|
|
4
5
|
/**
|
|
@@ -34,46 +35,38 @@ export interface ReconnectingWebSocketOptions {
|
|
|
34
35
|
}
|
|
35
36
|
/** Message buffer strategy interface. */
|
|
36
37
|
export interface MessageBufferStrategy {
|
|
37
|
-
/** Array of buffered messages. */
|
|
38
|
-
messages: (string | ArrayBufferLike | Blob | ArrayBufferView)[];
|
|
39
|
-
/**
|
|
40
|
-
* Add a message to the buffer.
|
|
41
|
-
* @param data - The message to buffer.
|
|
42
|
-
*/
|
|
43
38
|
push(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
|
|
44
|
-
|
|
45
|
-
* Get and remove the next message from the buffer.
|
|
46
|
-
* @returns The next message or `undefined` if no more messages are available.
|
|
47
|
-
*/
|
|
48
|
-
shift(): (string | ArrayBufferLike | Blob | ArrayBufferView) | undefined;
|
|
49
|
-
/** Clear all buffered messages. */
|
|
50
|
-
clear(): void;
|
|
39
|
+
[Symbol.iterator](): Iterator<string | ArrayBufferLike | Blob | ArrayBufferView>;
|
|
51
40
|
}
|
|
52
41
|
/** Error thrown when reconnection problems occur. */
|
|
53
42
|
export declare class ReconnectingWebSocketError extends TransportError {
|
|
54
43
|
code: "RECONNECTION_LIMIT_REACHED" | "RECONNECTION_STOPPED_BY_USER" | "USER_INITIATED_CLOSE" | "UNKNOWN_ERROR";
|
|
55
|
-
|
|
56
|
-
constructor(code: "RECONNECTION_LIMIT_REACHED" | "RECONNECTION_STOPPED_BY_USER" | "USER_INITIATED_CLOSE" | "UNKNOWN_ERROR", originalError?: unknown);
|
|
44
|
+
constructor(code: "RECONNECTION_LIMIT_REACHED" | "RECONNECTION_STOPPED_BY_USER" | "USER_INITIATED_CLOSE" | "UNKNOWN_ERROR", cause?: unknown);
|
|
57
45
|
}
|
|
58
46
|
/**
|
|
59
47
|
* A WebSocket that automatically reconnects when disconnected.
|
|
60
48
|
* Fully compatible with standard WebSocket API.
|
|
61
49
|
*/
|
|
62
50
|
export declare class ReconnectingWebSocket implements WebSocket {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
51
|
+
protected _socket: WebSocket;
|
|
52
|
+
protected _protocols?: string | string[];
|
|
53
|
+
protected _listeners: {
|
|
54
|
+
type: string;
|
|
55
|
+
listener: EventListenerOrEventListenerObject;
|
|
56
|
+
options?: boolean | AddEventListenerOptions;
|
|
57
|
+
listenerProxy: EventListenerOrEventListenerObject;
|
|
58
|
+
}[];
|
|
59
|
+
protected _attempt: number;
|
|
67
60
|
reconnectOptions: Required<ReconnectingWebSocketOptions>;
|
|
68
61
|
readonly reconnectAbortController: AbortController;
|
|
69
62
|
constructor(url: string | URL, protocols?: string | string[], options?: ReconnectingWebSocketOptions);
|
|
70
|
-
|
|
63
|
+
protected _createSocket(url: string | URL, protocols?: string | string[]): WebSocket;
|
|
71
64
|
/** Initializes the internal event listeners for the socket. */
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
protected _setupEventListeners(): void;
|
|
66
|
+
protected _open: () => void;
|
|
67
|
+
protected _close: (event: CloseEvent) => Promise<void>;
|
|
75
68
|
/** Clean up internal resources. */
|
|
76
|
-
|
|
69
|
+
protected _cleanup(code: ConstructorParameters<typeof ReconnectingWebSocketError>[0], cause?: unknown): void;
|
|
77
70
|
get url(): string;
|
|
78
71
|
get readyState(): number;
|
|
79
72
|
get bufferedAmount(): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_reconnecting_websocket.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/_reconnecting_websocket.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"_reconnecting_websocket.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/_reconnecting_websocket.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,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,EAAE,MAAM,EAAE,WAAW,KAAK,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;IAE5F;;;;;OAKG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,KAAK,YAAY,CAAC,OAAO,CAAC,CAAC;IAEpF;;;OAGG;IACH,aAAa,CAAC,EAAE,qBAAqB,CAAC;CACzC;AAED,yCAAyC;AACzC,MAAM,WAAW,qBAAqB;IAClC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,GAAG,eAAe,GAAG,IAAI,CAAC;IACpE,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,eAAe,GAAG,IAAI,GAAG,eAAe,CAAC,CAAC;CACpF;AAiBD,qDAAqD;AACrD,qBAAa,0BAA2B,SAAQ,cAAc;IAE/C,IAAI,EACL,4BAA4B,GAC5B,8BAA8B,GAC9B,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