durablews 2.0.0-alpha.0 → 2.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/README.md +52 -34
- package/package.json +37 -2
package/README.md
CHANGED
|
@@ -1,44 +1,48 @@
|
|
|
1
1
|
# DurableWS
|
|
2
2
|
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
-
|
|
28
|
-
|
|
29
|
-
|
|
3
|
+
> The WebSocket client that survives the real world — automatic reconnection,
|
|
4
|
+
> bounded queueing, and typed messages. Zero dependencies, every modern
|
|
5
|
+
> runtime, durable by default.
|
|
6
|
+
|
|
7
|
+
> ⚠️ **v2 is in alpha** (`npm install durablews@alpha`). The features below
|
|
8
|
+
> are built and tested (unit, integration, real-browser e2e); the API may
|
|
9
|
+
> still shift before 2.0. The
|
|
10
|
+
> [architecture RFC](https://github.com/imnsco/DurableWS/blob/main/rfcs/0001-v2-architecture.md)
|
|
11
|
+
> tracks design and status. The `1.x` release predates this rewrite — don't
|
|
12
|
+
> use it.
|
|
13
|
+
|
|
14
|
+
## What you get
|
|
15
|
+
|
|
16
|
+
- **Automatic reconnection, on by default** — full-jitter exponential
|
|
17
|
+
backoff, unlimited retries, a `shouldReconnect` veto, and `reconnecting`
|
|
18
|
+
events for your UI.
|
|
19
|
+
- **Message queueing while disconnected, on by default** — bounded,
|
|
20
|
+
drop-oldest, flushed in order on open. Every dropped message fires a `drop`
|
|
21
|
+
event; nothing is silently lost.
|
|
22
|
+
- **Opt-in heartbeat / idle detection** — quietly-dead links are closed (code
|
|
23
|
+
`4408`) and recovered through the normal reconnect machinery.
|
|
24
|
+
- **Typed + validated messages** — pass any
|
|
25
|
+
[Standard Schema](https://standardschema.dev) (zod, valibot, arktype, …)
|
|
26
|
+
and inbound messages are type-inferred *and* runtime-validated.
|
|
27
|
+
- **Middleware, inbound and outbound** — an onion pipeline with async-safe,
|
|
28
|
+
ordered outbound execution (auth/token-refresh ready).
|
|
29
|
+
- **Pluggable codec** — JSON by default; swap in msgpack or anything else.
|
|
30
|
+
- **Vue & React bindings in the box** — `durablews/vue` (composable) and
|
|
31
|
+
`durablews/react` (hook); the frameworks are optional peers.
|
|
32
|
+
- **A drop-in `WebSocket` class** — `durablews/compat` for one-line migration
|
|
33
|
+
or `webSocketImpl` injection, with a published known-deviations table.
|
|
34
|
+
- **Zero runtime dependencies**, built on the standard global `WebSocket`.
|
|
30
35
|
|
|
31
36
|
## Requirements
|
|
32
37
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
-
|
|
36
|
-
|
|
38
|
+
- **Node.js ≥ 22** — the first release where the global `WebSocket` is
|
|
39
|
+
available unflagged. (There is no `ws` dependency, by design.)
|
|
40
|
+
- Any modern runtime with a global `WebSocket`: current browsers, Deno, Bun,
|
|
41
|
+
and Cloudflare Workers.
|
|
37
42
|
|
|
38
43
|
## Installation
|
|
39
44
|
|
|
40
45
|
```bash
|
|
41
|
-
# v2 is not yet published; once the alpha ships it will be:
|
|
42
46
|
npm install durablews@alpha
|
|
43
47
|
```
|
|
44
48
|
|
|
@@ -60,10 +64,24 @@ client.send({ type: "hello", message: "world" });
|
|
|
60
64
|
client.close();
|
|
61
65
|
```
|
|
62
66
|
|
|
67
|
+
Typed and validated, with any Standard Schema:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { z } from "zod";
|
|
71
|
+
|
|
72
|
+
const Message = z.object({ type: z.string(), body: z.string() });
|
|
73
|
+
const client = defineClient({ url, schema: Message });
|
|
74
|
+
|
|
75
|
+
client.on("message", (msg) => {
|
|
76
|
+
// msg: { type: string; body: string } — validated at runtime
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
63
80
|
## Documentation
|
|
64
81
|
|
|
65
|
-
|
|
66
|
-
|
|
82
|
+
**[durablews.imns.co](https://durablews.imns.co)** — getting started, guides
|
|
83
|
+
(durability tuning, middleware, codecs, drop-in compat), framework pages, the
|
|
84
|
+
API reference, and an honest comparison with the alternatives.
|
|
67
85
|
|
|
68
86
|
## Contributing
|
|
69
87
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "durablews",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A resilient, TypeScript-based WebSocket client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -104,6 +104,7 @@
|
|
|
104
104
|
"devDependencies": {
|
|
105
105
|
"@arethetypeswrong/cli": "^0.18.3",
|
|
106
106
|
"@playwright/test": "^1.60.0",
|
|
107
|
+
"@size-limit/preset-small-lib": "^12.1.0",
|
|
107
108
|
"@testing-library/react": "^16.3.2",
|
|
108
109
|
"@types/node": "^22.19.20",
|
|
109
110
|
"@types/react": "^19.2.17",
|
|
@@ -113,6 +114,7 @@
|
|
|
113
114
|
"publint": "^0.3.21",
|
|
114
115
|
"react": "^19.2.7",
|
|
115
116
|
"react-dom": "^19.2.7",
|
|
117
|
+
"size-limit": "^12.1.0",
|
|
116
118
|
"tsup": "^8.5.1",
|
|
117
119
|
"typescript": "^5.3.3",
|
|
118
120
|
"vitest": "^1.2.2",
|
|
@@ -120,6 +122,38 @@
|
|
|
120
122
|
"vue": "^3.5.35",
|
|
121
123
|
"ws": "^8.21.0"
|
|
122
124
|
},
|
|
125
|
+
"size-limit": [
|
|
126
|
+
{
|
|
127
|
+
"name": "core (durablews)",
|
|
128
|
+
"path": "dist/index.js",
|
|
129
|
+
"limit": "3 KB",
|
|
130
|
+
"brotli": true
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"name": "durablews/vue",
|
|
134
|
+
"path": "dist/vue.js",
|
|
135
|
+
"limit": "3.5 KB",
|
|
136
|
+
"brotli": true,
|
|
137
|
+
"ignore": [
|
|
138
|
+
"vue"
|
|
139
|
+
]
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"name": "durablews/react",
|
|
143
|
+
"path": "dist/react.js",
|
|
144
|
+
"limit": "3.5 KB",
|
|
145
|
+
"brotli": true,
|
|
146
|
+
"ignore": [
|
|
147
|
+
"react"
|
|
148
|
+
]
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"name": "durablews/compat",
|
|
152
|
+
"path": "dist/compat.js",
|
|
153
|
+
"limit": "4 KB",
|
|
154
|
+
"brotli": true
|
|
155
|
+
}
|
|
156
|
+
],
|
|
123
157
|
"scripts": {
|
|
124
158
|
"build": "tsup",
|
|
125
159
|
"test": "vitest",
|
|
@@ -128,6 +162,7 @@
|
|
|
128
162
|
"e2e:install": "playwright install --with-deps chromium",
|
|
129
163
|
"typecheck": "tsc --noEmit",
|
|
130
164
|
"typecheck:next": "pnpm --package=typescript@next dlx tsc --noEmit",
|
|
131
|
-
"check:publish": "publint && attw --pack . --profile node16"
|
|
165
|
+
"check:publish": "publint && attw --pack . --profile node16",
|
|
166
|
+
"size": "size-limit"
|
|
132
167
|
}
|
|
133
168
|
}
|