@firtoz/websocket-do 4.0.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firtoz/websocket-do",
3
- "version": "4.0.0",
3
+ "version": "6.0.0",
4
4
  "description": "Type-safe WebSocket session management for Cloudflare Durable Objects with Hono integration",
5
5
  "main": "./src/index.ts",
6
6
  "module": "./src/index.ts",
@@ -18,7 +18,7 @@
18
18
  "README.md"
19
19
  ],
20
20
  "scripts": {
21
- "typecheck": "tsc --noEmit",
21
+ "typecheck": "tsc --noEmit -p ./tsconfig.json",
22
22
  "lint": "biome check --write src",
23
23
  "lint:ci": "biome ci src",
24
24
  "format": "biome format src --write"
@@ -47,7 +47,7 @@
47
47
  "peerDependencies": {
48
48
  "@cloudflare/workers-types": "^4.20251008.0",
49
49
  "@firtoz/hono-fetcher": "workspace:*",
50
- "hono": "^4.9.10"
50
+ "hono": "^4.10.1"
51
51
  },
52
52
  "optionalDependencies": {
53
53
  "msgpackr": "^1.11.5",
package/src/ZodSession.ts CHANGED
@@ -9,9 +9,13 @@ export interface ZodSessionOptions<TClientMessage, TServerMessage> {
9
9
  }
10
10
 
11
11
  export abstract class ZodSession<
12
+ // biome-ignore lint/suspicious/noExplicitAny: We need to allow any for the environment
12
13
  TEnv extends object = any,
14
+ // biome-ignore lint/suspicious/noExplicitAny: We need to allow any for the data
13
15
  TData = any,
16
+ // biome-ignore lint/suspicious/noExplicitAny: We need to allow any for the server message
14
17
  TServerMessage = any,
18
+ // biome-ignore lint/suspicious/noExplicitAny: We need to allow any for the client message
15
19
  TClientMessage = any,
16
20
  > extends BaseSession<TEnv, TData, TServerMessage, TClientMessage> {
17
21
  protected readonly clientCodec: ReturnType<typeof zodMsgpack<TClientMessage>>;
@@ -18,7 +18,7 @@ export interface ZodWebSocketClientOptions<TClientMessage, TServerMessage> {
18
18
  onOpen?: (event: Event) => void;
19
19
  onClose?: (event: CloseEvent) => void;
20
20
  onError?: (event: Event) => void;
21
- onValidationError?: (error: unknown, rawMessage: unknown) => void;
21
+ onValidationError?: (error: Error, rawMessage: unknown) => void;
22
22
  }
23
23
 
24
24
  export class ZodWebSocketClient<TClientMessage, TServerMessage> {
@@ -28,7 +28,7 @@ export class ZodWebSocketClient<TClientMessage, TServerMessage> {
28
28
  private readonly enableBufferMessages: boolean;
29
29
  private readonly onMessageCallback?: (message: TServerMessage) => void;
30
30
  private readonly onValidationError?: (
31
- error: unknown,
31
+ error: Error,
32
32
  rawMessage: unknown,
33
33
  ) => void;
34
34
 
@@ -116,7 +116,10 @@ export class ZodWebSocketClient<TClientMessage, TServerMessage> {
116
116
  this.onMessageCallback?.(parsedMessage);
117
117
  } catch (error) {
118
118
  console.error("Failed to process message:", error);
119
- this.onValidationError?.(error, event.data);
119
+ this.onValidationError?.(
120
+ error instanceof Error ? error : new Error(String(error)),
121
+ event.data,
122
+ );
120
123
  }
121
124
  }
122
125
 
@@ -3,8 +3,11 @@ import type { ZodSession, ZodSessionOptions } from "./ZodSession";
3
3
 
4
4
  export abstract class ZodWebSocketDO<
5
5
  TEnv extends object,
6
+ // biome-ignore lint/suspicious/noExplicitAny: We need to allow any for the session
6
7
  TSession extends ZodSession<TEnv, any, any, any>,
8
+ // biome-ignore lint/suspicious/noExplicitAny: We need to allow any for the client message
7
9
  TClientMessage = any,
10
+ // biome-ignore lint/suspicious/noExplicitAny: We need to allow any for the server message
8
11
  TServerMessage = any,
9
12
  > extends BaseWebSocketDO<TEnv, TSession> {
10
13
  protected abstract getZodOptions(): ZodSessionOptions<