UNPKG

@eclipse-emfcloud/modelserver-theia

Version:
66 lines 2.92 kB
"use strict"; /******************************************************************************** * Copyright (c) 2022 STMicroelectronics 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 * https://www.eclipse.org/legal/epl-2.0, or the MIT License which is * available at https://opensource.org/licenses/MIT. * * SPDX-License-Identifier: EPL-2.0 OR MIT *******************************************************************************/ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TheiaModelServerJsonRpcProxyFactory = void 0; const type_util_1 = require("@eclipse-emfcloud/modelserver-client/lib/utils/type-util"); const proxy_factory_1 = require("@theia/core/lib/common/messaging/proxy-factory"); const urijs_1 = __importDefault(require("urijs")); class TheiaModelServerJsonRpcProxyFactory extends proxy_factory_1.JsonRpcProxyFactory { async onRequest(method, ...args) { return super.onRequest(method, ...this.processArguments(args)); } onNotification(method, ...args) { super.onNotification(method, ...this.processArguments(args)); } processArguments(args) { const processedArgs = []; for (const arg of args) { // process arguments and restore URI objects properly for JSON-rpc communication if ((0, type_util_1.isURI)(arg)) { processedArgs.push(new urijs_1.default((0, type_util_1.asURI)(arg))); } else if (Array.isArray(arg)) { const argArray = []; for (const argument of arg) { if ((0, type_util_1.isURI)(argument)) { argArray.push(new urijs_1.default((0, type_util_1.asURI)(argument))); } else { argArray.push(argument); } } processedArgs.push(argArray); } else if (type_util_1.AnyObject.is(arg)) { const argObject = {}; for (const [key, value] of Object.entries(arg)) { if ((0, type_util_1.isURI)(value)) { argObject[key] = new urijs_1.default((0, type_util_1.asURI)(value)); } else { argObject[key] = value; } } processedArgs.push(argObject); } else { processedArgs.push(arg); } } return processedArgs; } } exports.TheiaModelServerJsonRpcProxyFactory = TheiaModelServerJsonRpcProxyFactory; //# sourceMappingURL=jsonrpc-proxy-factory.js.map