Skip to content

Commit

Permalink
Rename JsonRpcProxyFactory and related types
Browse files Browse the repository at this point in the history
- Rename `JsonRpcProxyFactory` and related types to `RpcProxyFactory` (Rpc*). The naming scheme was a remainder of the old vscode jsonr-rpc based protocol.
  By simply using the `Rpc` suffix the class names are less misleading and protocol agnostic.
- Keep deprecated declarations of the old `JsonRpc*` namespace. The components are heavily used by adopters so we should maintain this deprecated symbols for a while to enable graceful migration without hard API breaks.
Naturally this is open for discussion, but judging from the files I had to touch in the core framework alone I think it's definitely 
a good idea to give adopters a grace period.

Complementary website PR: eclipse-theia/theia-website#422

Fixes #12581
Contributed on behalf of STMicroelectronics
  • Loading branch information
tortmayr committed Jun 1, 2023
1 parent 53b1987 commit 440a59d
Show file tree
Hide file tree
Showing 44 changed files with 188 additions and 151 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
- [repo] with the upgrade to Inversify 6.0, a few initialization methods were adjusted. See also [this migration guide entry](https://github.com/eclipse-theia/theia/blob/master/doc/Migration.md#inversify-60). Additionally, other changes include: [#12425](https://github.com/eclipse-theia/theia/pull/12425)
- The type expected by the `PreferenceProxySchema` symbol has been changed from `PromiseLike<PreferenceSchema>` to `() => PromiseLike<PreferenceSchema>`
- The symbol `OnigasmPromise` has been changed to `OnigasmProvider` and injects a function of type `() => Promise<IOnigLib>`
- The symbol `PreferenceTransactionPrelude` has been changed to `PreferenceTransactionPreludeProvider ` and injects a function of type `() => Promise<unknown>`
- The symbol `PreferenceTransactionPrelude` has been changed to `PreferenceTransactionPreludeProvider` and injects a function of type `() => Promise<unknown>`
- [rpc] Replaced name suffixes classes and types that were still referencing the old rpc protocol. From `JsonRpc*` to `Rpc*`.
- Old classes and types are still available but haven been deprecated and might get removed in future releases [#12588](https://github.com/eclipse-theia/theia/pull/12588)
- e.g. `JsonRpcProxyFactory` is deprecated, use `RpcProxyFactory` instead.

## v1.38.0 - 05/25/2023

Expand Down
4 changes: 2 additions & 2 deletions examples/api-samples/src/common/updater/sample-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// *****************************************************************************
import { JsonRpcServer } from '@theia/core/lib/common/messaging/proxy-factory';
import { RpcServer } from '@theia/core/lib/common/messaging/proxy-factory';

export enum UpdateStatus {
InProgress = 'in-progress',
Expand All @@ -23,7 +23,7 @@ export enum UpdateStatus {

export const SampleUpdaterPath = '/services/sample-updater';
export const SampleUpdater = Symbol('SampleUpdater');
export interface SampleUpdater extends JsonRpcServer<SampleUpdaterClient> {
export interface SampleUpdater extends RpcServer<SampleUpdaterClient> {
checkForUpdates(): Promise<{ status: UpdateStatus }>;
onRestartToUpdateRequested(): void;
disconnectClient(client: SampleUpdaterClient): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// *****************************************************************************

import { ContainerModule } from '@theia/core/shared/inversify';
import { JsonRpcConnectionHandler } from '@theia/core/lib/common/messaging/proxy-factory';
import { RpcConnectionHandler } from '@theia/core/lib/common/messaging/proxy-factory';
import { ElectronMainApplicationContribution } from '@theia/core/lib/electron-main/electron-main-application';
import { ElectronConnectionHandler } from '@theia/core/lib/electron-common/messaging/electron-connection-handler';
import { SampleUpdaterPath, SampleUpdater, SampleUpdaterClient } from '../../common/updater/sample-updater';
Expand All @@ -26,7 +26,7 @@ export default new ContainerModule(bind => {
bind(SampleUpdater).toService(SampleUpdaterImpl);
bind(ElectronMainApplicationContribution).toService(SampleUpdater);
bind(ElectronConnectionHandler).toDynamicValue(context =>
new JsonRpcConnectionHandler<SampleUpdaterClient>(SampleUpdaterPath, client => {
new RpcConnectionHandler<SampleUpdaterClient>(SampleUpdaterPath, client => {
const server = context.container.get<SampleUpdater>(SampleUpdater);
server.setClient(client);
client.onDidCloseConnection(() => server.disconnectClient(client));
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/browser/messaging/ws-connection-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
// *****************************************************************************

import { injectable, interfaces, decorate, unmanaged } from 'inversify';
import { JsonRpcProxyFactory, JsonRpcProxy, Emitter, Event, Channel } from '../../common';
import { RpcProxyFactory, RpcProxy, Emitter, Event, Channel } from '../../common';
import { Endpoint } from '../endpoint';
import { AbstractConnectionProvider } from '../../common/messaging/abstract-connection-provider';
import { io, Socket } from 'socket.io-client';
import { IWebSocket, WebSocketChannel } from '../../common/messaging/web-socket-channel';

decorate(injectable(), JsonRpcProxyFactory);
decorate(unmanaged(), JsonRpcProxyFactory, 0);
decorate(injectable(), RpcProxyFactory);
decorate(unmanaged(), RpcProxyFactory, 0);

export interface WebSocketOptions {
/**
Expand All @@ -44,7 +44,7 @@ export class WebSocketConnectionProvider extends AbstractConnectionProvider<WebS
return this.onSocketDidCloseEmitter.event;
}

static override createProxy<T extends object>(container: interfaces.Container, path: string, arg?: object): JsonRpcProxy<T> {
static override createProxy<T extends object>(container: interfaces.Container, path: string, arg?: object): RpcProxy<T> {
return container.get(WebSocketConnectionProvider).createProxy<T>(path, arg);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/common/logger-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
// *****************************************************************************

import { injectable } from 'inversify';
import { JsonRpcServer } from './messaging/proxy-factory';
import { RpcServer } from './messaging/proxy-factory';

export const ILoggerServer = Symbol('ILoggerServer');

export const loggerPath = '/services/logger';

export interface ILoggerServer extends JsonRpcServer<ILoggerClient> {
export interface ILoggerServer extends RpcServer<ILoggerClient> {
setLogLevel(name: string, logLevel: number): Promise<void>;
getLogLevel(name: string): Promise<number>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { injectable, interfaces } from 'inversify';
import { Emitter, Event } from '../event';
import { ConnectionHandler } from './handler';
import { JsonRpcProxy, JsonRpcProxyFactory } from './proxy-factory';
import { RpcProxy, RpcProxyFactory } from './proxy-factory';
import { Channel, ChannelMultiplexer } from '../message-rpc/channel';

/**
Expand All @@ -32,15 +32,15 @@ export abstract class AbstractConnectionProvider<AbstractOptions extends object>
* Create a proxy object to remote interface of T type
* over an electron ipc connection for the given path and proxy factory.
*/
static createProxy<T extends object>(container: interfaces.Container, path: string, factory: JsonRpcProxyFactory<T>): JsonRpcProxy<T>;
static createProxy<T extends object>(container: interfaces.Container, path: string, factory: RpcProxyFactory<T>): RpcProxy<T>;
/**
* Create a proxy object to remote interface of T type
* over an electron ipc connection for the given path.
*
* An optional target can be provided to handle
* notifications and requests from a remote side.
*/
static createProxy<T extends object>(container: interfaces.Container, path: string, target?: object): JsonRpcProxy<T> {
static createProxy<T extends object>(container: interfaces.Container, path: string, target?: object): RpcProxy<T> {
throw new Error('abstract');
}

Expand All @@ -53,17 +53,17 @@ export abstract class AbstractConnectionProvider<AbstractOptions extends object>
* Create a proxy object to remote interface of T type
* over a web socket connection for the given path and proxy factory.
*/
createProxy<T extends object>(path: string, factory: JsonRpcProxyFactory<T>): JsonRpcProxy<T>;
createProxy<T extends object>(path: string, factory: RpcProxyFactory<T>): RpcProxy<T>;
/**
* Create a proxy object to remote interface of T type
* over a web socket connection for the given path.
*
* An optional target can be provided to handle
* notifications and requests from a remote side.
*/
createProxy<T extends object>(path: string, target?: object): JsonRpcProxy<T>;
createProxy<T extends object>(path: string, arg?: object): JsonRpcProxy<T> {
const factory = arg instanceof JsonRpcProxyFactory ? arg : new JsonRpcProxyFactory<T>(arg);
createProxy<T extends object>(path: string, target?: object): RpcProxy<T>;
createProxy<T extends object>(path: string, arg?: object): RpcProxy<T> {
const factory = arg instanceof RpcProxyFactory ? arg : new RpcProxyFactory<T>(arg);
this.listen({
path,
onConnection: c => factory.listen(c)
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/common/messaging/proxy-factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// *****************************************************************************

import * as chai from 'chai';
import { JsonRpcProxyFactory, JsonRpcProxy } from './proxy-factory';
import { RpcProxyFactory, RpcProxy } from './proxy-factory';
import { ChannelPipe } from '../message-rpc/channel.spec';

const expect = chai.expect;
Expand Down Expand Up @@ -84,19 +84,19 @@ describe('Proxy-Factory', () => {

function getSetup(): {
client: TestClient;
clientProxy: JsonRpcProxy<TestClient>;
clientProxy: RpcProxy<TestClient>;
server: TestServer;
serverProxy: JsonRpcProxy<TestServer>;
serverProxy: RpcProxy<TestServer>;
} {
const client = new TestClient();
const server = new TestServer();

const serverProxyFactory = new JsonRpcProxyFactory<TestServer>(client);
const serverProxyFactory = new RpcProxyFactory<TestServer>(client);
const pipe = new ChannelPipe();
serverProxyFactory.listen(pipe.right);
const serverProxy = serverProxyFactory.createProxy();

const clientProxyFactory = new JsonRpcProxyFactory<TestClient>(server);
const clientProxyFactory = new RpcProxyFactory<TestClient>(server);
clientProxyFactory.listen(pipe.left);
const clientProxy = clientProxyFactory.createProxy();
return {
Expand Down
Loading

0 comments on commit 440a59d

Please sign in to comment.