A generic websocket connection with Zod schema validation and on message execution.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add setParams function

vinerima 4ea75d20 968bca18

+30 -1
+1 -1
package.json
··· 1 1 { 2 2 "name": "@vinerima/wah", 3 - "version": "2.0.0", 3 + "version": "2.0.1", 4 4 "description": "Generic WebSocket action handler with Zod-based schema validation and typed message dispatch", 5 5 "author": "vinerima", 6 6 "license": "MIT",
+19
src/WebSocketClient.ts
··· 131 131 } 132 132 133 133 /** 134 + * Merges new query parameters without triggering a reconnection. 135 + * The updated params take effect on the next connection attempt 136 + * (e.g., when the built-in reconnection fires after a disconnect). 137 + * 138 + * @param params - Key-value pairs to merge into the current query parameters. 139 + * 140 + * @example 141 + * ```typescript 142 + * // Update cursor on disconnect so reconnection resumes from last position 143 + * client.on("close", () => { 144 + * client.setParams({ cursor: lastEventId }); 145 + * }); 146 + * ``` 147 + */ 148 + setParams(params: Record<string, string | number | boolean>): void { 149 + this.connection.setParams(params); 150 + } 151 + 152 + /** 134 153 * Returns a read-only snapshot of the current connection state. 135 154 */ 136 155 getConnectionInfo(): ConnectionInfo {
+10
src/connection/WebSocketConnection.ts
··· 119 119 } 120 120 121 121 /** 122 + * Merges new query parameters without triggering a reconnection. 123 + * The updated params will take effect on the next connection attempt 124 + * (e.g., after a disconnect triggers the built-in reconnection). 125 + */ 126 + setParams(params: Record<string, string | number | boolean>): void { 127 + this.queryParams = { ...this.queryParams, ...params }; 128 + this.logger.debug("Query params set (no reconnect)", { params: this.queryParams }); 129 + } 130 + 131 + /** 122 132 * Returns a read-only snapshot of the current connection state. 123 133 */ 124 134 getConnectionInfo(): ConnectionInfo {