Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5eed702631 | |||
| ac5ce0346b | |||
| eabda34aca | |||
| 0e41748da5 | |||
| f4586d529d | |||
| c09eaf613d | |||
| d5ff5b0ed8 | |||
| 1783d72395 | |||
| a01755fb9e | |||
| 3ebf34ee9d | |||
| b71a238a3d | |||
| d0c7a95e16 | |||
| ed38ff50e7 | |||
| 0a3be3e7f4 |
1599
package-lock.json
generated
1599
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
16
package.json
16
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartmongo",
|
"name": "@pushrocks/smartmongo",
|
||||||
"version": "2.0.0",
|
"version": "2.0.7",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "create a local mongodb for testing",
|
"description": "create a local mongodb for testing",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@@ -10,19 +10,21 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/ --web)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web --allowimplicitany)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.61",
|
"@gitzone/tsbuild": "^2.1.63",
|
||||||
"@gitzone/tsbundle": "^2.0.3",
|
"@gitzone/tsbundle": "^2.0.5",
|
||||||
"@gitzone/tstest": "^1.0.71",
|
"@gitzone/tstest": "^1.0.71",
|
||||||
"@pushrocks/tapbundle": "^5.0.3",
|
"@pushrocks/tapbundle": "^5.0.3",
|
||||||
"@types/node": "^17.0.34"
|
"@types/node": "^17.0.39"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdata": "^4.0.27",
|
"@pushrocks/mongodump": "^1.0.7",
|
||||||
|
"@pushrocks/smartdata": "^5.0.3",
|
||||||
|
"@pushrocks/smartpath": "^5.0.5",
|
||||||
"@pushrocks/smartpromise": "^3.1.7",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"mongodb-memory-server": "^8.5.2"
|
"mongodb-memory-server": "^8.6.0"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ tap.test('should create a mongo instance', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should stop the instance', async () => {
|
tap.test('should stop the instance', async () => {
|
||||||
await smartmongoInstance.stop();
|
await smartmongoInstance.stopAndDumpToDir('.nogit/');
|
||||||
})
|
})
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smartmongo',
|
name: '@pushrocks/smartmongo',
|
||||||
version: '2.0.0',
|
version: '2.0.7',
|
||||||
description: 'create a local mongodb for testing'
|
description: 'create a local mongodb for testing'
|
||||||
}
|
}
|
||||||
|
|||||||
40
ts/index.ts
40
ts/index.ts
@@ -14,24 +14,52 @@ export class SmartMongo {
|
|||||||
public readyPromise = this._readyDeferred.promise;
|
public readyPromise = this._readyDeferred.promise;
|
||||||
public mongoReplicaSet: plugins.mongoPlugin.MongoMemoryReplSet;
|
public mongoReplicaSet: plugins.mongoPlugin.MongoMemoryReplSet;
|
||||||
|
|
||||||
constructor() {
|
constructor() {}
|
||||||
}
|
|
||||||
|
|
||||||
public async start(countArg: number = 1) {
|
public async start(countArg: number = 1) {
|
||||||
this.mongoReplicaSet = await plugins.mongoPlugin.MongoMemoryReplSet.create({ replSet: { count: countArg } });
|
this.mongoReplicaSet = await plugins.mongoPlugin.MongoMemoryReplSet.create({
|
||||||
|
replSet: { count: countArg },
|
||||||
|
instanceOpts: [
|
||||||
|
{
|
||||||
|
storageEngine: 'wiredTiger',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
this._readyDeferred.resolve();
|
this._readyDeferred.resolve();
|
||||||
console.log(`mongoReplicaSet with ${countArg} replicas started.`);
|
console.log(`mongoReplicaSet with ${countArg} replicas started.`);
|
||||||
console.log(`@pushrocks/smartmongo version ${commitinfo.version}`);
|
console.log(`@pushrocks/smartmongo version ${commitinfo.version}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns a mongo descriptor for modules like
|
||||||
|
* @pushrocks/smartfile.
|
||||||
|
*/
|
||||||
public async getMongoDescriptor(): Promise<plugins.smartdata.IMongoDescriptor> {
|
public async getMongoDescriptor(): Promise<plugins.smartdata.IMongoDescriptor> {
|
||||||
await this.readyPromise;
|
await this.readyPromise;
|
||||||
return {
|
return {
|
||||||
|
mongoDbName: `smartmongo_testdatabase`,
|
||||||
mongoDbUrl: this.mongoReplicaSet.getUri(),
|
mongoDbUrl: this.mongoReplicaSet.getUri(),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stops the smartmongo instance
|
||||||
|
* and cleans up after itself
|
||||||
|
*/
|
||||||
public async stop() {
|
public async stop() {
|
||||||
await this.mongoReplicaSet.stop(true);
|
await this.mongoReplicaSet.stop();
|
||||||
|
await this.mongoReplicaSet.cleanup();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* like stop() but allows you to actually store
|
||||||
|
* the database on disk
|
||||||
|
*/
|
||||||
|
public async stopAndDumpToDir(dirArg: string, nameFunctionArg?: (doc: any) => string, emptyDirArg = true) {
|
||||||
|
const mongodumpInstance = new plugins.mongodump.MongoDump();
|
||||||
|
const mongodumpTarget = await mongodumpInstance.addMongoTargetByMongoDescriptor(await this.getMongoDescriptor());
|
||||||
|
await mongodumpTarget.dumpAllCollectionsToDir(dirArg, nameFunctionArg, emptyDirArg);
|
||||||
|
await mongodumpInstance.stop();
|
||||||
|
await this.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
// @pushrocks scope
|
// @pushrocks scope
|
||||||
|
import * as mongodump from '@pushrocks/mongodump';
|
||||||
import * as smartdata from '@pushrocks/smartdata';
|
import * as smartdata from '@pushrocks/smartdata';
|
||||||
|
import * as smartpath from '@pushrocks/smartpath';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
mongodump,
|
||||||
smartdata,
|
smartdata,
|
||||||
|
smartpath,
|
||||||
smartpromise,
|
smartpromise,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user