@eclipse-emfcloud/model-service-theia
Version:
Model service Theia
98 lines • 4.07 kB
JavaScript
;
// *****************************************************************************
// Copyright (C) 2023-2024 STMicroelectronics.
//
// 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: MIT License which is
// available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: EPL-2.0 OR MIT
// *****************************************************************************
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FakeModelAccessorBusProtocol = void 0;
exports.bindFakeModelAccessorBusProtocol = bindFakeModelAccessorBusProtocol;
exports.connectClient = connectClient;
const inversify_1 = require("@theia/core/shared/inversify");
const common_1 = require("../../common");
/**
* All that we need for testing are the subscription-related methods and `get()`.
*/
let FakeModelAccessorBusProtocol = class FakeModelAccessorBusProtocol {
constructor() {
this.nextSubscriptionId = 0;
this.subscriptions = new Map();
this.pendingSubs = [];
}
subscribe(_context, accessorId) {
const token = {
id: ++this.nextSubscriptionId,
accessorId: accessorId,
};
this.subscriptions.set(token.id, token);
const result = Promise.resolve(token);
this.pendingSubs.push(result);
return result;
}
closeSubscription(token) {
this.subscriptions.delete(token.id);
this.client?.closeSubscription(token.id);
}
/**
* (fake) get function that returns the first parameter given
*
* @param _context not used
* @param _accessorId not used
* @param parameters a list of parameters (can be empty)
* @returns the first parameter given
*/
async get(_context, _accessorId, ...parameters) {
return parameters[0];
}
setClient(client) {
this.client = client;
}
get pendingSubsReady() {
return Promise.allSettled(this.pendingSubs).then(() => {
this.pendingSubs.length = 0;
});
}
lookupSubs(accessorId) {
const result = [];
if (!this.client) {
// No point
return result;
}
for (const token of this.subscriptions.values()) {
if (token.accessorId === accessorId) {
result.push(token);
}
}
return result;
}
};
exports.FakeModelAccessorBusProtocol = FakeModelAccessorBusProtocol;
exports.FakeModelAccessorBusProtocol = FakeModelAccessorBusProtocol = __decorate([
(0, inversify_1.injectable)()
], FakeModelAccessorBusProtocol);
function bindFakeModelAccessorBusProtocol(binder) {
const bind = binder instanceof inversify_1.Container ? binder.bind.bind(binder) : binder;
bind(FakeModelAccessorBusProtocol).toSelf().inSingletonScope();
bind(common_1.ModelAccessorBusProtocol).toService(FakeModelAccessorBusProtocol);
}
function connectClient(modelAccessorBus, subscriber) {
const subscriberImpl = subscriber;
modelAccessorBus.setClient(subscriberImpl.client);
subscriberImpl.setModelAccessorBus(modelAccessorBus);
}
//# sourceMappingURL=fake-model-accessor-bus-protocol.js.map