couchbase-index-manager
Version:
Manage Couchbase indexes during the CI/CD process
49 lines • 1.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConnectionManager = void 0;
const couchbase_1 = require("couchbase");
const index_manager_1 = require("./index-manager");
/**
* @private
* Wraps a process in a Couchbase connection with IndexManager
*/
class ConnectionManager {
constructor(connectionInfo) {
this.connectionInfo = connectionInfo;
}
/**
* Runs the process
*/
async execute(handler) {
const manager = await this.bootstrap();
try {
const result = await handler(manager);
return result;
}
finally {
await this.close();
}
}
/**
* Bootstraps the Couchbase connection.
*/
async bootstrap() {
this.cluster = await (0, couchbase_1.connect)(this.connectionInfo.cluster, {
username: this.connectionInfo.username,
password: this.connectionInfo.password,
});
this.bucket = this.cluster.bucket(this.connectionInfo.bucketName);
return new index_manager_1.IndexManager(this.bucket, this.cluster);
}
/**
* Closes the Couchbase connection.
*/
async close() {
var _a;
await ((_a = this.cluster) === null || _a === void 0 ? void 0 : _a.close());
this.cluster = undefined;
this.bucket = undefined;
}
}
exports.ConnectionManager = ConnectionManager;
//# sourceMappingURL=connection-manager.js.map