From dca7ea57076f7b99d39b7aa8566ccd19f7abe606 Mon Sep 17 00:00:00 2001 From: wisplite Date: Thu, 23 Apr 2026 08:54:13 -0500 Subject: [PATCH] fix json parsing error --- dist/index.js | 4 ++-- dist/utils/websocket.d.ts | 2 +- dist/utils/websocket.js | 2 +- src/index.ts | 4 ++-- src/utils/websocket.ts | 5 +++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index a12e368..6d8782d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -47,8 +47,8 @@ export class TetherClient { mutation_id: mutation_id })); return new Promise((resolve, reject) => { - this.websocketHandler.onMutation = (data) => { - if (data.mutation_id === mutation_id) { + this.websocketHandler.onMutation = (mutation_id, data) => { + if (mutation_id === mutation_id) { resolve(data); } }; diff --git a/dist/utils/websocket.d.ts b/dist/utils/websocket.d.ts index 4d1bb25..46b254c 100644 --- a/dist/utils/websocket.d.ts +++ b/dist/utils/websocket.d.ts @@ -8,7 +8,7 @@ export declare class WebSocketHandler { private maxReconnectAttempts; private reconnectInterval; private sendQueue; - onMutation: (data: any) => void; + onMutation: (mutation_id: string, data: any) => void; startConnection: (url: string) => void; attemptReconnect: () => void; close: () => void; diff --git a/dist/utils/websocket.js b/dist/utils/websocket.js index 62f30ab..6a89d86 100644 --- a/dist/utils/websocket.js +++ b/dist/utils/websocket.js @@ -28,7 +28,7 @@ export class WebSocketHandler { this.onQuery(data.location, data.data); } else if (data.type === 'mutation') { - this.onMutation(data.data); + this.onMutation(data.mutation_id || '', data.data); } else if (data.type === 'error') { console.error(data.error); diff --git a/src/index.ts b/src/index.ts index 43a6d84..132236b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -52,8 +52,8 @@ export class TetherClient { mutation_id: mutation_id })); return new Promise((resolve, reject) => { - this.websocketHandler.onMutation = (data) => { - if (data.mutation_id === mutation_id) { + this.websocketHandler.onMutation = (mutation_id: string, data: any) => { + if (mutation_id === mutation_id) { resolve(data); } }; diff --git a/src/utils/websocket.ts b/src/utils/websocket.ts index 6208db0..12e3fe9 100644 --- a/src/utils/websocket.ts +++ b/src/utils/websocket.ts @@ -8,7 +8,7 @@ export class WebSocketHandler { private maxReconnectAttempts: number = 5; private reconnectInterval: number = 1000; private sendQueue: string[] = []; - public onMutation: (data: any) => void = () => {}; + public onMutation: (mutation_id: string, data: any) => void = () => {}; startConnection = (url: string) => { this.url = url; this.ws = new WebSocket(url); @@ -30,11 +30,12 @@ export class WebSocketHandler { location?: string; data?: unknown; error?: string; + mutation_id?: string; }; if (data.type === 'query') { this.onQuery(data.location, data.data); } else if (data.type === 'mutation') { - this.onMutation(data.data); + this.onMutation(data.mutation_id || '', data.data); } else if (data.type === 'error') { console.error(data.error); }