UNPKG

ravendb

Version:
67 lines 2.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MaintenanceOperationExecutor = void 0; const OperationCompletionAwaiter_js_1 = require("./OperationCompletionAwaiter.js"); const ServerOperationExecutor_js_1 = require("./ServerOperationExecutor.js"); const index_js_1 = require("../../Exceptions/index.js"); const TypeUtil_js_1 = require("../../Utility/TypeUtil.js"); class MaintenanceOperationExecutor { _store; _nodeTag; _shardNumber; _databaseName; _requestExecutor; _serverOperationExecutor; constructor(store, databaseName, nodeTag, shardNumber) { this._store = store; this._databaseName = databaseName || store.database; this._nodeTag = nodeTag; this._shardNumber = shardNumber; } get requestExecutor() { if (this._requestExecutor) { return this._requestExecutor; } this._requestExecutor = this._databaseName ? this._store.getRequestExecutor(this._databaseName) : null; return this.requestExecutor; } get server() { if (!this._serverOperationExecutor) { this._serverOperationExecutor = new ServerOperationExecutor_js_1.ServerOperationExecutor(this._store); } return this._serverOperationExecutor; } forDatabase(databaseName) { if (this._databaseName && this._databaseName.toLowerCase() === (databaseName || "").toLowerCase()) { return this; } return new MaintenanceOperationExecutor(this._store, databaseName, this._nodeTag, this._shardNumber); } async send(operation) { this._assertDatabaseNameSet(); const command = operation.getCommand(this.requestExecutor.conventions); this.applyNodeTagAndShardNumberToCommandIfSet(command); await this.requestExecutor.execute(command); if (operation.resultType === "OperationId") { const idResult = command.result; return new OperationCompletionAwaiter_js_1.OperationCompletionAwaiter(this.requestExecutor, this.requestExecutor.conventions, idResult.operationId, command.selectedNodeTag || idResult.operationNodeTag); } return command.result; } _assertDatabaseNameSet() { if (!this._databaseName) { (0, index_js_1.throwError)("InvalidOperationException", "Cannot use maintenance without a database defined, did you forget to call forDatabase?"); } } applyNodeTagAndShardNumberToCommandIfSet(command) { if (this._nodeTag) { command.selectedNodeTag = this._nodeTag; } if (!TypeUtil_js_1.TypeUtil.isNullOrUndefined(this._shardNumber)) { command.selectedShardNumber = this._shardNumber; } } } exports.MaintenanceOperationExecutor = MaintenanceOperationExecutor; //# sourceMappingURL=MaintenanceOperationExecutor.js.map