8 Commits

Author SHA1 Message Date
e01d09e40a 1.0.9 2022-05-17 17:16:12 +02:00
96cb2f2a3a fix(core): update 2022-05-17 17:16:12 +02:00
9414dac380 1.0.8 2021-12-21 01:54:04 +01:00
160e350b82 fix(core): update 2021-12-21 01:54:04 +01:00
457de52134 1.0.7 2021-12-20 17:07:40 +01:00
997a662d63 fix(core): update 2021-12-20 17:07:39 +01:00
0f81392b8e 1.0.6 2021-12-20 17:02:20 +01:00
9c5f5ea44e fix(core): update 2021-12-20 17:02:19 +01:00
5 changed files with 20 additions and 12 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@pushrocks/smartmongo",
"version": "1.0.5",
"version": "1.0.9",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@pushrocks/smartmongo",
"version": "1.0.5",
"version": "1.0.9",
"license": "MIT",
"dependencies": {
"@pushrocks/smartdata": "^4.0.27",

View File

@@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartmongo",
"version": "1.0.5",
"version": "1.0.9",
"private": false,
"description": "create a local mongodb for testing",
"main": "dist_ts/index.js",

View File

@@ -4,7 +4,7 @@ import * as smartmongo from '../ts/index';
let smartmongoInstance: smartmongo.SmartMongo;
tap.test('should create a mongo instance', async () => {
smartmongoInstance = await smartmongo.SmartMongo.createAndInit();
smartmongoInstance = await smartmongo.SmartMongo.createAndStart();
});
tap.test('should stop the instance', async () => {

8
ts/00_commitinfo_data.ts Normal file
View File

@@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartmongo',
version: '1.0.9',
description: 'create a local mongodb for testing'
}

View File

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