durablews 2.0.0-alpha.0 → 2.0.0-alpha.1
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 +1 -1
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
|
|