UNPKG

@opra/common

Version:
55 lines (54 loc) 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RpcApi = void 0; const index_js_1 = require("../../helpers/index.js"); const api_base_js_1 = require("../common/api-base.js"); /** * @class RpcApi */ class RpcApi extends api_base_js_1.ApiBase { constructor(init) { super(init); // noinspection JSUnusedGlobalSymbols this._controllerReverseMap = new WeakMap(); this.transport = 'rpc'; this.controllers = new index_js_1.ResponsiveMap(); this.platform = init.platform; } findController(arg0) { if (typeof arg0 === 'function') { /** Check for cached mapping */ const controller = this._controllerReverseMap.get(arg0); if (controller != null) return controller; /** Lookup for ctor in all controllers */ for (const c of this.controllers.values()) { if (c.ctor === arg0) { this._controllerReverseMap.set(arg0, c); return c; } } this._controllerReverseMap.set(arg0, null); return; } return this.controllers.get(arg0); } findOperation(arg0, operationName) { const controller = this.findController(arg0); return controller?.operations.get(operationName); } toJSON() { const schema = super.toJSON(); const out = { ...schema, transport: this.transport, platform: this.platform, controllers: {}, }; for (const v of this.controllers.values()) { out.controllers[v.name] = v.toJSON(); } return out; } } exports.RpcApi = RpcApi;