@greendrake/rpc-server 0.3.0 → 0.4.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 +3 -5
- package/package.json +3 -3
- package/src/types.ts +2 -2
package/README.md
CHANGED
|
@@ -46,8 +46,6 @@ Bun.serve({
|
|
|
46
46
|
})
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
[`@greendrake/server`](../server) wraps that last call with health probes, CORS and a graceful-shutdown sequence; nothing here requires it.
|
|
50
|
-
|
|
51
49
|
## Methods
|
|
52
50
|
|
|
53
51
|
A `MethodDef` is what a method requires of its caller, what its argument looks like, and what runs:
|
|
@@ -113,11 +111,11 @@ A codec applies to everything on the wire, in both directions, for a service who
|
|
|
113
111
|
|
|
114
112
|
```ts
|
|
115
113
|
registry.emitToUser(userId, 'thread.updated', { id }) // {type:'event', event, data} to that user's sockets
|
|
116
|
-
registry.broadcastEvent('
|
|
114
|
+
registry.broadcastEvent('job.progress', progress) // …to every socket
|
|
117
115
|
registry.broadcastData('telemetry', reading) // the bare {type, data} form
|
|
118
116
|
```
|
|
119
117
|
|
|
120
|
-
Push-producing code takes the `EventSink` interface (`emitToUser` + `broadcastEvent`) rather than the class, so it can be driven by anything. On the client, `@greendrake/rpc`'s `liveBinding`
|
|
118
|
+
Push-producing code takes the `EventSink` interface (`emitToUser` + `broadcastEvent`) rather than the class, so it can be driven by anything. On the client, `@greendrake/rpc`'s `liveBinding` subscribes to these, folds each push in or re-reads, and re-reads again after a dropped socket returns.
|
|
121
119
|
|
|
122
120
|
## Error codes
|
|
123
121
|
|
|
@@ -140,7 +138,7 @@ By convention a code ending `_NOT_FOUND` becomes a `NotFoundError` client-side,
|
|
|
140
138
|
|
|
141
139
|
## The pair's typing
|
|
142
140
|
|
|
143
|
-
`ClientMethods<M>` turns a dispatch table into the method map a client hands `RpcClient
|
|
141
|
+
`ClientMethods<M>` turns a dispatch table into the method map a client hands `RpcClient`, or any typed client built on it:
|
|
144
142
|
|
|
145
143
|
```ts
|
|
146
144
|
export const methods = { /* … */ }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@greendrake/rpc-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "RPC server over JSON for bun: method dispatch with auth, nonce and Standard Schema argument validation, HTTP and WebSocket transports, connection registry and server push",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Eugene Greendrake <eugene@greendrake.nz>",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
},
|
|
35
35
|
"prettier": "@greendrake/dev-config/prettier",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@greendrake/rpc": "0.
|
|
37
|
+
"@greendrake/rpc": "0.4.0",
|
|
38
38
|
"@standard-schema/spec": "^1.1.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@greendrake/dev-config": "0.
|
|
41
|
+
"@greendrake/dev-config": "0.4.0",
|
|
42
42
|
"@types/bun": "^1.3.5",
|
|
43
43
|
"typescript": "6.0.3"
|
|
44
44
|
}
|
package/src/types.ts
CHANGED
|
@@ -85,8 +85,8 @@ export const method = <A = void, R = unknown>(def: MethodDef<A, R>): MethodDef<A
|
|
|
85
85
|
|
|
86
86
|
type MethodArgs<A> = [A] extends [void] ? [] : [args: A]
|
|
87
87
|
|
|
88
|
-
// The client-side view of a dispatch table: the method map a
|
|
89
|
-
//
|
|
88
|
+
// The client-side view of a dispatch table: the method map a frontend hands
|
|
89
|
+
// its typed client, derived from the definitions rather than restated beside
|
|
90
90
|
// them. The pair's typing meets here — a method whose argument shape or result
|
|
91
91
|
// changes server-side stops compiling in the frontend that calls it.
|
|
92
92
|
export type ClientMethods<M extends Methods> = {
|