View Source mix hyperliquid.gen.schemas (hyperliquid v0.2.2)
Generates Elixir Ecto schemas from the @nktkas/hyperliquid TypeScript SDK.
This task helps maintain type parity between the TypeScript SDK and the Elixir implementation by parsing Valibot schemas and generating equivalent Ecto schemas.
Usage
# Generate all schemas
mix hyperliquid.gen.schemas
# Generate specific category
mix hyperliquid.gen.schemas --category=subscription
# Generate specific endpoint
mix hyperliquid.gen.schemas --endpoint=webData2
# Dry run (don't write files)
mix hyperliquid.gen.schemas --dry-runOptions
--category- Generate schemas for a specific category (info, exchange, subscription)--endpoint- Generate schema for a specific endpoint--dry-run- Show what would be generated without writing files--ts-sdk-path- Path to the TypeScript SDK repository (default: ../../../@nktkas_hyperliquid)
Examples
# Generate all subscription schemas
mix hyperliquid.gen.schemas --category=subscription
# Generate only webData2 schema
mix hyperliquid.gen.schemas --endpoint=webData2 --category=subscription
# Preview changes without writing
mix hyperliquid.gen.schemas --dry-runArchitecture
This generator:
- Reads TypeScript files from the @nktkas/hyperliquid SDK
- Parses Valibot schemas to extract type information
- Generates Elixir Ecto embedded schemas
- Writes single-file modules with all nested schemas
- Tracks SDK version for future sync checks
Type Mapping
The following TypeScript/Valibot types are mapped to Elixir/Ecto:
v.string()→:stringv.number()/UnsignedInteger→:integerv.boolean()→:booleanUnsignedDecimal/Decimal→:string(for precision)v.array(...)→{:array, type}orembeds_manyv.object(...)→embeds_oneorembeds_manyv.record(...)→:mapv.union([...])→:stringwith validationAddress→:stringwith regex validationHex→:string
Generated File Structure
lib/hyperliquid/api/
├── info/
│ ├── all_mids.ex
│ ├── clearinghouse_state.ex
│ └── ...
├── exchange/
│ ├── order.ex
│ ├── cancel.ex
│ └── ...
└── subscription/
├── web_data2.ex
├── web_data3.ex
└── ...Each file contains:
- Request parameter schema
- Response/Event schema with embedded nested types
- Changesets for validation
- Helper functions
- Usage examples in @moduledoc
Summary
Functions
Callback implementation for Mix.Task.run/1.
Functions
Callback implementation for Mix.Task.run/1.