@opra/common
Version:
Opra common package
52 lines (51 loc) • 1.59 kB
JavaScript
import { ResponsiveMap } from '../../helpers/index.js';
import { ApiBase } from '../common/api-base.js';
/**
* @class MQApi
*/
export class MQApi extends ApiBase {
// noinspection JSUnusedGlobalSymbols
_controllerReverseMap = new WeakMap();
transport = 'mq';
platform;
controllers = new ResponsiveMap();
constructor(init) {
super(init);
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;
}
}