2021-12-20 14:58:23 +00:00
|
|
|
import * as plugins from './smartmongo.plugins';
|
|
|
|
|
|
|
|
export class SmartMongo {
|
|
|
|
// STATIC
|
2021-12-20 16:02:19 +00:00
|
|
|
public static async createAndStart() {
|
2021-12-20 14:58:23 +00:00
|
|
|
const smartMongoInstance = new SmartMongo();
|
2021-12-20 16:02:19 +00:00
|
|
|
await smartMongoInstance.start();
|
2021-12-20 14:58:23 +00:00
|
|
|
return smartMongoInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
// INSTANCE
|
|
|
|
private _readyDeferred = plugins.smartpromise.defer();
|
|
|
|
public readyPromise = this._readyDeferred.promise;
|
|
|
|
public mongod: plugins.mongoPlugin.MongoMemoryServer;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
}
|
|
|
|
|
2021-12-20 16:02:19 +00:00
|
|
|
public async start() {
|
2021-12-20 14:58:23 +00:00
|
|
|
this.mongod = await plugins.mongoPlugin.MongoMemoryServer.create();
|
|
|
|
this._readyDeferred.resolve();
|
|
|
|
console.log('mongod started');
|
|
|
|
}
|
|
|
|
|
2021-12-20 15:24:04 +00:00
|
|
|
public async getMongoDescriptor(): Promise<plugins.smartdata.IMongoDescriptor> {
|
2021-12-20 14:58:23 +00:00
|
|
|
await this.readyPromise;
|
|
|
|
return {
|
|
|
|
mongoDbUrl: this.mongod.getUri(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public async stop() {
|
|
|
|
this.mongod.stop();
|
|
|
|
}
|
|
|
|
}
|