import * as plugins from './smartmongo.plugins'; export class SmartMongo { // STATIC public static async createAndStart() { const smartMongoInstance = new SmartMongo(); await smartMongoInstance.start(); return smartMongoInstance; } // INSTANCE private _readyDeferred = plugins.smartpromise.defer(); public readyPromise = this._readyDeferred.promise; public mongoReplicaSet: plugins.mongoPlugin.MongoMemoryReplSet; constructor() { } public async start(countArg: number = 4) { this.mongoReplicaSet = await plugins.mongoPlugin.MongoMemoryReplSet.create({ replSet: { count: countArg } }); this._readyDeferred.resolve(); console.log(`mongoReplicaSet with ${countArg} replicas started.`); } public async getMongoDescriptor(): Promise { await this.readyPromise; return { mongoDbUrl: this.mongoReplicaSet.getUri(), } } public async stop() { await this.mongoReplicaSet.stop(true); } }