@nktkas/hyperliquid 0.25.0-beta.2 → 0.25.0-beta.4
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 +114 -106
- package/esm/bin/_utils.d.ts +80 -0
- package/esm/bin/_utils.d.ts.map +1 -0
- package/esm/bin/_utils.js +112 -0
- package/esm/bin/_utils.js.map +1 -0
- package/esm/bin/cli.d.ts +3 -0
- package/esm/bin/cli.d.ts.map +1 -0
- package/esm/bin/cli.js +334 -0
- package/esm/bin/cli.js.map +1 -0
- package/esm/src/{errors.d.ts → _errors.d.ts} +1 -1
- package/esm/src/_errors.d.ts.map +1 -0
- package/esm/src/{errors.js → _errors.js} +1 -1
- package/esm/src/_errors.js.map +1 -0
- package/esm/src/clients/exchange.d.ts +91 -91
- package/esm/src/clients/exchange.d.ts.map +1 -1
- package/esm/src/clients/exchange.js +61 -56
- package/esm/src/clients/exchange.js.map +1 -1
- package/esm/src/clients/info.d.ts +134 -112
- package/esm/src/clients/info.d.ts.map +1 -1
- package/esm/src/clients/info.js +95 -72
- package/esm/src/clients/info.js.map +1 -1
- package/esm/src/clients/multiSign.d.ts +2 -2
- package/esm/src/clients/multiSign.d.ts.map +1 -1
- package/esm/src/clients/multiSign.js +3 -1
- package/esm/src/clients/multiSign.js.map +1 -1
- package/esm/src/clients/subscription.d.ts +23 -23
- package/esm/src/clients/subscription.d.ts.map +1 -1
- package/esm/src/clients/subscription.js +8 -11
- package/esm/src/clients/subscription.js.map +1 -1
- package/esm/src/mod.d.ts +21 -0
- package/esm/src/mod.d.ts.map +1 -0
- package/esm/src/mod.js +14 -0
- package/esm/src/mod.js.map +1 -0
- package/esm/src/schemas/_base.d.ts +8 -6
- package/esm/src/schemas/_base.d.ts.map +1 -1
- package/esm/src/schemas/_base.js +6 -4
- package/esm/src/schemas/_base.js.map +1 -1
- package/esm/src/schemas/exchange/requests.d.ts +332 -313
- package/esm/src/schemas/exchange/requests.d.ts.map +1 -1
- package/esm/src/schemas/exchange/requests.js +52 -61
- package/esm/src/schemas/exchange/requests.js.map +1 -1
- package/esm/src/schemas/exchange/responses.d.ts +10 -10
- package/esm/src/schemas/exchange/responses.js +3 -3
- package/esm/src/schemas/exchange/responses.js.map +1 -1
- package/esm/src/schemas/explorer/requests.d.ts +1 -1
- package/esm/src/schemas/explorer/requests.js +2 -2
- package/esm/src/schemas/explorer/requests.js.map +1 -1
- package/esm/src/schemas/explorer/responses.d.ts +16 -16
- package/esm/src/schemas/explorer/responses.js +3 -3
- package/esm/src/schemas/explorer/responses.js.map +1 -1
- package/esm/src/schemas/info/accounts.d.ts +975 -229
- package/esm/src/schemas/info/accounts.d.ts.map +1 -1
- package/esm/src/schemas/info/accounts.js +65 -21
- package/esm/src/schemas/info/accounts.js.map +1 -1
- package/esm/src/schemas/info/assets.d.ts +110 -110
- package/esm/src/schemas/info/assets.js +9 -9
- package/esm/src/schemas/info/assets.js.map +1 -1
- package/esm/src/schemas/info/markets.d.ts +25 -25
- package/esm/src/schemas/info/markets.js +3 -3
- package/esm/src/schemas/info/markets.js.map +1 -1
- package/esm/src/schemas/info/orders.d.ts +175 -175
- package/esm/src/schemas/info/orders.js +3 -3
- package/esm/src/schemas/info/orders.js.map +1 -1
- package/esm/src/schemas/info/requests.d.ts +31 -16
- package/esm/src/schemas/info/requests.d.ts.map +1 -1
- package/esm/src/schemas/info/requests.js +51 -40
- package/esm/src/schemas/info/requests.js.map +1 -1
- package/esm/src/schemas/info/validators.d.ts +30 -30
- package/esm/src/schemas/info/validators.d.ts.map +1 -1
- package/esm/src/schemas/info/validators.js +8 -8
- package/esm/src/schemas/info/validators.js.map +1 -1
- package/esm/src/schemas/info/vaults.d.ts +46 -46
- package/esm/src/schemas/info/vaults.js +10 -10
- package/esm/src/schemas/info/vaults.js.map +1 -1
- package/esm/src/schemas/mod.d.ts +3 -3
- package/esm/src/schemas/mod.d.ts.map +1 -1
- package/esm/src/schemas/mod.js +3 -3
- package/esm/src/schemas/mod.js.map +1 -1
- package/esm/src/schemas/subscriptions/requests.d.ts +4 -4
- package/esm/src/schemas/subscriptions/requests.d.ts.map +1 -1
- package/esm/src/schemas/subscriptions/requests.js +17 -17
- package/esm/src/schemas/subscriptions/requests.js.map +1 -1
- package/esm/src/schemas/subscriptions/responses.d.ts +618 -618
- package/esm/src/schemas/subscriptions/responses.js +14 -14
- package/esm/src/schemas/subscriptions/responses.js.map +1 -1
- package/esm/src/signing/mod.d.ts +1 -1
- package/esm/src/signing/mod.d.ts.map +1 -1
- package/esm/src/signing/mod.js +6 -6
- package/esm/src/signing/mod.js.map +1 -1
- package/esm/src/signing/signTypedData/ethers.d.ts.map +1 -0
- package/esm/src/signing/signTypedData/ethers.js.map +1 -0
- package/esm/src/signing/signTypedData/mod.d.ts.map +1 -0
- package/esm/src/signing/signTypedData/mod.js.map +1 -0
- package/esm/src/signing/signTypedData/private_key.d.ts.map +1 -0
- package/esm/src/signing/{_signTypedData → signTypedData}/private_key.js +18 -17
- package/esm/src/signing/signTypedData/private_key.js.map +1 -0
- package/esm/src/signing/signTypedData/viem.d.ts.map +1 -0
- package/esm/src/signing/signTypedData/viem.js.map +1 -0
- package/esm/src/transports/_polyfills.d.ts +12 -0
- package/esm/src/transports/_polyfills.d.ts.map +1 -0
- package/esm/src/transports/_polyfills.js +40 -0
- package/esm/src/transports/_polyfills.js.map +1 -0
- package/esm/src/transports/base.d.ts +8 -8
- package/esm/src/transports/base.d.ts.map +1 -1
- package/esm/src/transports/base.js +2 -2
- package/esm/src/transports/base.js.map +1 -1
- package/esm/src/transports/http/http_transport.d.ts +11 -4
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +17 -6
- package/esm/src/transports/http/http_transport.js.map +1 -1
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +8 -7
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/esm/src/transports/websocket/_hyperliquid_event_target.js +14 -33
- package/esm/src/transports/websocket/_hyperliquid_event_target.js.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts +26 -29
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.js +82 -76
- package/esm/src/transports/websocket/_reconnecting_websocket.js.map +1 -1
- package/esm/src/transports/websocket/_websocket_async_request.d.ts +6 -0
- package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/esm/src/transports/websocket/_websocket_async_request.js +49 -41
- package/esm/src/transports/websocket/_websocket_async_request.js.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.d.ts +48 -70
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +90 -103
- package/esm/src/transports/websocket/websocket_transport.js.map +1 -1
- package/package.json +12 -8
- package/script/bin/_utils.d.ts +80 -0
- package/script/bin/_utils.d.ts.map +1 -0
- package/script/bin/_utils.js +116 -0
- package/script/bin/_utils.js.map +1 -0
- package/script/bin/cli.d.ts +3 -0
- package/script/bin/cli.d.ts.map +1 -0
- package/script/bin/cli.js +369 -0
- package/script/bin/cli.js.map +1 -0
- package/script/src/{errors.d.ts → _errors.d.ts} +1 -1
- package/script/src/_errors.d.ts.map +1 -0
- package/script/src/{errors.js → _errors.js} +1 -1
- package/script/src/_errors.js.map +1 -0
- package/script/src/clients/exchange.d.ts +91 -91
- package/script/src/clients/exchange.d.ts.map +1 -1
- package/script/src/clients/exchange.js +61 -56
- package/script/src/clients/exchange.js.map +1 -1
- package/script/src/clients/info.d.ts +134 -112
- package/script/src/clients/info.d.ts.map +1 -1
- package/script/src/clients/info.js +94 -71
- package/script/src/clients/info.js.map +1 -1
- package/script/src/clients/multiSign.d.ts +2 -2
- package/script/src/clients/multiSign.d.ts.map +1 -1
- package/script/src/clients/multiSign.js +9 -7
- package/script/src/clients/multiSign.js.map +1 -1
- package/script/src/clients/subscription.d.ts +23 -23
- package/script/src/clients/subscription.d.ts.map +1 -1
- package/script/src/clients/subscription.js +8 -11
- package/script/src/clients/subscription.js.map +1 -1
- package/script/src/mod.d.ts +21 -0
- package/script/src/mod.d.ts.map +1 -0
- package/script/{mod.js → src/mod.js} +12 -8
- package/script/src/mod.js.map +1 -0
- package/script/src/schemas/_base.d.ts +8 -6
- package/script/src/schemas/_base.d.ts.map +1 -1
- package/script/src/schemas/_base.js +7 -5
- package/script/src/schemas/_base.js.map +1 -1
- package/script/src/schemas/exchange/requests.d.ts +332 -313
- package/script/src/schemas/exchange/requests.d.ts.map +1 -1
- package/script/src/schemas/exchange/requests.js +51 -60
- package/script/src/schemas/exchange/requests.js.map +1 -1
- package/script/src/schemas/exchange/responses.d.ts +10 -10
- package/script/src/schemas/exchange/responses.js +2 -2
- package/script/src/schemas/exchange/responses.js.map +1 -1
- package/script/src/schemas/explorer/requests.d.ts +1 -1
- package/script/src/schemas/explorer/requests.js +1 -1
- package/script/src/schemas/explorer/requests.js.map +1 -1
- package/script/src/schemas/explorer/responses.d.ts +16 -16
- package/script/src/schemas/explorer/responses.js +2 -2
- package/script/src/schemas/explorer/responses.js.map +1 -1
- package/script/src/schemas/info/accounts.d.ts +975 -229
- package/script/src/schemas/info/accounts.d.ts.map +1 -1
- package/script/src/schemas/info/accounts.js +65 -21
- package/script/src/schemas/info/accounts.js.map +1 -1
- package/script/src/schemas/info/assets.d.ts +110 -110
- package/script/src/schemas/info/assets.js +8 -8
- package/script/src/schemas/info/assets.js.map +1 -1
- package/script/src/schemas/info/markets.d.ts +25 -25
- package/script/src/schemas/info/markets.js +2 -2
- package/script/src/schemas/info/markets.js.map +1 -1
- package/script/src/schemas/info/orders.d.ts +175 -175
- package/script/src/schemas/info/orders.js +2 -2
- package/script/src/schemas/info/orders.js.map +1 -1
- package/script/src/schemas/info/requests.d.ts +31 -16
- package/script/src/schemas/info/requests.d.ts.map +1 -1
- package/script/src/schemas/info/requests.js +51 -40
- package/script/src/schemas/info/requests.js.map +1 -1
- package/script/src/schemas/info/validators.d.ts +30 -30
- package/script/src/schemas/info/validators.d.ts.map +1 -1
- package/script/src/schemas/info/validators.js +7 -7
- package/script/src/schemas/info/validators.js.map +1 -1
- package/script/src/schemas/info/vaults.d.ts +46 -46
- package/script/src/schemas/info/vaults.js +9 -9
- package/script/src/schemas/info/vaults.js.map +1 -1
- package/script/src/schemas/mod.d.ts +3 -3
- package/script/src/schemas/mod.d.ts.map +1 -1
- package/script/src/schemas/mod.js +4 -4
- package/script/src/schemas/mod.js.map +1 -1
- package/script/src/schemas/subscriptions/requests.d.ts +4 -4
- package/script/src/schemas/subscriptions/requests.d.ts.map +1 -1
- package/script/src/schemas/subscriptions/requests.js +16 -16
- package/script/src/schemas/subscriptions/requests.js.map +1 -1
- package/script/src/schemas/subscriptions/responses.d.ts +618 -618
- package/script/src/schemas/subscriptions/responses.js +13 -13
- package/script/src/schemas/subscriptions/responses.js.map +1 -1
- package/script/src/signing/mod.d.ts +1 -1
- package/script/src/signing/mod.d.ts.map +1 -1
- package/script/src/signing/mod.js +40 -7
- package/script/src/signing/mod.js.map +1 -1
- package/script/src/signing/signTypedData/ethers.d.ts.map +1 -0
- package/script/src/signing/signTypedData/ethers.js.map +1 -0
- package/script/src/signing/signTypedData/mod.d.ts.map +1 -0
- package/script/src/signing/signTypedData/mod.js.map +1 -0
- package/script/src/signing/signTypedData/private_key.d.ts.map +1 -0
- package/script/src/signing/{_signTypedData → signTypedData}/private_key.js +55 -21
- package/script/src/signing/signTypedData/private_key.js.map +1 -0
- package/script/src/signing/signTypedData/viem.d.ts.map +1 -0
- package/script/src/signing/signTypedData/viem.js.map +1 -0
- package/script/src/transports/_polyfills.d.ts +12 -0
- package/script/src/transports/_polyfills.d.ts.map +1 -0
- package/script/src/transports/_polyfills.js +43 -0
- package/script/src/transports/_polyfills.js.map +1 -0
- package/script/src/transports/base.d.ts +8 -8
- package/script/src/transports/base.d.ts.map +1 -1
- package/script/src/transports/base.js +3 -3
- package/script/src/transports/base.js.map +1 -1
- package/script/src/transports/http/http_transport.d.ts +11 -4
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +17 -6
- package/script/src/transports/http/http_transport.js.map +1 -1
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +8 -7
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/script/src/transports/websocket/_hyperliquid_event_target.js +47 -33
- package/script/src/transports/websocket/_hyperliquid_event_target.js.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts +26 -29
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.js +82 -76
- package/script/src/transports/websocket/_reconnecting_websocket.js.map +1 -1
- package/script/src/transports/websocket/_websocket_async_request.d.ts +6 -0
- package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/script/src/transports/websocket/_websocket_async_request.js +52 -43
- package/script/src/transports/websocket/_websocket_async_request.js.map +1 -1
- package/script/src/transports/websocket/websocket_transport.d.ts +48 -70
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +92 -105
- package/script/src/transports/websocket/websocket_transport.js.map +1 -1
- package/src/bin/_utils.ts +185 -0
- package/src/bin/cli.ts +359 -0
- package/src/src/clients/exchange.ts +155 -144
- package/src/src/clients/info.ts +158 -124
- package/src/src/clients/multiSign.ts +13 -11
- package/src/src/clients/subscription.ts +32 -32
- package/src/src/mod.ts +29 -0
- package/src/src/schemas/_base.ts +25 -8
- package/src/src/schemas/exchange/requests.ts +59 -61
- package/src/src/schemas/exchange/responses.ts +3 -3
- package/src/src/schemas/explorer/requests.ts +2 -2
- package/src/src/schemas/explorer/responses.ts +3 -3
- package/src/src/schemas/info/accounts.ts +129 -21
- package/src/src/schemas/info/assets.ts +9 -9
- package/src/src/schemas/info/markets.ts +3 -3
- package/src/src/schemas/info/orders.ts +3 -3
- package/src/src/schemas/info/requests.ts +72 -40
- package/src/src/schemas/info/validators.ts +22 -24
- package/src/src/schemas/info/vaults.ts +10 -10
- package/src/src/schemas/mod.ts +3 -3
- package/src/src/schemas/subscriptions/requests.ts +27 -17
- package/src/src/schemas/subscriptions/responses.ts +14 -14
- package/src/src/signing/mod.ts +6 -6
- package/src/src/signing/{_signTypedData → signTypedData}/private_key.ts +22 -17
- package/src/src/transports/_polyfills.ts +41 -0
- package/src/src/transports/base.ts +8 -8
- package/src/src/transports/http/http_transport.ts +25 -14
- package/src/src/transports/websocket/_hyperliquid_event_target.ts +24 -51
- package/src/src/transports/websocket/_reconnecting_websocket.ts +107 -119
- package/src/src/transports/websocket/_websocket_async_request.ts +57 -59
- package/src/src/transports/websocket/websocket_transport.ts +126 -167
- package/esm/mod.d.ts +0 -20
- package/esm/mod.d.ts.map +0 -1
- package/esm/mod.js +0 -12
- package/esm/mod.js.map +0 -1
- package/esm/src/errors.d.ts.map +0 -1
- package/esm/src/errors.js.map +0 -1
- package/esm/src/signing/_signTypedData/ethers.d.ts.map +0 -1
- package/esm/src/signing/_signTypedData/ethers.js.map +0 -1
- package/esm/src/signing/_signTypedData/mod.d.ts.map +0 -1
- package/esm/src/signing/_signTypedData/mod.js.map +0 -1
- package/esm/src/signing/_signTypedData/private_key.d.ts.map +0 -1
- package/esm/src/signing/_signTypedData/private_key.js.map +0 -1
- package/esm/src/signing/_signTypedData/viem.d.ts.map +0 -1
- package/esm/src/signing/_signTypedData/viem.js.map +0 -1
- package/script/mod.d.ts +0 -20
- package/script/mod.d.ts.map +0 -1
- package/script/mod.js.map +0 -1
- package/script/src/errors.d.ts.map +0 -1
- package/script/src/errors.js.map +0 -1
- package/script/src/signing/_signTypedData/ethers.d.ts.map +0 -1
- package/script/src/signing/_signTypedData/ethers.js.map +0 -1
- package/script/src/signing/_signTypedData/mod.d.ts.map +0 -1
- package/script/src/signing/_signTypedData/mod.js.map +0 -1
- package/script/src/signing/_signTypedData/private_key.d.ts.map +0 -1
- package/script/src/signing/_signTypedData/private_key.js.map +0 -1
- package/script/src/signing/_signTypedData/viem.d.ts.map +0 -1
- package/script/src/signing/_signTypedData/viem.js.map +0 -1
- package/src/mod.ts +0 -28
- /package/esm/src/signing/{_signTypedData → signTypedData}/ethers.d.ts +0 -0
- /package/esm/src/signing/{_signTypedData → signTypedData}/ethers.js +0 -0
- /package/esm/src/signing/{_signTypedData → signTypedData}/mod.d.ts +0 -0
- /package/esm/src/signing/{_signTypedData → signTypedData}/mod.js +0 -0
- /package/esm/src/signing/{_signTypedData → signTypedData}/private_key.d.ts +0 -0
- /package/esm/src/signing/{_signTypedData → signTypedData}/viem.d.ts +0 -0
- /package/esm/src/signing/{_signTypedData → signTypedData}/viem.js +0 -0
- /package/script/src/signing/{_signTypedData → signTypedData}/ethers.d.ts +0 -0
- /package/script/src/signing/{_signTypedData → signTypedData}/ethers.js +0 -0
- /package/script/src/signing/{_signTypedData → signTypedData}/mod.d.ts +0 -0
- /package/script/src/signing/{_signTypedData → signTypedData}/mod.js +0 -0
- /package/script/src/signing/{_signTypedData → signTypedData}/private_key.d.ts +0 -0
- /package/script/src/signing/{_signTypedData → signTypedData}/viem.d.ts +0 -0
- /package/script/src/signing/{_signTypedData → signTypedData}/viem.js +0 -0
- /package/src/src/{errors.ts → _errors.ts} +0 -0
- /package/src/src/signing/{_signTypedData → signTypedData}/ethers.ts +0 -0
- /package/src/src/signing/{_signTypedData → signTypedData}/mod.ts +0 -0
- /package/src/src/signing/{_signTypedData → signTypedData}/viem.ts +0 -0
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ runtimes, written in TypeScript.
|
|
|
23
23
|
> [!NOTE]
|
|
24
24
|
> While this library is in TypeScript, it can also be used in JavaScript and supports ESM/CommonJS.
|
|
25
25
|
|
|
26
|
-
### Node.js (choose your package manager)
|
|
26
|
+
### Node.js v20+ (choose your package manager)
|
|
27
27
|
|
|
28
28
|
```
|
|
29
29
|
npm i @nktkas/hyperliquid
|
|
@@ -33,7 +33,21 @@ pnpm add @nktkas/hyperliquid
|
|
|
33
33
|
yarn add @nktkas/hyperliquid
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
If you are using **Node.js v20 specifically** and intend to use [`WebSocketTransport`](#websocket-transport), you need
|
|
37
|
+
to install the [`ws`](https://www.npmjs.com/package/ws) package and pass the `WebSocket` class to the constructor:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import WebSocket from "ws"; // install `ws` package
|
|
41
|
+
import * as hl from "@nktkas/hyperliquid";
|
|
42
|
+
|
|
43
|
+
const transport = new hl.WebSocketTransport({
|
|
44
|
+
reconnect: {
|
|
45
|
+
WebSocket, // pass `WebSocket` class from `ws` package
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Deno v2.0+
|
|
37
51
|
|
|
38
52
|
```
|
|
39
53
|
deno add jsr:@nktkas/hyperliquid
|
|
@@ -41,79 +55,41 @@ deno add jsr:@nktkas/hyperliquid
|
|
|
41
55
|
|
|
42
56
|
### Web
|
|
43
57
|
|
|
58
|
+
The SDK is fully browser-compatible; integrate it via CDN or bundle it with your application.
|
|
59
|
+
|
|
44
60
|
```html
|
|
45
61
|
<script type="module">
|
|
46
62
|
import * as hl from "https://esm.sh/jsr/@nktkas/hyperliquid";
|
|
47
63
|
</script>
|
|
48
64
|
```
|
|
49
65
|
|
|
50
|
-
### React Native
|
|
66
|
+
### React Native v0.74.5 / Expo v51
|
|
51
67
|
|
|
52
|
-
|
|
53
|
-
<summary>For React Native, you need to import polyfills before importing the SDK:</summary>
|
|
54
|
-
|
|
55
|
-
```js
|
|
56
|
-
// React Native v0.79 / Expo v53
|
|
57
|
-
// Issues:
|
|
58
|
-
// - signing: does not support private keys directly, use `viem` or `ethers`
|
|
59
|
-
|
|
60
|
-
import "event-target-polyfill"; // for `WebSocketTransport`
|
|
61
|
-
// or
|
|
62
|
-
// import { Event, EventTarget } from "event-target-shim";
|
|
63
|
-
// if (!globalThis.EventTarget || !globalThis.Event) {
|
|
64
|
-
// globalThis.EventTarget = EventTarget;
|
|
65
|
-
// globalThis.Event = Event;
|
|
66
|
-
// }
|
|
68
|
+
For React Native, you need to import polyfills before importing the SDK:
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return event;
|
|
74
|
-
};
|
|
75
|
-
}
|
|
70
|
+
```ts
|
|
71
|
+
import "fast-text-encoding"; // `TextEncoder` (utf-8)
|
|
72
|
+
import "event-target-polyfill"; // `EventTarget`, `Event`
|
|
73
|
+
import * as hl from "@nktkas/hyperliquid";
|
|
74
|
+
```
|
|
76
75
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
let resolve, reject;
|
|
80
|
-
const promise = new Promise((res, rej) => {
|
|
81
|
-
resolve = res;
|
|
82
|
-
reject = rej;
|
|
83
|
-
});
|
|
84
|
-
return { promise, resolve, reject };
|
|
85
|
-
};
|
|
86
|
-
}
|
|
76
|
+
<details>
|
|
77
|
+
<summary>Issues:</summary>
|
|
87
78
|
|
|
88
|
-
|
|
89
|
-
AbortSignal.any = function (signals) {
|
|
90
|
-
const controller = new AbortController();
|
|
91
|
-
for (const signal of signals) {
|
|
92
|
-
if (signal.aborted) {
|
|
93
|
-
controller.abort(signal.reason);
|
|
94
|
-
return controller.signal;
|
|
95
|
-
}
|
|
96
|
-
signal.addEventListener("abort", () => {
|
|
97
|
-
controller.abort(signal.reason);
|
|
98
|
-
}, { once: true, signal: controller.signal });
|
|
99
|
-
}
|
|
100
|
-
return controller.signal;
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (!AbortSignal.timeout) {
|
|
105
|
-
AbortSignal.timeout = function (delay) {
|
|
106
|
-
const controller = new AbortController();
|
|
107
|
-
setTimeout(() => controller.abort(), delay);
|
|
108
|
-
return controller.signal;
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
```
|
|
79
|
+
- signing: doesn't support a private key directly as a wallet, use `viem` or `ethers` instead
|
|
112
80
|
|
|
113
81
|
</details>
|
|
114
82
|
|
|
115
83
|
## Quick Start
|
|
116
84
|
|
|
85
|
+
### CLI
|
|
86
|
+
|
|
87
|
+
The SDK includes a command-line interface for quick interactions with Hyperliquid API without writing code.
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npx @nktkas/hyperliquid --help
|
|
91
|
+
```
|
|
92
|
+
|
|
117
93
|
### [Info endpoint](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint)
|
|
118
94
|
|
|
119
95
|
```ts
|
|
@@ -189,6 +165,7 @@ const multiSignClient = new hl.MultiSignClient({
|
|
|
189
165
|
multiSignAddress: "0x...",
|
|
190
166
|
signers: [
|
|
191
167
|
"0x...", // `viem`, `ethers`, or private key directly
|
|
168
|
+
// ... more signers
|
|
192
169
|
],
|
|
193
170
|
});
|
|
194
171
|
|
|
@@ -206,10 +183,10 @@ First, choose and configure your transport layer (more details in the [API Refer
|
|
|
206
183
|
import * as hl from "@nktkas/hyperliquid";
|
|
207
184
|
|
|
208
185
|
// 1. HTTP Transport: suitable for one-time requests or serverless environments
|
|
209
|
-
const httpTransport = new hl.HttpTransport({...}); // Accepts optional parameters (e.g. isTestnet, timeout, etc.)
|
|
186
|
+
const httpTransport = new hl.HttpTransport({ ... }); // Accepts optional parameters (e.g. isTestnet, timeout, etc.)
|
|
210
187
|
|
|
211
188
|
// 2. WebSocket Transport: has better network latency than HTTP transport
|
|
212
|
-
const wsTransport = new hl.WebSocketTransport({...}); // Accepts optional parameters (e.g. url, isTestnet, timeout, reconnect, etc.)
|
|
189
|
+
const wsTransport = new hl.WebSocketTransport({ ... }); // Accepts optional parameters (e.g. url, isTestnet, timeout, reconnect, etc.)
|
|
213
190
|
```
|
|
214
191
|
|
|
215
192
|
### 2) Initialize Client
|
|
@@ -531,6 +508,7 @@ class ExchangeClient {
|
|
|
531
508
|
setReferrer(params: SetReferrerParameters): Promise<SuccessResponse>;
|
|
532
509
|
subAccountModify(params: SubAccountModifyParameters): Promise<SuccessResponse>;
|
|
533
510
|
spotUser(params: SpotUserParameters): Promise<SuccessResponse>;
|
|
511
|
+
webData2(params: WebData2Parameters): Promise<WebData2>;
|
|
534
512
|
|
|
535
513
|
// Transfer
|
|
536
514
|
sendAsset(params: SendAssetParameters): Promise<SuccessResponse>;
|
|
@@ -626,7 +604,7 @@ class MultiSignClient extends ExchangeClient {
|
|
|
626
604
|
multiSignAddress: Hex;
|
|
627
605
|
signers: [
|
|
628
606
|
AbstractWallet, // first is leader for multi-sign transaction (signs transaction 2 times)
|
|
629
|
-
...AbstractWallet[], //
|
|
607
|
+
...AbstractWallet[], // ... more signers
|
|
630
608
|
];
|
|
631
609
|
},
|
|
632
610
|
);
|
|
@@ -641,69 +619,105 @@ Transport acts as a layer between class requests and Hyperliquid servers.
|
|
|
641
619
|
|
|
642
620
|
#### HTTP Transport
|
|
643
621
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
- Uses [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) for requests. Can be configured using
|
|
647
|
-
[`fetchOptions`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit).
|
|
648
|
-
- Automatically determines the target URL based on the request + `isTestnet` flag.
|
|
622
|
+
Uses [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) for requests.
|
|
649
623
|
|
|
650
624
|
```ts
|
|
651
625
|
class HttpTransport {
|
|
652
626
|
constructor(options?: {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
627
|
+
/** Whether to use testnet url (default: false) */
|
|
628
|
+
isTestnet?: boolean;
|
|
629
|
+
/** Request timeout in ms (default: 10_000) */
|
|
630
|
+
timeout?: number;
|
|
631
|
+
/** Custom server URLs */
|
|
632
|
+
server?: {
|
|
656
633
|
mainnet?: { api?: string | URL; rpc?: string | URL };
|
|
657
634
|
testnet?: { api?: string | URL; rpc?: string | URL };
|
|
658
635
|
};
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
636
|
+
/** Custom fetch options */
|
|
637
|
+
fetchOptions?: RequestInit;
|
|
638
|
+
/** Callback before request is sent */
|
|
639
|
+
onRequest?: (request: Request) => MaybePromise<Request | void | null | undefined>;
|
|
640
|
+
/** Callback after response is received */
|
|
641
|
+
onResponse?: (response: Response) => MaybePromise<Response | void | null | undefined>;
|
|
642
|
+
/** Callback on error during fetching */
|
|
643
|
+
onError?: (error: unknown) => MaybePromise<Error | void | null | undefined>;
|
|
662
644
|
});
|
|
663
645
|
}
|
|
664
646
|
```
|
|
665
647
|
|
|
666
648
|
#### WebSocket Transport
|
|
667
649
|
|
|
650
|
+
Uses [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) for requests. Supports
|
|
651
|
+
[subscriptions](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions) and
|
|
652
|
+
[post requests](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/post-requests).
|
|
653
|
+
|
|
668
654
|
**Features:**
|
|
669
655
|
|
|
670
|
-
- Uses [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) for requests.
|
|
671
|
-
- Supports [subscriptions](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions)
|
|
672
|
-
and [post requests](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/post-requests).
|
|
673
656
|
- Automatically restores connection after loss and resubscribes to previous subscriptions.
|
|
674
657
|
- Smart keep alive (pings only when idle).
|
|
675
658
|
- Lazy initialization with message buffering during connection establishment.
|
|
676
659
|
|
|
677
660
|
**Limitations:**
|
|
678
661
|
|
|
679
|
-
- Cannot mix api/explorer endpoints or mainnet/testnet in single connection. Need to
|
|
680
|
-
different endpoints.
|
|
681
|
-
- Cannot send explorer post-requests via WebSocket.
|
|
662
|
+
- 1 instance = 1 immutable endpoint. Cannot mix api/explorer endpoints or mainnet/testnet in single connection. Need to
|
|
663
|
+
create separate instances for different endpoints.
|
|
664
|
+
- Cannot send explorer post-requests via WebSocket.
|
|
682
665
|
|
|
683
666
|
```ts
|
|
684
667
|
class WebSocketTransport {
|
|
685
668
|
constructor(options?: {
|
|
686
|
-
|
|
687
|
-
isTestnet?: boolean;
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
669
|
+
/** Indicates this transport uses testnet endpoint (default: false) */
|
|
670
|
+
isTestnet?: boolean;
|
|
671
|
+
/**
|
|
672
|
+
* Custom WebSocket endpoint for API and Subscription requests.
|
|
673
|
+
* (default: `wss://api.hyperliquid.xyz` for mainnet, `wss://api.testnet.hyperliquid.xyz` for testnet)
|
|
674
|
+
*/
|
|
675
|
+
url?: string | URL;
|
|
676
|
+
/** Timeout for requests in ms (default: 10_000) */
|
|
677
|
+
timeout?: number;
|
|
678
|
+
/** Interval between sending ping messages in ms (default: 30_000) */
|
|
679
|
+
keepAliveInterval?: number;
|
|
680
|
+
/** Reconnection policy configuration for closed connections */
|
|
693
681
|
reconnect?: {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
682
|
+
/** Custom WebSocket constructor (default: global WebSocket) */
|
|
683
|
+
WebSocket?: new (url: string | URL) => WebSocket;
|
|
684
|
+
/** Maximum number of reconnection attempts (default: 3) */
|
|
685
|
+
maxRetries?: number;
|
|
686
|
+
/** Maximum time in ms to wait for a connection to open (default: 10_000) */
|
|
687
|
+
connectionTimeout?: number;
|
|
688
|
+
/** Delay before reconnection in ms (default: Exponential backoff (max 10s)) */
|
|
689
|
+
reconnectionDelay?: number | ((attempt: number) => number);
|
|
699
690
|
};
|
|
700
|
-
|
|
691
|
+
/** Enable automatic re-subscription to Hyperliquid subscription after reconnection (default: true) */
|
|
692
|
+
resubscribe?: boolean;
|
|
701
693
|
});
|
|
702
694
|
ready(signal?: AbortSignal): Promise<void>;
|
|
703
695
|
close(signal?: AbortSignal): Promise<void>;
|
|
704
696
|
}
|
|
705
697
|
```
|
|
706
698
|
|
|
699
|
+
### Errors
|
|
700
|
+
|
|
701
|
+
All SDK errors extend from `HyperliquidError` base class for unified error handling:
|
|
702
|
+
|
|
703
|
+
```ts
|
|
704
|
+
import { ApiRequestError, HyperliquidError, SchemaError, TransportError } from "@nktkas/hyperliquid";
|
|
705
|
+
|
|
706
|
+
try {
|
|
707
|
+
await exchClient.order({ ... });
|
|
708
|
+
} catch (error) {
|
|
709
|
+
if (error instanceof SchemaError) {
|
|
710
|
+
// Invalid data format (before sending request)
|
|
711
|
+
} else if (error instanceof ApiRequestError) {
|
|
712
|
+
// API returned error (e.g., insufficient funds)
|
|
713
|
+
} else if (error instanceof TransportError) {
|
|
714
|
+
// Network/connection failure (e.g., timeout)
|
|
715
|
+
} else if (error instanceof HyperliquidError) {
|
|
716
|
+
// Some other Hyperliquid SDK error
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
```
|
|
720
|
+
|
|
707
721
|
## Additional Import Points
|
|
708
722
|
|
|
709
723
|
### `/schemas`
|
|
@@ -743,7 +757,7 @@ Also valibot schema can be converted to JSON Schema:
|
|
|
743
757
|
import { OrderRequest } from "@nktkas/hyperliquid/schemas";
|
|
744
758
|
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
745
759
|
|
|
746
|
-
const schema = toJsonSchema(OrderRequest, { errorMode: "ignore" });
|
|
760
|
+
const schema = toJsonSchema(OrderRequest, { errorMode: "ignore", typeMode: "output" });
|
|
747
761
|
|
|
748
762
|
console.log(JSON.stringify(schema, null, 2));
|
|
749
763
|
// {
|
|
@@ -789,7 +803,7 @@ import { CancelRequest, parser } from "@nktkas/hyperliquid/schemas";
|
|
|
789
803
|
|
|
790
804
|
const privateKey = "0x..."; // `viem`, `ethers`, or private key directly
|
|
791
805
|
|
|
792
|
-
const action = parser(CancelRequest.entries.action)({ // for correct signature generation
|
|
806
|
+
const action = parser(CancelRequest.entries.action)({ // for correct signature generation (optional)
|
|
793
807
|
type: "cancel",
|
|
794
808
|
cancels: [
|
|
795
809
|
{ a: 0, o: 12345 },
|
|
@@ -816,7 +830,7 @@ import { ApproveAgentRequest, parser } from "@nktkas/hyperliquid/schemas";
|
|
|
816
830
|
|
|
817
831
|
const privateKey = "0x..."; // `viem`, `ethers`, or private key directly
|
|
818
832
|
|
|
819
|
-
const action = parser(ApproveAgentRequest.entries.action)({ // for correct signature generation
|
|
833
|
+
const action = parser(ApproveAgentRequest.entries.action)({ // for correct signature generation (optional)
|
|
820
834
|
type: "approveAgent",
|
|
821
835
|
signatureChainId: "0x66eee",
|
|
822
836
|
hyperliquidChain: "Mainnet",
|
|
@@ -859,19 +873,13 @@ with `tif: "Ioc"` and price that guarantee immediate execution:
|
|
|
859
873
|
- For buys: set limit price >= current best ask
|
|
860
874
|
- For sells: set limit price <= current best bid
|
|
861
875
|
|
|
862
|
-
### How to use the [Agent Wallet](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/nonces-and-api-wallets#api-wallets)
|
|
863
|
-
|
|
864
|
-
**Agent Wallet**: Use agent's private key in constructor instead of master account's private key.
|
|
865
|
-
|
|
866
|
-
**Vault and Sub-Account**: Pass vault or sub-account address via `vaultAddress` options to methods or set
|
|
867
|
-
`defaultVaultAddress` in constructor.
|
|
876
|
+
### How to use the [Agent Wallet](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/nonces-and-api-wallets#api-wallets) in [`ExchangeClient`](#exchangeclient)?
|
|
868
877
|
|
|
869
|
-
|
|
878
|
+
Use agent's private key in constructor instead of master account's private key.
|
|
870
879
|
|
|
871
|
-
[
|
|
880
|
+
### How to use the [Vault](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#subaccounts-and-vaults) / [Sub-Account](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#subaccounts-and-vaults) in [`ExchangeClient`](#exchangeclient)?
|
|
872
881
|
|
|
873
|
-
|
|
874
|
-
initializing the transport.
|
|
882
|
+
Pass vault or sub-account address via `vaultAddress` options to methods or set `defaultVaultAddress` in constructor.
|
|
875
883
|
|
|
876
884
|
## Contributing
|
|
877
885
|
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export type RawArgs = {
|
|
2
|
+
[key: string]: string | undefined;
|
|
3
|
+
} & {
|
|
4
|
+
_: string[];
|
|
5
|
+
};
|
|
6
|
+
export type ParseOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* Consider these keys as flags (no value expected).
|
|
9
|
+
* Value going after a flag will be treated as a positional argument.
|
|
10
|
+
*/
|
|
11
|
+
flags?: string[];
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Parse command-line arguments into a key-value object.
|
|
15
|
+
* Does not transform values.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseArgs(args: string[], options?: ParseOptions): RawArgs;
|
|
18
|
+
export interface TransformOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Transform rule for flags (keys without values).
|
|
21
|
+
* @value `undefined`
|
|
22
|
+
* @default "true"
|
|
23
|
+
*/
|
|
24
|
+
flag?: "true" | "false" | ((key: string) => "true" | "false");
|
|
25
|
+
/**
|
|
26
|
+
* Transform rule for null values.
|
|
27
|
+
* @value `"null"` (case insensitive)
|
|
28
|
+
* @default "null"
|
|
29
|
+
*/
|
|
30
|
+
null?: "null" | "string" | ((key: string, value: string) => "null" | "string");
|
|
31
|
+
/**
|
|
32
|
+
* Transform rule for boolean values.
|
|
33
|
+
* @value `"true"`, `"false"` (case insensitive)
|
|
34
|
+
* @default "bool"
|
|
35
|
+
*/
|
|
36
|
+
bool?: "bool" | "string" | ((key: string, value: string) => "bool" | "string");
|
|
37
|
+
/**
|
|
38
|
+
* Transform rule for hexadecimal values.
|
|
39
|
+
* @value `"0xff"`, `"0X1A"` (case insensitive) (0x prefix required)
|
|
40
|
+
* @default "string"
|
|
41
|
+
*/
|
|
42
|
+
hex?: "string" | "number" | ((key: string, value: string) => "string" | "number");
|
|
43
|
+
/**
|
|
44
|
+
* Transform rule for special numeric values.
|
|
45
|
+
* @value `"Infinity"`, `"-Infinity"`, `"NaN"`, `"-NaN"` (case insensitive)
|
|
46
|
+
* @default "string"
|
|
47
|
+
*/
|
|
48
|
+
specialNumber?: "string" | "number" | ((key: string, value: string) => "string" | "number");
|
|
49
|
+
/**
|
|
50
|
+
* Transform rule for numeric values.
|
|
51
|
+
* @value `"123"`, `"12.3"`, `"1e+2"`, `"+123"`, `"-123"` (anything that can be parsed by `Number(value)`) (excludes hex values)
|
|
52
|
+
* @default "number"
|
|
53
|
+
*/
|
|
54
|
+
number?: "number" | "string" | ((key: string, value: string) => "number" | "string");
|
|
55
|
+
/**
|
|
56
|
+
* Transform rule for JSON object/array values.
|
|
57
|
+
* @value `"{ \"a\": 1 }"`, `"[invalid array string]"` (anything that begins with `{` and ends with `}` or begins with `[` and ends with `]`)
|
|
58
|
+
* @default "object"
|
|
59
|
+
*/
|
|
60
|
+
json?: "object" | "string" | ((key: string, value: string) => "object" | "string");
|
|
61
|
+
}
|
|
62
|
+
export interface Args {
|
|
63
|
+
[key: string]: string | number | boolean | null | Record<string, unknown> | unknown[];
|
|
64
|
+
_: string[];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Transform raw args (string values) into typed args based on rules.
|
|
68
|
+
*
|
|
69
|
+
* Order of transformation:
|
|
70
|
+
* 1. flag (`undefined`)
|
|
71
|
+
* 2. null (`"null"`)
|
|
72
|
+
* 3. boolean (`"true"`, `"false"`)
|
|
73
|
+
* 4. hex (`"0x..."`)
|
|
74
|
+
* 5. special number (`"Infinity"`, `"-Infinity"`, `"NaN", "-NaN"`)
|
|
75
|
+
* 6. number (numeric strings)
|
|
76
|
+
* 7. json (object/array strings)
|
|
77
|
+
* 8. string (default)
|
|
78
|
+
*/
|
|
79
|
+
export declare function transformArgs(args: RawArgs, options?: TransformOptions): Args;
|
|
80
|
+
//# sourceMappingURL=_utils.d.ts.map
|
|
@@ -0,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CAAC;IAC5F;;;;OAIG;IACH,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,QAAQ,GAAG,QAAQ,CAAC,CAAC;IACrF;;;;OAIG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,QAAQ,GAAG,QAAQ,CAAC,CAAC;CACtF;AAED,MAAM,WAAW,IAAI;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,EAAE,CAAC;IACtF,CAAC,EAAE,MAAM,EAAE,CAAC;CACf;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAuE7E"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse command-line arguments into a key-value object.
|
|
3
|
+
* Does not transform values.
|
|
4
|
+
*/
|
|
5
|
+
export function parseArgs(args, options) {
|
|
6
|
+
const result = { _: [] };
|
|
7
|
+
for (let i = 0; i < args.length; i++) {
|
|
8
|
+
const arg = args[i];
|
|
9
|
+
const nextArg = args[i + 1];
|
|
10
|
+
if (arg.startsWith("-")) {
|
|
11
|
+
if (arg === "-_" || arg === "--_")
|
|
12
|
+
continue; // Skip reserved key "_"
|
|
13
|
+
const isLong = arg.startsWith("--");
|
|
14
|
+
let keyPart = arg.slice(isLong ? 2 : 1);
|
|
15
|
+
let value;
|
|
16
|
+
const eqIndex = keyPart.indexOf("=");
|
|
17
|
+
if (eqIndex !== -1) {
|
|
18
|
+
value = keyPart.substring(eqIndex + 1);
|
|
19
|
+
keyPart = keyPart.substring(0, eqIndex);
|
|
20
|
+
}
|
|
21
|
+
else if (!options?.flags?.includes(keyPart) && // Skip if key is defined as flag and don't expect value
|
|
22
|
+
typeof nextArg === "string" && (!nextArg.startsWith("-") || !isNaN(parseFloat(nextArg)))) {
|
|
23
|
+
value = nextArg;
|
|
24
|
+
i++; // Skip next arg as it's consumed as value for current key
|
|
25
|
+
}
|
|
26
|
+
result[keyPart] = value;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
result._.push(arg);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Transform raw args (string values) into typed args based on rules.
|
|
36
|
+
*
|
|
37
|
+
* Order of transformation:
|
|
38
|
+
* 1. flag (`undefined`)
|
|
39
|
+
* 2. null (`"null"`)
|
|
40
|
+
* 3. boolean (`"true"`, `"false"`)
|
|
41
|
+
* 4. hex (`"0x..."`)
|
|
42
|
+
* 5. special number (`"Infinity"`, `"-Infinity"`, `"NaN", "-NaN"`)
|
|
43
|
+
* 6. number (numeric strings)
|
|
44
|
+
* 7. json (object/array strings)
|
|
45
|
+
* 8. string (default)
|
|
46
|
+
*/
|
|
47
|
+
export function transformArgs(args, options) {
|
|
48
|
+
const opts = {
|
|
49
|
+
flag: "true",
|
|
50
|
+
null: "null",
|
|
51
|
+
bool: "bool",
|
|
52
|
+
hex: "string",
|
|
53
|
+
specialNumber: "string",
|
|
54
|
+
number: "number",
|
|
55
|
+
json: "object",
|
|
56
|
+
...options,
|
|
57
|
+
};
|
|
58
|
+
const result = { _: args._ };
|
|
59
|
+
for (const key in args) {
|
|
60
|
+
if (key === "_")
|
|
61
|
+
continue; // Skip the positional args array
|
|
62
|
+
const value = args[key];
|
|
63
|
+
// Transformation logic
|
|
64
|
+
let transformedValue;
|
|
65
|
+
// flag
|
|
66
|
+
if (value === undefined) {
|
|
67
|
+
const action = typeof opts.flag === "function" ? opts.flag(key) : opts.flag;
|
|
68
|
+
transformedValue = action === "true" ? true : false;
|
|
69
|
+
} // null
|
|
70
|
+
else if (value.toLowerCase() === "null") {
|
|
71
|
+
const action = typeof opts.null === "function" ? opts.null(key, value) : opts.null;
|
|
72
|
+
transformedValue = action === "null" ? null : value;
|
|
73
|
+
} // boolean
|
|
74
|
+
else if (value.toLowerCase() === "true" || value.toLowerCase() === "false") {
|
|
75
|
+
const action = typeof opts.bool === "function" ? opts.bool(key, value) : opts.bool;
|
|
76
|
+
transformedValue = action === "bool" ? value.toLowerCase() === "true" : value;
|
|
77
|
+
} // hex
|
|
78
|
+
else if ((value.startsWith("0x") || value.startsWith("0X")) && !isNaN(parseInt(value, 16))) {
|
|
79
|
+
const action = typeof opts.hex === "function" ? opts.hex(key, value) : opts.hex;
|
|
80
|
+
transformedValue = action === "string" ? value : parseInt(value, 16);
|
|
81
|
+
} // special number
|
|
82
|
+
else if (value.toLowerCase() === "infinity" || value.toLowerCase() === "-infinity" ||
|
|
83
|
+
value.toLowerCase() === "nan" || value.toLowerCase() === "-nan") {
|
|
84
|
+
const action = typeof opts.specialNumber === "function"
|
|
85
|
+
? opts.specialNumber(key, value)
|
|
86
|
+
: opts.specialNumber;
|
|
87
|
+
transformedValue = action === "string" ? value : Number(value);
|
|
88
|
+
} // number
|
|
89
|
+
else if (!isNaN(Number(value))) {
|
|
90
|
+
const action = typeof opts.number === "function" ? opts.number(key, value) : opts.number;
|
|
91
|
+
transformedValue = action === "number" ? Number(value) : value;
|
|
92
|
+
} // json object/array
|
|
93
|
+
else if ((value.startsWith("{") && value.endsWith("}")) ||
|
|
94
|
+
(value.startsWith("[") && value.endsWith("]"))) {
|
|
95
|
+
const action = typeof opts.json === "function" ? opts.json(key, value) : opts.json;
|
|
96
|
+
try {
|
|
97
|
+
transformedValue = action === "object"
|
|
98
|
+
? JSON.parse(value)
|
|
99
|
+
: value;
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
transformedValue = value;
|
|
103
|
+
}
|
|
104
|
+
} // string (default)
|
|
105
|
+
else {
|
|
106
|
+
transformedValue = value;
|
|
107
|
+
}
|
|
108
|
+
result[key] = transformedValue;
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=_utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_utils.js","sourceRoot":"","sources":["../../src/bin/_utils.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,IAAc,EAAE,OAAsB;IAC5D,MAAM,MAAM,GAAG,EAAE,CAAC,EAAE,EAAE,EAAwB,CAAC;IAC/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACnC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAuB,CAAC;QAElD,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,KAAK;gBAAE,SAAS,CAAC,wBAAwB;YAErE,MAAM,MAAM,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YACpC,IAAI,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACxC,IAAI,KAAyB,CAAC;YAC9B,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAErC,IAAI,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC;gBACjB,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;gBACvC,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YAC5C,CAAC;iBA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