@configurator/ravendb
Version:
RavenDB client for Node.js
49 lines • 2.21 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MaintenanceOperationExecutor = void 0;
const OperationCompletionAwaiter_1 = require("./OperationCompletionAwaiter");
const ServerOperationExecutor_1 = require("./ServerOperationExecutor");
const Exceptions_1 = require("../../Exceptions");
class MaintenanceOperationExecutor {
constructor(store, databaseName) {
this._store = store;
this._databaseName = databaseName || store.database;
}
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_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);
}
async send(operation) {
this._assertDatabaseNameSet();
const command = operation.getCommand(this.requestExecutor.conventions);
await this.requestExecutor.execute(command);
if (operation.resultType === "OperationId") {
const idResult = command.result;
return new OperationCompletionAwaiter_1.OperationCompletionAwaiter(this.requestExecutor, this.requestExecutor.conventions, idResult.operationId, command.selectedNodeTag || idResult.operationNodeTag);
}
return command.result;
}
_assertDatabaseNameSet() {
if (!this._databaseName) {
(0, Exceptions_1.throwError)("InvalidOperationException", "Cannot use maintenance without a database defined, did you forget to call forDatabase?");
}
}
}
exports.MaintenanceOperationExecutor = MaintenanceOperationExecutor;
//# sourceMappingURL=MaintenanceOperationExecutor.js.map