@orpc/server 2.0.0-beta.5 → 2.0.0-beta.7
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
CHANGED
|
@@ -134,7 +134,6 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
134
134
|
</tr>
|
|
135
135
|
<tr>
|
|
136
136
|
<td align="center"><a href="https://github.com/piscis?ref=orpc" target="_blank" rel="noopener" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="119" alt="Alex"/><br />Alex</a></td>
|
|
137
|
-
<td align="center"><a href="https://github.com/nattstack?ref=orpc" target="_blank" rel="noopener" title="nattstack"><img src="https://avatars.githubusercontent.com/u/31426677?u=fa9dbb8b3e66eb0ea3c88db5dc07f31c8c5418fe&v=4" width="119" alt="nattstack"/><br />nattstack</a></td>
|
|
138
137
|
<td align="center"><a href="https://github.com/finom?ref=orpc" target="_blank" rel="noopener" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=29e91400dbd4a9c217048a8f59562c4f740498e6&v=4" width="119" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
|
|
139
138
|
</tr>
|
|
140
139
|
</table>
|
|
@@ -173,6 +172,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
173
172
|
<a href="https://github.com/illarionvk?ref=orpc" target="_blank" rel="noopener" title="Illarion Koperski"><img src="https://avatars.githubusercontent.com/u/5012724?u=7cfa13652f7ac5fb3c56d880e3eb3fbe40c3ea34&v=4" width="32" height="32" alt="Illarion Koperski" /></a>
|
|
174
173
|
<a href="https://github.com/steelbrain?ref=orpc" target="_blank" rel="noopener" title="Anees Iqbal"><img src="https://avatars.githubusercontent.com/u/4278113?u=22b80b5399eed68ac76cd58b02961b0481f1db11&v=4" width="32" height="32" alt="Anees Iqbal" /></a>
|
|
175
174
|
<a href="https://github.com/Scrumplex?ref=orpc" target="_blank" rel="noopener" title="Sefa Eyeoglu"><img src="https://avatars.githubusercontent.com/u/11587657?u=ab503582165c0bbff0cca47ce31c9450bb1553c9&v=4" width="32" height="32" alt="Sefa Eyeoglu" /></a>
|
|
175
|
+
<a href="https://github.com/nattstack?ref=orpc" target="_blank" rel="noopener" title="nattstack"><img src="https://avatars.githubusercontent.com/u/31426677?u=fa9dbb8b3e66eb0ea3c88db5dc07f31c8c5418fe&v=4" width="32" height="32" alt="nattstack" /></a>
|
|
176
176
|
<a href="https://github.com/ChromeGG?ref=orpc" target="_blank" rel="noopener" title="Adam Tkaczyk"><img src="https://avatars.githubusercontent.com/u/39050595?u=a58ca6042a6950e94e6e92442db76ef584279bc0&v=4" width="32" height="32" alt="Adam Tkaczyk" /></a>
|
|
177
177
|
<a href="https://github.com/plancraft?ref=orpc" target="_blank" rel="noopener" title="plancraft"><img src="https://avatars.githubusercontent.com/u/46482287?v=4" width="32" height="32" alt="plancraft" /></a>
|
|
178
178
|
</p>
|
|
@@ -9,7 +9,11 @@ import '@orpc/client';
|
|
|
9
9
|
import '@orpc/contract';
|
|
10
10
|
import '@standardserver/core';
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Supports standard WebSocket instances, Bun ServerWebSocket, "ws" ServerWebSocket,
|
|
14
|
+
* Cloudflare WebSocket Hibernation, and similar implementations.
|
|
15
|
+
*/
|
|
16
|
+
type WebsocketLike = Pick<WebSocket, 'send'>;
|
|
13
17
|
interface WebsocketHandlerOptions<_T extends Context> {
|
|
14
18
|
/**
|
|
15
19
|
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
@@ -26,10 +30,6 @@ declare class WebsocketHandler<T extends Context> {
|
|
|
26
30
|
private readonly encodePeerMessageOptions;
|
|
27
31
|
private readonly decodePeerMessageOptions;
|
|
28
32
|
constructor(handler: StandardHandler<T>, options?: NoInfer<WebsocketHandlerOptions<T>>);
|
|
29
|
-
/**
|
|
30
|
-
* Attaches necessary event listeners to a WebSocket to handle incoming messages and peer management.
|
|
31
|
-
*/
|
|
32
|
-
upgrade(ws: WebsocketLike, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): void;
|
|
33
33
|
/**
|
|
34
34
|
* Handles a single message received from a WebSocket.
|
|
35
35
|
*
|
|
@@ -49,6 +49,13 @@ declare class WebsocketHandler<T extends Context> {
|
|
|
49
49
|
* @param ws The WebSocket instance to clean up, must be the same instance used in `.message()` calls to properly clean up
|
|
50
50
|
*/
|
|
51
51
|
close(ws: WebsocketLike): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Attaches websocket event listeners for message and close handling.
|
|
54
|
+
*
|
|
55
|
+
* Use this instead of calling `.message()` and `.close()` manually.
|
|
56
|
+
* Requires a websocket-like object that supports `addEventListener` and `removeEventListener`.
|
|
57
|
+
*/
|
|
58
|
+
upgrade(ws: Pick<WebSocket, 'send' | 'addEventListener' | 'removeEventListener'>, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): void;
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, WebsocketHandlerOptions<T> {
|
|
@@ -9,7 +9,11 @@ import '@orpc/client';
|
|
|
9
9
|
import '@orpc/contract';
|
|
10
10
|
import '@standardserver/core';
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Supports standard WebSocket instances, Bun ServerWebSocket, "ws" ServerWebSocket,
|
|
14
|
+
* Cloudflare WebSocket Hibernation, and similar implementations.
|
|
15
|
+
*/
|
|
16
|
+
type WebsocketLike = Pick<WebSocket, 'send'>;
|
|
13
17
|
interface WebsocketHandlerOptions<_T extends Context> {
|
|
14
18
|
/**
|
|
15
19
|
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
@@ -26,10 +30,6 @@ declare class WebsocketHandler<T extends Context> {
|
|
|
26
30
|
private readonly encodePeerMessageOptions;
|
|
27
31
|
private readonly decodePeerMessageOptions;
|
|
28
32
|
constructor(handler: StandardHandler<T>, options?: NoInfer<WebsocketHandlerOptions<T>>);
|
|
29
|
-
/**
|
|
30
|
-
* Attaches necessary event listeners to a WebSocket to handle incoming messages and peer management.
|
|
31
|
-
*/
|
|
32
|
-
upgrade(ws: WebsocketLike, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): void;
|
|
33
33
|
/**
|
|
34
34
|
* Handles a single message received from a WebSocket.
|
|
35
35
|
*
|
|
@@ -49,6 +49,13 @@ declare class WebsocketHandler<T extends Context> {
|
|
|
49
49
|
* @param ws The WebSocket instance to clean up, must be the same instance used in `.message()` calls to properly clean up
|
|
50
50
|
*/
|
|
51
51
|
close(ws: WebsocketLike): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Attaches websocket event listeners for message and close handling.
|
|
54
|
+
*
|
|
55
|
+
* Use this instead of calling `.message()` and `.close()` manually.
|
|
56
|
+
* Requires a websocket-like object that supports `addEventListener` and `removeEventListener`.
|
|
57
|
+
*/
|
|
58
|
+
upgrade(ws: Pick<WebSocket, 'send' | 'addEventListener' | 'removeEventListener'>, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): void;
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, WebsocketHandlerOptions<T> {
|
|
@@ -17,13 +17,6 @@ class WebsocketHandler {
|
|
|
17
17
|
peers = /* @__PURE__ */ new WeakMap();
|
|
18
18
|
encodePeerMessageOptions;
|
|
19
19
|
decodePeerMessageOptions;
|
|
20
|
-
/**
|
|
21
|
-
* Attaches necessary event listeners to a WebSocket to handle incoming messages and peer management.
|
|
22
|
-
*/
|
|
23
|
-
upgrade(ws, ...rest) {
|
|
24
|
-
ws.addEventListener("message", (event) => this.message(ws, event.data, ...rest));
|
|
25
|
-
ws.addEventListener("close", () => this.close(ws));
|
|
26
|
-
}
|
|
27
20
|
/**
|
|
28
21
|
* Handles a single message received from a WebSocket.
|
|
29
22
|
*
|
|
@@ -63,6 +56,16 @@ class WebsocketHandler {
|
|
|
63
56
|
this.peers.delete(ws);
|
|
64
57
|
}
|
|
65
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Attaches websocket event listeners for message and close handling.
|
|
61
|
+
*
|
|
62
|
+
* Use this instead of calling `.message()` and `.close()` manually.
|
|
63
|
+
* Requires a websocket-like object that supports `addEventListener` and `removeEventListener`.
|
|
64
|
+
*/
|
|
65
|
+
upgrade(ws, ...rest) {
|
|
66
|
+
ws.addEventListener("message", (event) => this.message(ws, event.data, ...rest));
|
|
67
|
+
ws.addEventListener("close", () => this.close(ws));
|
|
68
|
+
}
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
class RPCHandler extends WebsocketHandler {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.7",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
@@ -90,10 +90,10 @@
|
|
|
90
90
|
"@standardserver/node": "^0.0.25",
|
|
91
91
|
"@standardserver/peer": "^0.0.25",
|
|
92
92
|
"cookie": "^1.1.1",
|
|
93
|
-
"@orpc/
|
|
94
|
-
"@orpc/contract": "2.0.0-beta.
|
|
95
|
-
"@orpc/
|
|
96
|
-
"@orpc/shared": "2.0.0-beta.
|
|
93
|
+
"@orpc/client": "2.0.0-beta.7",
|
|
94
|
+
"@orpc/contract": "2.0.0-beta.7",
|
|
95
|
+
"@orpc/interop": "2.0.0-beta.7",
|
|
96
|
+
"@orpc/shared": "2.0.0-beta.7"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
99
|
"crossws": "^0.4.6",
|