• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nktkas / hyperliquid / 19405103680

16 Nov 2025 11:46AM UTC coverage: 94.726% (-0.6%) from 95.329%
19405103680

push

github

nktkas
test(info): adapt command execution for Deno and Node.js environments

368 of 581 branches covered (63.34%)

Branch coverage included in aggregate %.

11667 of 12124 relevant lines covered (96.23%)

951.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.18
/src/api/_base.ts
1
// deno-lint-ignore-file no-explicit-any ban-types
2
import * as v from "valibot";
355✔
3
import { HyperliquidError } from "../_base.ts";
355✔
4

5
// -------------------- Types --------------------
6

7
export type MaybePromise<T> = T | Promise<T>;
8

9
export type Prettify<T> =
10
  & { [K in keyof T]: T[K] }
11
  & {};
12

13
export type DeepImmutable<T> = {
14
  readonly [K in keyof T]: DeepImmutable<T[K]>;
15
};
16

17
export type OmitFirst<T extends readonly any[]> = T extends readonly [any, ...infer R] ? R : [];
18

19
export type OverloadedParameters<T> = T extends {
20
  (...args: infer A1): unknown;
21
  (...args: infer A2): unknown;
22
  (...args: infer A3): unknown;
23
  (...args: infer A4): unknown;
24
} ? A1 | A2 | A3 | A4
25
  : T extends {
26
    (...args: infer A1): unknown;
27
    (...args: infer A2): unknown;
28
    (...args: infer A3): unknown;
29
  } ? A1 | A2 | A3
30
  : T extends {
31
    (...args: infer A1): unknown;
32
    (...args: infer A2): unknown;
33
  } ? A1 | A2
34
  : T extends (...args: infer A) => unknown ? A
35
  : never;
36

37
// -------------------- Schemas --------------------
38

39
export const UnsignedDecimal = /* @__PURE__ */ (() => {
355✔
40
  return v.pipe(
602✔
41
    v.union([v.string(), v.number()]),
2,408✔
42
    v.transform(String),
602✔
43
    v.string(),
602✔
44
    v.trim(),
602✔
45
    v.regex(/^[0-9]+(\.[0-9]+)?$/),
602✔
46
    v.transform((value) => formatDecimal(value)),
602✔
47
  );
48
})();
355✔
49
export type UnsignedDecimal = v.InferOutput<typeof UnsignedDecimal>;
50

51
export const Decimal = /* @__PURE__ */ (() => {
355✔
52
  return v.pipe(
602✔
53
    v.union([v.string(), v.number()]),
2,408✔
54
    v.transform(String),
602✔
55
    v.string(),
602✔
56
    v.trim(),
602✔
57
    v.regex(/^-?[0-9]+(\.[0-9]+)?$/),
602✔
58
    v.transform((value) => formatDecimal(value)),
602✔
59
  );
60
})();
355✔
61
export type Decimal = v.InferOutput<typeof Decimal>;
62

63
export const Integer = /* @__PURE__ */ (() => {
355✔
64
  return v.pipe(
602✔
65
    v.union([v.string(), v.number()]),
2,408✔
66
    v.transform(Number),
602✔
67
    v.number(),
602✔
68
    v.integer(),
602✔
69
    v.safeInteger(),
602✔
70
  );
71
})();
355✔
72
export type Integer = v.InferOutput<typeof Integer>;
73

74
export const UnsignedInteger = /* @__PURE__ */ (() => {
355✔
75
  return v.pipe(
602✔
76
    v.union([v.string(), v.number()]),
2,408✔
77
    v.transform(Number),
602✔
78
    v.number(),
602✔
79
    v.integer(),
602✔
80
    v.safeInteger(),
602✔
81
    v.minValue(0),
602✔
82
  );
83
})();
355✔
84
export type UnsignedInteger = v.InferOutput<typeof UnsignedInteger>;
85

86
export const Hex = /* @__PURE__ */ (() => {
355✔
87
  return v.pipe(
602✔
88
    v.string(),
602✔
89
    v.regex(/^0[xX][0-9a-fA-F]+$/),
602✔
90
    v.transform((value) => value.toLowerCase() as `0x${string}`),
602✔
91
  );
92
})();
355✔
93
export type Hex = v.InferOutput<typeof Hex>;
94

95
export const Address = /* @__PURE__ */ (() => {
355✔
96
  return v.pipe(Hex, v.length(42));
602✔
97
})();
355✔
98
export type Address = v.InferOutput<typeof Address>;
99

100
export const TokenId = /* @__PURE__ */ (() => {
355✔
101
  return v.pipe(
602✔
102
    v.string(),
602✔
103
    v.regex(/^[^:]+:0x[0-9a-fA-F]+$/),
602✔
104
    v.transform((value) => value as `${string}:${Hex}`),
602✔
105
  );
106
})();
355✔
107
export type TokenId = v.InferOutput<typeof TokenId>;
108

109
export const Percent = /* @__PURE__ */ (() => {
355✔
110
  return v.pipe(
602✔
111
    v.string(),
602✔
112
    v.regex(/^[0-9]+(\.[0-9]+)?%$/),
602✔
113
    v.transform((value) => value as `${string}%`),
602✔
114
  );
115
})();
355✔
116
export type Percent = v.InferOutput<typeof Percent>;
117

118
export const ISO8601WithoutTimezone = /* @__PURE__ */ (() => {
355✔
119
  return v.pipe(
602✔
120
    v.string(),
602✔
121
    v.regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[12]\d|0[1-9]|3[01])[T ](?:0\d|1\d|2[0-3])(?::[0-5]\d){2}(?:\.\d{1,9})?$/),
602✔
122
  );
123
})();
355✔
124
export type ISO8601WithoutTimezone = v.InferOutput<typeof ISO8601WithoutTimezone>;
125

126
/** Removes leading/trailing zeros from decimal string without precision loss. */
127
function formatDecimal(numStr: string): string {
355✔
128
  return numStr
538,216✔
129
    .trim()
538,216✔
130
    .replace(/^(-?)0+(?=\d)/, "$1") // Remove leading zeros, keep sign
538,216✔
131
    .replace(/(\.\d*?)0+$/, "$1") // Remove trailing zeros after decimal
538,216✔
132
    .replace(/\.$/, ""); // Remove lone decimal point
538,216✔
133
}
538,216✔
134

135
/** Thrown when validating invalid data.  */
136
export class SchemaError extends HyperliquidError {
355✔
137
  constructor(message: string) {
×
138
    super(message);
×
139
    this.name = "SchemaError";
×
140
  }
×
141
}
355✔
142

143
/**
144
 * Creates a valibot parser with summarized error messages.
145
 * Used for validating, formatting, and sorting object keys for correct signature generation.
146
 * @param schema - The valibot schema to validate against.
147
 * @returns A parser function that validates input against the schema.
148
 */
149
export function parser<TSchema extends v.GenericSchema>(schema: TSchema): v.Parser<TSchema, undefined> {
355✔
150
  const safeParser = v.safeParser(schema);
1,840✔
151
  const parser = (input: unknown) => {
1,840✔
152
    const result = safeParser(input);
3,325✔
153
    if (result.issues) throw new SchemaError("\n" + v.summarize(result.issues));
×
154
    return result.output;
3,325✔
155
  };
1,840✔
156
  parser.schema = schema;
1,840✔
157
  parser.config = undefined;
1,840✔
158
  return parser;
1,840✔
159
}
1,840✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc