UNPKG

@breautek/storm

Version:

Object-Oriented REST API framework

68 lines (65 loc) 2.3 kB
"use strict"; /* Copyright 2017-2021 Norman Breau Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Database = void 0; const tslib_1 = require("tslib"); const Crypto = tslib_1.__importStar(require("node:crypto")); const instance_1 = require("./instance"); const MASTER_NAME = 'MASTER'; const TAG = 'Database'; class Database { constructor() { this.$clusterConfigMap = {}; } addMaster(config) { if (this.$clusterConfigMap[MASTER_NAME]) { throw new Error(`Node "${MASTER_NAME}" already exists.`); } this.$clusterConfigMap[MASTER_NAME] = config; this._addNode(MASTER_NAME, config); } removeMaster() { delete this.$clusterConfigMap[MASTER_NAME]; this._removeNode(MASTER_NAME); } addSlave(slaveID, config) { let id = `SLAVE.${Crypto.randomUUID()}.${slaveID}`; this.$clusterConfigMap[id] = config; this._addNode(id, config); return id; } removeSlave(slaveID) { if (!this.$clusterConfigMap[slaveID]) { (0, instance_1.getInstance)().getLogger().warn(TAG, `Node ${slaveID} is not a part of this cluster.`); return; } delete this.$clusterConfigMap[slaveID]; this._removeNode(slaveID); } getConnection(requireWriteAccess = false, nodeID, requiredPosition) { let query = 'SLAVE*'; if (nodeID) { query = nodeID; } else if (requireWriteAccess) { query = 'MASTER'; } return this._getConnection(query, requireWriteAccess, requiredPosition); } destroy() { return this._destroy(); } } exports.Database = Database; //# sourceMappingURL=Database.js.map