@@ -24,28 +24,29 @@ import { Channel } from '../message-rpc/channel';
24
24
import { RequestHandler , RpcProtocol } from '../message-rpc/rpc-protocol' ;
25
25
import { ConnectionHandler } from './handler' ;
26
26
import { Deferred } from '../promise-util' ;
27
+ import { decorate , injectable , unmanaged } from '../../../shared/inversify' ;
27
28
28
- export type JsonRpcServer < Client > = Disposable & {
29
+ export type RpcServer < Client > = Disposable & {
29
30
/**
30
31
* If this server is a proxy to a remote server then
31
32
* a client is used as a local object
32
- * to handle JSON- RPC messages from the remote server.
33
+ * to handle RPC messages from the remote server.
33
34
*/
34
35
setClient ( client : Client | undefined ) : void ;
35
36
getClient ?( ) : Client | undefined ;
36
37
} ;
37
38
38
- export interface JsonRpcConnectionEventEmitter {
39
+ export interface RpcConnectionEventEmitter {
39
40
readonly onDidOpenConnection : Event < void > ;
40
41
readonly onDidCloseConnection : Event < void > ;
41
42
}
42
- export type JsonRpcProxy < T > = T & JsonRpcConnectionEventEmitter ;
43
+ export type RpcProxy < T > = T & RpcConnectionEventEmitter ;
43
44
44
- export class JsonRpcConnectionHandler < T extends object > implements ConnectionHandler {
45
+ export class RpcConnectionHandler < T extends object > implements ConnectionHandler {
45
46
constructor (
46
47
readonly path : string ,
47
- readonly targetFactory : ( proxy : JsonRpcProxy < T > ) => any ,
48
- readonly factoryConstructor : new ( ) => JsonRpcProxyFactory < T > = JsonRpcProxyFactory
48
+ readonly targetFactory : ( proxy : RpcProxy < T > ) => any ,
49
+ readonly factoryConstructor : new ( ) => RpcProxyFactory < T > = RpcProxyFactory
49
50
) { }
50
51
51
52
onConnection ( connection : Channel ) : void {
@@ -63,12 +64,12 @@ export type RpcProtocolFactory = (channel: Channel, requestHandler: RequestHandl
63
64
const defaultRpcProtocolFactory : RpcProtocolFactory = ( channel , requestHandler ) => new RpcProtocol ( channel , requestHandler ) ;
64
65
65
66
/**
66
- * Factory for JSON- RPC proxy objects.
67
+ * Factory for RPC proxy objects.
67
68
*
68
- * A JSON- RPC proxy exposes the programmatic interface of an object through
69
- * JSON- RPC. This allows remote programs to call methods of this objects by
70
- * sending JSON- RPC requests. This takes place over a bi-directional stream,
71
- * where both ends can expose an object and both can call methods each other's
69
+ * A RPC proxy exposes the programmatic interface of an object through
70
+ * Theia's RPC protocol. This allows remote programs to call methods of this objects by
71
+ * sending RPC requests. This takes place over a bi-directional stream,
72
+ * where both ends can expose an object and both can call methods on each other'
72
73
* exposed object.
73
74
*
74
75
* For example, assuming we have an object of the following type on one end:
@@ -77,45 +78,45 @@ const defaultRpcProtocolFactory: RpcProtocolFactory = (channel, requestHandler)
77
78
* bar(baz: number): number { return baz + 1 }
78
79
* }
79
80
*
80
- * which we want to expose through a JSON- RPC interface. We would do:
81
+ * which we want to expose through a RPC interface. We would do:
81
82
*
82
83
* let target = new Foo()
83
- * let factory = new JsonRpcProxyFactory <Foo>('/foo', target)
84
+ * let factory = new RpcProxyFactory <Foo>('/foo', target)
84
85
* factory.onConnection(connection)
85
86
*
86
87
* The party at the other end of the `connection`, in order to remotely call
87
88
* methods on this object would do:
88
89
*
89
- * let factory = new JsonRpcProxyFactory <Foo>('/foo')
90
+ * let factory = new RpcProxyFactory <Foo>('/foo')
90
91
* factory.onConnection(connection)
91
92
* let proxy = factory.createProxy();
92
93
* let result = proxy.bar(42)
93
94
* // result is equal to 43
94
95
*
95
96
* One the wire, it would look like this:
96
97
*
97
- * --> {"jsonrpc": "2.0 ", "id": 0 , "method": "bar", "params ": {"baz": 42} }
98
- * <-- {"jsonrpc": "2.0 ", "id": 0 , "result ": 43}
99
- *
98
+ * --> { "type":"1 ", "id": 1 , "method": "bar", "args ": [42] }
99
+ * <-- { "type":"3 ", "id": 1 , "res ": 43}
100
+ *
100
101
* Note that in the code of the caller, we didn't pass a target object to
101
- * JsonRpcProxyFactory , because we don't want/need to expose an object.
102
+ * RpcProxyFactory , because we don't want/need to expose an object.
102
103
* If we had passed a target object, the other side could've called methods on
103
104
* it.
104
105
*
105
- * @param <T> - The type of the object to expose to JSON- RPC.
106
+ * @param <T> - The type of the object to expose to RPC.
106
107
*/
107
108
108
- export class JsonRpcProxyFactory < T extends object > implements ProxyHandler < T > {
109
+ export class RpcProxyFactory < T extends object > implements ProxyHandler < T > {
109
110
110
111
protected readonly onDidOpenConnectionEmitter = new Emitter < void > ( ) ;
111
112
protected readonly onDidCloseConnectionEmitter = new Emitter < void > ( ) ;
112
113
113
114
protected rpcDeferred : Deferred < RpcProtocol > ;
114
115
115
116
/**
116
- * Build a new JsonRpcProxyFactory .
117
+ * Build a new RpcProxyFactory .
117
118
*
118
- * @param target - The object to expose to JSON- RPC methods calls. If this
119
+ * @param target - The object to expose to RPC methods calls. If this
119
120
* is omitted, the proxy won't be able to handle requests, only send them.
120
121
*/
121
122
constructor ( public target ?: any , protected rpcProtocolFactory = defaultRpcProtocolFactory ) {
@@ -135,10 +136,10 @@ export class JsonRpcProxyFactory<T extends object> implements ProxyHandler<T> {
135
136
}
136
137
137
138
/**
138
- * Connect a MessageConnection to the factory.
139
+ * Connect a { @link Channel} to the factory by creating an { @link RpcProtocol} on top of it .
139
140
*
140
- * This connection will be used to send/receive JSON- RPC requests and
141
- * response .
141
+ * This protocol will be used to send/receive RPC requests and
142
+ * responses .
142
143
*/
143
144
listen ( channel : Channel ) : void {
144
145
const protocol = this . rpcProtocolFactory ( channel , ( meth , args ) => this . onRequest ( meth , ...args ) ) ;
@@ -148,9 +149,9 @@ export class JsonRpcProxyFactory<T extends object> implements ProxyHandler<T> {
148
149
}
149
150
150
151
/**
151
- * Process an incoming JSON- RPC method call.
152
+ * Process an incoming RPC method call.
152
153
*
153
- * onRequest is called when the JSON- RPC connection received a method call
154
+ * onRequest is called when the RPC connection received a method call
154
155
* request. It calls the corresponding method on [[target]].
155
156
*
156
157
* The return value is a Promise object that is resolved with the return
@@ -179,7 +180,7 @@ export class JsonRpcProxyFactory<T extends object> implements ProxyHandler<T> {
179
180
}
180
181
181
182
/**
182
- * Process an incoming JSON- RPC notification.
183
+ * Process an incoming RPC notification.
183
184
*
184
185
* Same as [[onRequest]], but called on incoming notifications rather than
185
186
* methods calls.
@@ -192,37 +193,37 @@ export class JsonRpcProxyFactory<T extends object> implements ProxyHandler<T> {
192
193
193
194
/**
194
195
* Create a Proxy exposing the interface of an object of type T. This Proxy
195
- * can be used to do JSON- RPC method calls on the remote target object as
196
+ * can be used to do RPC method calls on the remote target object as
196
197
* if it was local.
197
198
*
198
- * If `T` implements `JsonRpcServer ` then a client is used as a target object for a remote target object.
199
+ * If `T` implements `RpcServer ` then a client is used as a target object for a remote target object.
199
200
*/
200
- createProxy ( ) : JsonRpcProxy < T > {
201
+ createProxy ( ) : RpcProxy < T > {
201
202
const result = new Proxy < T > ( this as any , this ) ;
202
203
return result as any ;
203
204
}
204
205
205
206
/**
206
- * Get a callable object that executes a JSON- RPC method call.
207
+ * Get a callable object that executes a RPC method call.
207
208
*
208
209
* Getting a property on the Proxy object returns a callable that, when
209
- * called, executes a JSON- RPC call. The name of the property defines the
210
+ * called, executes a RPC call. The name of the property defines the
210
211
* method to be called. The callable takes a variable number of arguments,
211
- * which are passed in the JSON- RPC method call.
212
+ * which are passed in the RPC method call.
212
213
*
213
214
* For example, if you have a Proxy object:
214
215
*
215
- * let fooProxyFactory = JsonRpcProxyFactory <Foo>('/foo')
216
+ * let fooProxyFactory = RpcProxyFactory <Foo>('/foo')
216
217
* let fooProxy = fooProxyFactory.createProxy()
217
218
*
218
219
* accessing `fooProxy.bar` will return a callable that, when called,
219
- * executes a JSON- RPC method call to method `bar`. Therefore, doing
220
+ * executes a RPC method call to method `bar`. Therefore, doing
220
221
* `fooProxy.bar()` will call the `bar` method on the remote Foo object.
221
222
*
222
223
* @param target - unused.
223
224
* @param p - The property accessed on the Proxy object.
224
225
* @param receiver - unused.
225
- * @returns A callable that executes the JSON- RPC call.
226
+ * @returns A callable that executes the RPC call.
226
227
*/
227
228
get ( target : T , p : PropertyKey , receiver : any ) : any {
228
229
if ( p === 'setClient' ) {
@@ -306,3 +307,37 @@ export class JsonRpcProxyFactory<T extends object> implements ProxyHandler<T> {
306
307
307
308
}
308
309
310
+ /**
311
+ * @deprecated since 1.39.0 use `RpcConnectionEventEmitter` instead
312
+ */
313
+ export type JsonRpcConnectionEventEmitter = RpcConnectionEventEmitter ;
314
+
315
+ /**
316
+ * @deprecated since 1.39.0 use `RpcServer` instead
317
+ */
318
+ export type JsonRpcServer < Client > = RpcServer < Client > ;
319
+
320
+ /**
321
+ * @deprecated since 1.39.0 use `RpcProxy` instead
322
+ */
323
+ export type JsonRpcProxy < T > = RpcProxy < T > ;
324
+
325
+ /**
326
+ * @deprecated since 1.39.0 use `RpcConnectionHandler` instead
327
+ */
328
+ export class JsonRpcConnectionHandler < T extends object > extends RpcConnectionHandler < T > {
329
+
330
+ }
331
+
332
+ /**
333
+ * @deprecated since 1.39.0 use `RpcProxyFactory` instead
334
+ */
335
+ export class JsonRpcProxyFactory < T extends object > extends RpcProxyFactory < T > {
336
+
337
+ }
338
+
339
+ // eslint-disable-next-line deprecation/deprecation
340
+ decorate ( injectable ( ) , JsonRpcProxyFactory ) ;
341
+ // eslint-disable-next-line deprecation/deprecation
342
+ decorate ( unmanaged ( ) , JsonRpcProxyFactory , 0 ) ;
343
+
0 commit comments