@theia/core
Version:
Theia is a cloud & desktop IDE framework implemented in TypeScript.
82 lines • 3.76 kB
JavaScript
import { __decorate } from "tslib";
// *****************************************************************************
// Copyright (C) 2023 EclipseSource and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
import { Emitter, Event } from '../../common/event.js';
import { RpcProxyFactory } from '../../common/messaging/proxy-factory.js';
import { injectable, inject, named } from 'inversify';
import { ServiceConnectionProvider } from '../../browser/messaging/service-connection-provider.js';
import { ILogger } from '../../common/logger.js';
let FrontendOnlyConnectionSource = class FrontendOnlyConnectionSource {
constructor() {
this.onConnectionDidOpen = new Emitter().event;
}
};
FrontendOnlyConnectionSource = __decorate([
injectable()
], FrontendOnlyConnectionSource);
export { FrontendOnlyConnectionSource };
/**
* Proxy factory for services without a frontend-only implementation. There is no backend,
* so no channel will ever open and requests would otherwise be queued forever, blocking
* any caller that awaits the result, e.g. during application startup.
* Instead, requests fail immediately and notifications (fire-and-forget) resolve silently.
*/
export class FrontendOnlyRpcProxyFactory extends RpcProxyFactory {
constructor(path, target) {
super(target);
this.path = path;
}
get(target, p, receiver) {
if (typeof p !== 'string') {
return undefined;
}
// members handled by the base proxy without a connection
if (['setClient', 'getClient', 'onDidOpenConnection', 'onDidCloseConnection', 'then', 'toJSON'].includes(p)) {
return super.get(target, p, receiver);
}
if (this.isNotification(p)) {
return () => Promise.resolve();
}
return () => Promise.reject(new Error(`Request '${p}' on service '${this.path}' is unavailable: no backend in frontend-only mode.`));
}
}
let FrontendOnlyServiceConnectionProvider = class FrontendOnlyServiceConnectionProvider extends ServiceConnectionProvider {
constructor() {
super(...arguments);
this.onSocketDidOpen = Event.None;
this.onSocketDidClose = Event.None;
this.onIncomingMessageActivity = Event.None;
}
createProxy(path, target) {
this.logger.debug(`[Frontend-Only Fallback] Created proxy connection for ${path}`);
if (target instanceof RpcProxyFactory) {
return target.createProxy();
}
return new FrontendOnlyRpcProxyFactory(path, target).createProxy();
}
listen(path, handler, reconnect) {
this.logger.debug('[Frontend-Only Fallback] Listen to websocket connection requested');
}
};
__decorate([
inject(ILogger),
named('core:FrontendOnlyServiceConnectionProvider')
], FrontendOnlyServiceConnectionProvider.prototype, "logger", void 0);
FrontendOnlyServiceConnectionProvider = __decorate([
injectable()
], FrontendOnlyServiceConnectionProvider);
export { FrontendOnlyServiceConnectionProvider };
//# sourceMappingURL=frontend-only-service-connection-provider.js.map