@firtoz/websocket-do 2.0.0 → 3.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.
Files changed (2) hide show
  1. package/README.md +44 -13
  2. package/package.json +4 -5
package/README.md CHANGED
@@ -26,9 +26,17 @@ bun add @firtoz/websocket-do
26
26
  This package requires the following peer dependencies:
27
27
 
28
28
  ```bash
29
- bun add hono @cloudflare/workers-types @firtoz/hono-fetcher
29
+ bun add hono @firtoz/hono-fetcher
30
30
  ```
31
31
 
32
+ For TypeScript support, use `wrangler types` to generate accurate types from your `wrangler.jsonc`:
33
+
34
+ ```bash
35
+ wrangler types
36
+ ```
37
+
38
+ This generates `worker-configuration.d.ts` with types for your specific environment bindings, replacing the need for `@cloudflare/workers-types`.
39
+
32
40
  ## Quick Start
33
41
 
34
42
  ### 1. Define Your Message Types
@@ -115,16 +123,24 @@ export class ChatRoomDO extends BaseWebSocketDO<Env, ChatSession> {
115
123
 
116
124
  ### 4. Configure Your Worker
117
125
 
118
- ```typescript
119
- // wrangler.toml
120
- [[durable_objects.bindings]]
121
- name = "CHAT_ROOM"
122
- class_name = "ChatRoomDO"
123
- script_name = "your-worker-name"
124
-
125
- [[migrations]]
126
- tag = "v1"
127
- new_classes = ["ChatRoomDO"]
126
+ ```jsonc
127
+ // wrangler.jsonc
128
+ {
129
+ "durable_objects": {
130
+ "bindings": [
131
+ {
132
+ "name": "CHAT_ROOM",
133
+ "class_name": "ChatRoomDO"
134
+ }
135
+ ]
136
+ },
137
+ "migrations": [
138
+ {
139
+ "tag": "v1",
140
+ "new_classes": ["ChatRoomDO"]
141
+ }
142
+ ]
143
+ }
128
144
  ```
129
145
 
130
146
  ### 5. Access from Your Worker
@@ -135,8 +151,8 @@ export default {
135
151
  const url = new URL(request.url);
136
152
 
137
153
  if (url.pathname === '/chat') {
138
- const id = env.CHAT_ROOM.idFromName('global-chat');
139
- const stub = env.CHAT_ROOM.get(id);
154
+ // Use getByName() for deterministic DO routing (2025+ compatibility)
155
+ const stub = env.CHAT_ROOM.getByName('global-chat');
140
156
 
141
157
  // Proxy to the Durable Object
142
158
  return stub.fetch(request);
@@ -315,6 +331,21 @@ async handleMessage(message: ClientMessage): Promise<void> {
315
331
  }
316
332
  ```
317
333
 
334
+ ## Testing
335
+
336
+ This package includes comprehensive integration tests in a separate test package using `@cloudflare/vitest-pool-workers`, which provides full WebSocket testing capabilities in a Miniflare-based environment that closely mirrors production.
337
+
338
+ **What can be tested:**
339
+ - ✅ Worker routing to Durable Objects
340
+ - ✅ HTTP endpoints on DOs
341
+ - ✅ DO state management and isolation
342
+ - ✅ Full WebSocket connection lifecycle
343
+ - ✅ Real-time WebSocket message exchange
344
+ - ✅ WebSocket session management
345
+ - ✅ Type-safe DO client integration
346
+
347
+ For detailed information about testing capabilities, example implementations, comprehensive test coverage, and setup instructions, see the [websocket-do-test](../../tests/websocket-do-test/) package.
348
+
318
349
  ## License
319
350
 
320
351
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firtoz/websocket-do",
3
- "version": "2.0.0",
3
+ "version": "3.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",
@@ -21,9 +21,7 @@
21
21
  "typecheck": "tsc --noEmit",
22
22
  "lint": "biome check --write src",
23
23
  "lint:ci": "biome ci src",
24
- "format": "biome format src --write",
25
- "test": "bun test",
26
- "test:watch": "bun test --watch"
24
+ "format": "biome format src --write"
27
25
  },
28
26
  "keywords": [
29
27
  "typescript",
@@ -58,6 +56,7 @@
58
56
  "access": "public"
59
57
  },
60
58
  "devDependencies": {
61
- "bun-types": "^1.2.23"
59
+ "bun-types": "^1.3.0",
60
+ "typescript": "^5.9.3"
62
61
  }
63
62
  }