UNPKG

nope-js-node

Version:

NoPE Runtime for Nodejs. For Browser-Support please use nope-browser

78 lines (77 loc) 2.68 kB
"use strict"; /** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2020-10-12 18:52:00 * @modify date 2021-10-19 09:15:25 * @desc [description] */ Object.defineProperty(exports, "__esModule", { value: true }); exports.NopeDispatcher = void 0; const pathMatchingMethods_1 = require("../helpers/pathMatchingMethods"); const Core_1 = require("./Core"); /** * A Dispatcher to perform a function on a Remote * Dispatcher. Therefore a Task is created and forwarded * to the remote. * * @export * @class nopeDispatcher */ class NopeDispatcher extends Core_1.NopeCore { get masterExists() { return this.connectivityManager.master.isMasterForced; } // See interface description pushData(path, content, options = {}) { return this.dataDistributor.pushData(path, content, options); } // See interface description pullData(path, _default = null) { return this.dataDistributor.pullData(path, _default); } // See interface description subscribeToEvent(event, subscription) { return this.eventDistributor.registerSubscription(event, subscription); } // See interface description emitEvent(eventName, data, options = {}) { this.eventDistributor.emit(eventName, data, options); } // See interface description query(pattern, type) { let items = []; switch (type) { case "instances": items = this.instanceManager.instances.data.getContent().map((item) => { return item.identifier; }); break; case "services": items = Array.from( // Extract the Ids of the Services this.rpcManager.services.simplified.keys()); break; case "properties": items = this.dataDistributor.publishers.data.getContent(); break; case "events": items = this.eventDistributor.publishers.data.getContent(); break; default: throw Error("Invalid Type-Parameter"); } return items.filter((item) => { return (0, pathMatchingMethods_1.comparePatternAndPath)(pattern, item).affected; }); } // See interface description getAllHosts() { const hosts = new Set(); for (const info of this.connectivityManager.dispatchers.originalData.values()) { hosts.add(info.host.name); } return Array.from(hosts); } } exports.NopeDispatcher = NopeDispatcher;