Skip to content

Commit 2d3e4c6

Browse files
authored
fix(apps/hermes/client): use camelCase for streaming params (#1679)
* fix(apps/hermes/client): use camelCase for streaming params * remove console log * refactor * use hex as example
1 parent 9f415a3 commit 2d3e4c6

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

apps/hermes/client/js/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/hermes-client",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Pyth Hermes Client",
55
"author": {
66
"name": "Pyth Data Association"

apps/hermes/client/js/src/HermesClient.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import EventSource from "eventsource";
22
import { schemas } from "./zodSchemas";
33
import { z } from "zod";
4+
import { camelToSnakeCaseObject } from "./utils";
45

56
// Accessing schema objects
67
export type AssetType = z.infer<typeof schemas.AssetType>;
@@ -193,8 +194,8 @@ export class HermesClient {
193194
options?: {
194195
encoding?: EncodingType;
195196
parsed?: boolean;
196-
allow_unordered?: boolean;
197-
benchmarks_only?: boolean;
197+
allowUnordered?: boolean;
198+
benchmarksOnly?: boolean;
198199
}
199200
): Promise<EventSource> {
200201
const url = new URL("/v2/updates/price/stream", this.baseURL);
@@ -203,7 +204,8 @@ export class HermesClient {
203204
});
204205

205206
if (options) {
206-
this.appendUrlSearchParams(url, options);
207+
const transformedOptions = camelToSnakeCaseObject(options);
208+
this.appendUrlSearchParams(url, transformedOptions);
207209
}
208210

209211
return new EventSource(url.toString());

apps/hermes/client/js/src/examples/HermesClient.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ async function run() {
4545
console.log(priceUpdates);
4646

4747
// Streaming price updates
48-
const eventSource = await connection.getPriceUpdatesStream(priceIds);
48+
const eventSource = await connection.getPriceUpdatesStream(priceIds, {
49+
encoding: "hex",
50+
parsed: true,
51+
allowUnordered: true,
52+
benchmarksOnly: true,
53+
});
4954

5055
eventSource.onmessage = (event) => {
5156
console.log("Received price update:", event.data);

apps/hermes/client/js/src/utils.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function camelToSnakeCase(str: string): string {
2+
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
3+
}
4+
5+
export function camelToSnakeCaseObject(
6+
obj: Record<string, string | boolean>
7+
): Record<string, string | boolean> {
8+
const result: Record<string, string | boolean> = {};
9+
Object.keys(obj).forEach((key) => {
10+
result[camelToSnakeCase(key)] = obj[key];
11+
});
12+
return result;
13+
}

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)