UNPKG

iobroker.js-controller

Version:

Updated by reinstall.js on 2018-06-11T15:19:56.688Z

123 lines (122 loc) 4.81 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var blocklistManager_exports = {}; __export(blocklistManager_exports, { BlocklistManager: () => BlocklistManager }); module.exports = __toCommonJS(blocklistManager_exports); var import_constants = require("@iobroker/js-controller-common-db/constants"); var import_semver = __toESM(require("semver"), 1); class BlocklistManager { /** The objects client */ objects; constructor(options) { this.objects = options.objects; } /** * Iterates over all instances, disables blocklisted once if enabled * * @returns A list of disabled instances */ async disableAllBlocklistedInstances() { const disabledList = []; const systemRepoObj = await this.objects.getObject(import_constants.SYSTEM_REPOSITORIES_ID); const systemConfigObj = await this.objects.getObject(import_constants.SYSTEM_CONFIG_ID); if (!systemConfigObj || !systemRepoObj) { return disabledList; } const instancesView = await this.objects.getObjectViewAsync("system", "instance", { startkey: import_constants.SYSTEM_ADAPTER_PREFIX, endkey: import_constants.SYSTEM_ADAPTER_PREFIX + import_constants.HIGHEST_UNICODE_SYMBOL }); for (const row of instancesView.rows) { const obj = row.value; if (!obj.common.enabled) { continue; } const isBlocked = this.internalIsAdapterVersionBlocked({ systemConfigObj, systemRepoObj, adapterName: obj.common.name, version: obj.common.version }); if (!isBlocked) { continue; } obj.common.enabled = false; await this.objects.setObject(obj._id, obj); disabledList.push(row.value); } return disabledList; } /** * Check if version of a specific adapter is blocked * * @param options adapter version and name information * @returns A boolean indicating if the adapter version is blocked */ async isAdapterVersionBlocked(options) { const systemRepoObj = await this.objects.getObject(import_constants.SYSTEM_REPOSITORIES_ID); const systemConfigObj = await this.objects.getObject(import_constants.SYSTEM_CONFIG_ID); if (!systemConfigObj || !systemRepoObj) { return false; } return this.internalIsAdapterVersionBlocked({ ...options, systemRepoObj, systemConfigObj }); } /** * Check if version of a specific adapter is blocked * * @param options information about adapter, version and cached objects * @returns A boolean indicating if the adapter version is blocked */ internalIsAdapterVersionBlocked(options) { const { adapterName, version, systemRepoObj, systemConfigObj } = options; for (const activeRepoName of systemConfigObj.common.activeRepo) { if (!(activeRepoName in systemRepoObj.native.repositories)) { return false; } const repo = systemRepoObj.native.repositories[activeRepoName]; const adapterEntry = repo.json?.[adapterName]; if (!adapterEntry || !("blockedVersions" in adapterEntry)) { return false; } for (const blockedVersion of adapterEntry.blockedVersions) { if (import_semver.default.satisfies(version, blockedVersion, { includePrerelease: true })) { return true; } } } return false; } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { BlocklistManager }); //# sourceMappingURL=blocklistManager.js.map