@super-line/server 0.8.0 → 0.10.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 -2
- package/dist/index.cjs +351 -16482
- package/dist/index.d.cts +180 -22
- package/dist/index.d.ts +180 -22
- package/dist/index.js +320 -207
- package/package.json +10 -9
- package/dist/arktype-aI7TBD0R-QUZZIMBF.js +0 -9
- package/dist/chunk-BXHVPS35.js +0 -164
- package/dist/chunk-MLKGABMK.js +0 -9
- package/dist/core-DXJRFNRR.js +0 -9858
- package/dist/dist-S566F7HE.js +0 -9
- package/dist/effect-QlVUlMFu-XUZCEH2A.js +0 -17
- package/dist/esm-F5WYXMGY.js +0 -5222
- package/dist/sury-CWZTCd75-XRKNS4FU.js +0 -17
- package/dist/typebox-Dei93FPO-EURKZGC4.js +0 -9
- package/dist/valibot--1zFm7rT-CYY6WSKB.js +0 -17
- package/dist/zod-Bwrt9trS-3RR2G3Z5.js +0 -31
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @super-line/server
|
|
2
2
|
|
|
3
|
-
The server for [**super-line**](https://mertdogar.github.io/super-line/) —
|
|
3
|
+
The server for [**super-line**](https://mertdogar.github.io/super-line/) — the strictly-typed realtime data bus for TypeScript. Implements a shared contract over any transport: role-keyed request handlers, rooms, topics, synced state, middleware, lifecycle hooks, and node-to-node messaging. WebSocket is the default wire; HTTP/SSE, libp2p, and loopback are alternatives.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
pnpm add @super-line/core @super-line/server @super-line/transport-websocket zod
|
|
@@ -30,7 +30,57 @@ srv.implement({
|
|
|
30
30
|
server.listen(3000)
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
Authenticate receives the `Handshake` (`{ transport, headers, query, peer?, raw }`) and returns `{ role, ctx }`; cross-role calls are rejected with `NOT_FOUND`. The wire is carried by a pluggable transport — [`@super-line/transport-websocket`](https://www.npmjs.com/package/@super-line/transport-websocket) provides the WS transport shown above;
|
|
33
|
+
Authenticate receives the `Handshake` (`{ transport, headers, query, peer?, raw }`) and returns `{ role, ctx }`; cross-role calls are rejected with `NOT_FOUND`. The wire is carried by a pluggable transport — [`@super-line/transport-websocket`](https://www.npmjs.com/package/@super-line/transport-websocket) provides the WS transport shown above; HTTP/SSE ([`transport-http`](https://www.npmjs.com/package/@super-line/transport-http)), libp2p ([`transport-libp2p`](https://www.npmjs.com/package/@super-line/transport-libp2p)), and in-memory ([`transport-loopback`](https://www.npmjs.com/package/@super-line/transport-loopback)) are alternatives — see the Transports guide.
|
|
34
|
+
|
|
35
|
+
### Cluster event bus
|
|
36
|
+
|
|
37
|
+
`srv.publish(topic, data)` / `srv.subscribe(topic, handler)` is a server-side pub/sub over a shared contract topic. The callback fires for a publish from any node — including this one (local echo, in-process, no round-trip). `meta.from` is the publishing node; self-exclude with `if (meta.from === srv.nodeId) return`.
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
const off = srv.subscribe('orders', (order, meta) => {
|
|
41
|
+
if (meta.from === srv.nodeId) return // skip our own echo
|
|
42
|
+
// react to an order published on another node
|
|
43
|
+
})
|
|
44
|
+
srv.publish('orders', { id: '...', total: 42 })
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Cross-node fan-out (rooms, topics, the bus, targeted `toConn`/`toUser`, and store changes) rides a pluggable `adapter`. Defaults to an in-memory adapter (single process); for a cluster pass one of [`adapter-redis`](https://www.npmjs.com/package/@super-line/adapter-redis), [`adapter-libp2p`](https://www.npmjs.com/package/@super-line/adapter-libp2p), [`adapter-rabbitmq`](https://www.npmjs.com/package/@super-line/adapter-rabbitmq), or [`adapter-zeromq`](https://www.npmjs.com/package/@super-line/adapter-zeromq).
|
|
48
|
+
|
|
49
|
+
### Synced state (stores)
|
|
50
|
+
|
|
51
|
+
Pass server-side `stores` and the server becomes authoritative over persisted, reactive Resources — clients open the matching client halves. The store decides the consistency model (LWW or CRDT), durability (in-memory / SQLite / libsql / Postgres), and clustering (`relay` fans out over the adapter; `self` owns a central backend + per-node replica, no adapter). The default pair is [`@super-line/store-memory`](https://www.npmjs.com/package/@super-line/store-memory) (LWW · in-memory · relay).
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { memoryStoreServer } from '@super-line/store-memory'
|
|
55
|
+
|
|
56
|
+
const srv = createSuperLineServer(api, {
|
|
57
|
+
transports: [webSocketServerTransport({ server })],
|
|
58
|
+
authenticate,
|
|
59
|
+
stores: { docs: memoryStoreServer() },
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const docs = srv.store('docs') // ServerStoreHandle — throws NOT_FOUND if unconfigured
|
|
63
|
+
await docs.create('intro', { title: 'Hi' }, { 'user:1': { read: true, write: true } })
|
|
64
|
+
await docs.grant('intro', 'user:2', { read: true })
|
|
65
|
+
await docs.write('intro', { title: 'Updated' }) // LWW co-write, fanned out with a `server` origin
|
|
66
|
+
await docs.delete('intro') // publishes a cluster-wide deletion (sdel) to every subscriber
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`ServerStoreHandle`: `create` / `read` / `write` / `grant` / `revoke` / `delete` / `list`. For a reactive in-process co-writer, `open(id)` returns a `ServerReplica` — the server half's mirror of the client's `store(ns).open(id)`:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
const replica = srv.store('docs').open('intro', { origin: 'agent' })
|
|
73
|
+
replica.subscribe(() => console.log(replica.getSnapshot()))
|
|
74
|
+
replica.update({ title: 'Live' }) // merge
|
|
75
|
+
replica.delete('title') // surgical key delete (the only way to remove a key server-side)
|
|
76
|
+
replica.close()
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`open` requires a store with reactive support (throws `UNSUPPORTED` otherwise). CRDT stores (`store-sync`, `store-sync-libsql`, `store-sync-pglite`) and the LWW stores both back it.
|
|
80
|
+
|
|
81
|
+
### Control Center inspector
|
|
82
|
+
|
|
83
|
+
Mount `plugins: [inspector()]` (from [`@super-line/plugin-inspector`](https://www.npmjs.com/package/@super-line/plugin-inspector); `inspector({ redact: ['password', 'token'] })` to mask fields) to emit `msg.*` telemetry and accept read-only [Control Center](https://www.npmjs.com/package/@super-line/control-center) clients. The plugin declares the reserved connection class the WS transport negotiates. **Default off; dev / trusted-network only.**
|
|
34
84
|
|
|
35
85
|
- 📖 Docs: <https://mertdogar.github.io/super-line/>
|
|
36
86
|
- 📚 Guides: [roles & auth](https://mertdogar.github.io/super-line/guide/roles-auth), [events & rooms](https://mertdogar.github.io/super-line/guide/events-rooms)
|