@firtoz/websocket-do 1.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 +48 -13
  2. package/package.json +8 -8
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @firtoz/websocket-do
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/%40firtoz%2Fwebsocket-do.svg)](https://www.npmjs.com/package/@firtoz/websocket-do)
4
+ [![npm downloads](https://img.shields.io/npm/dm/%40firtoz%2Fwebsocket-do.svg)](https://www.npmjs.com/package/@firtoz/websocket-do)
5
+ [![license](https://img.shields.io/npm/l/%40firtoz%2Fwebsocket-do.svg)](https://github.com/firtoz/fullstack-toolkit/blob/main/LICENSE)
6
+
3
7
  Type-safe WebSocket session management for Cloudflare Durable Objects with Hono integration.
4
8
 
5
9
  ## Features
@@ -22,9 +26,17 @@ bun add @firtoz/websocket-do
22
26
  This package requires the following peer dependencies:
23
27
 
24
28
  ```bash
25
- bun add hono @cloudflare/workers-types @firtoz/hono-fetcher
29
+ bun add hono @firtoz/hono-fetcher
26
30
  ```
27
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
+
28
40
  ## Quick Start
29
41
 
30
42
  ### 1. Define Your Message Types
@@ -111,16 +123,24 @@ export class ChatRoomDO extends BaseWebSocketDO<Env, ChatSession> {
111
123
 
112
124
  ### 4. Configure Your Worker
113
125
 
114
- ```typescript
115
- // wrangler.toml
116
- [[durable_objects.bindings]]
117
- name = "CHAT_ROOM"
118
- class_name = "ChatRoomDO"
119
- script_name = "your-worker-name"
120
-
121
- [[migrations]]
122
- tag = "v1"
123
- 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
+ }
124
144
  ```
125
145
 
126
146
  ### 5. Access from Your Worker
@@ -131,8 +151,8 @@ export default {
131
151
  const url = new URL(request.url);
132
152
 
133
153
  if (url.pathname === '/chat') {
134
- const id = env.CHAT_ROOM.idFromName('global-chat');
135
- 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');
136
156
 
137
157
  // Proxy to the Durable Object
138
158
  return stub.fetch(request);
@@ -311,6 +331,21 @@ async handleMessage(message: ClientMessage): Promise<void> {
311
331
  }
312
332
  ```
313
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
+
314
349
  ## License
315
350
 
316
351
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firtoz/websocket-do",
3
- "version": "1.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",
@@ -19,10 +19,9 @@
19
19
  ],
20
20
  "scripts": {
21
21
  "typecheck": "tsc --noEmit",
22
- "lint": "biome lint src --write",
23
- "format": "biome format src --write",
24
- "test": "bun test",
25
- "test:watch": "bun test --watch"
22
+ "lint": "biome check --write src",
23
+ "lint:ci": "biome ci src",
24
+ "format": "biome format src --write"
26
25
  },
27
26
  "keywords": [
28
27
  "typescript",
@@ -46,9 +45,9 @@
46
45
  "url": "https://github.com/firtoz/fullstack-toolkit/issues"
47
46
  },
48
47
  "peerDependencies": {
49
- "@cloudflare/workers-types": "^4.20251004.0",
48
+ "@cloudflare/workers-types": "^4.20251008.0",
50
49
  "@firtoz/hono-fetcher": "workspace:*",
51
- "hono": "^4.9.9"
50
+ "hono": "^4.9.10"
52
51
  },
53
52
  "engines": {
54
53
  "node": ">=18.0.0"
@@ -57,6 +56,7 @@
57
56
  "access": "public"
58
57
  },
59
58
  "devDependencies": {
60
- "bun-types": "^1.2.23"
59
+ "bun-types": "^1.3.0",
60
+ "typescript": "^5.9.3"
61
61
  }
62
62
  }