35 lines
857 B
TypeScript
35 lines
857 B
TypeScript
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 mongod: plugins.mongoPlugin.MongoMemoryServer;
|
|
|
|
constructor() {
|
|
}
|
|
|
|
public async start() {
|
|
this.mongod = await plugins.mongoPlugin.MongoMemoryServer.create();
|
|
this._readyDeferred.resolve();
|
|
console.log('mongod started');
|
|
}
|
|
|
|
public async getMongoDescriptor(): Promise<plugins.smartdata.IMongoDescriptor> {
|
|
await this.readyPromise;
|
|
return {
|
|
mongoDbUrl: this.mongod.getUri(),
|
|
}
|
|
}
|
|
|
|
public async stop() {
|
|
this.mongod.stop();
|
|
}
|
|
} |