@rest-vir/define-service 0.3.0 → 0.3.2
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.
|
@@ -24,7 +24,7 @@ export type RestVirApi<SpecificService extends ServiceDefinition> = {
|
|
|
24
24
|
webSockets: {
|
|
25
25
|
[WebSocketPath in keyof SpecificService['webSockets']]: SpecificService['webSockets'][WebSocketPath] extends WebSocketDefinition ? SpecificService['webSockets'][WebSocketPath] & {
|
|
26
26
|
/** Connect to this WebSocket. */
|
|
27
|
-
connect(...params: CollapsedConnectWebSocketParams<SpecificService['webSockets'][WebSocketPath], false
|
|
27
|
+
connect(...params: CollapsedConnectWebSocketParams<SpecificService['webSockets'][WebSocketPath], false>): Promise<ClientWebSocket<SpecificService['webSockets'][WebSocketPath]>>;
|
|
28
28
|
} : never;
|
|
29
29
|
};
|
|
30
30
|
};
|
|
@@ -89,6 +89,23 @@ export type CollapsedSendAndWaitForReplyParams<Location extends WebSocketLocatio
|
|
|
89
89
|
MessageFromClientType: true;
|
|
90
90
|
MessageFromHostType: true;
|
|
91
91
|
}>> | NoParam = NoParam> = HasRequiredKeys<SendAndWaitForReplyParams<Location, WebSocketToConnect>> extends true ? [SendAndWaitForReplyParams<Location, WebSocketToConnect>] : [SendAndWaitForReplyParams<Location, WebSocketToConnect>?];
|
|
92
|
+
/**
|
|
93
|
+
* Narrows a {@link WebSocketDefinition} for use within {@link OverwriteWebSocketMethods}.
|
|
94
|
+
*
|
|
95
|
+
* @category Internal
|
|
96
|
+
* @category Package : @rest-vir/define-service
|
|
97
|
+
* @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
|
|
98
|
+
*/
|
|
99
|
+
export type NarrowOriginalDefinition<OriginalWebSocketDefinition extends Readonly<SelectFrom<WebSocketDefinition, {
|
|
100
|
+
MessageFromClientType: true;
|
|
101
|
+
MessageFromHostType: true;
|
|
102
|
+
SearchParamsType: true;
|
|
103
|
+
}>> | NoParam = NoParam> = OriginalWebSocketDefinition extends NoParam ? NoParam : Omit<OriginalWebSocketDefinition,
|
|
104
|
+
/**
|
|
105
|
+
* Omit connect so this is compatible with API WebSocket objects (which have a `connect`
|
|
106
|
+
* method).
|
|
107
|
+
*/
|
|
108
|
+
'connect'>;
|
|
92
109
|
/**
|
|
93
110
|
* Takes any WebSocket class and overwrites it with some new rest vir methods and makes some
|
|
94
111
|
* existing WebSocket methods type safe.
|
|
@@ -111,7 +128,7 @@ export type OverwriteWebSocketMethods<WebSocketClass extends CommonWebSocket, Lo
|
|
|
111
128
|
* Adds an event listener that's wrapped in assertions to verify that message events have
|
|
112
129
|
* the expected contents.
|
|
113
130
|
*/
|
|
114
|
-
addEventListener<const EventName extends keyof CommonWebSocketEventMap>(eventName: EventName, listener: WebSocketListener<EventName, OriginalWebSocketDefinition
|
|
131
|
+
addEventListener<const EventName extends keyof CommonWebSocketEventMap>(eventName: EventName, listener: WebSocketListener<EventName, NarrowOriginalDefinition<OriginalWebSocketDefinition>, FlipWebSocketLocation<Location>, WebSocketClass>): void;
|
|
115
132
|
/**
|
|
116
133
|
* Sends a message to the other side of the WebSocket connection and waits that other side
|
|
117
134
|
* to send a message in response.
|
|
@@ -119,7 +136,7 @@ export type OverwriteWebSocketMethods<WebSocketClass extends CommonWebSocket, Lo
|
|
|
119
136
|
* This will catch messages that might not have been intended as a response for the original
|
|
120
137
|
* message as it will catch _any_ message sent from the other side.
|
|
121
138
|
*/
|
|
122
|
-
sendAndWaitForReply(...params: CollapsedSendAndWaitForReplyParams<Location, OriginalWebSocketDefinition
|
|
139
|
+
sendAndWaitForReply(...params: CollapsedSendAndWaitForReplyParams<Location, NarrowOriginalDefinition<OriginalWebSocketDefinition>>): Promise<NarrowOriginalDefinition<OriginalWebSocketDefinition> extends NoParam ? any : GetWebSocketMessageTypeFromLocation<Exclude<NarrowOriginalDefinition<OriginalWebSocketDefinition>, NoParam>, FlipWebSocketLocation<Location>>>;
|
|
123
140
|
/**
|
|
124
141
|
* Sends data through the WebSocket to the other side of the connection. This rest-vir
|
|
125
142
|
* wrapper ensures that all sent messages match expected types from the WebSocket
|
|
@@ -128,10 +145,10 @@ export type OverwriteWebSocketMethods<WebSocketClass extends CommonWebSocket, Lo
|
|
|
128
145
|
* See [MDN](https://developer.mozilla.org/docs/Web/API/WebSocket/send) for the original
|
|
129
146
|
* `WebSocket.send()` docs.
|
|
130
147
|
*/
|
|
131
|
-
send(...args: OriginalWebSocketDefinition extends NoParam ? [message?: any] : GetWebSocketMessageTypeFromLocation<Exclude<OriginalWebSocketDefinition
|
|
132
|
-
message?: GetWebSocketMessageTypeFromLocation<Exclude<OriginalWebSocketDefinition
|
|
148
|
+
send(...args: NarrowOriginalDefinition<OriginalWebSocketDefinition> extends NoParam ? [message?: any] : GetWebSocketMessageTypeFromLocation<Exclude<NarrowOriginalDefinition<OriginalWebSocketDefinition>, NoParam>, Location> extends undefined ? [
|
|
149
|
+
message?: GetWebSocketMessageTypeFromLocation<Exclude<NarrowOriginalDefinition<OriginalWebSocketDefinition>, NoParam>, Location>
|
|
133
150
|
] : [
|
|
134
|
-
message: GetWebSocketMessageTypeFromLocation<Exclude<OriginalWebSocketDefinition
|
|
151
|
+
message: GetWebSocketMessageTypeFromLocation<Exclude<NarrowOriginalDefinition<OriginalWebSocketDefinition>, NoParam>, Location>
|
|
135
152
|
]): void;
|
|
136
153
|
}>;
|
|
137
154
|
/**
|