@apipass/mongo-memory-server 0.0.35 → 0.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
1
3
|
export declare abstract class MongodbMemoryServerSetup {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
+
mongoDb: MongoMemoryServer | null;
|
|
5
|
+
client: typeof mongoose | null;
|
|
4
6
|
abstract databaseName: string;
|
|
5
7
|
initialize(): Promise<void>;
|
|
6
8
|
connectDatabase(): Promise<void>;
|
|
@@ -13,6 +13,10 @@ exports.MongodbMemoryServerSetup = void 0;
|
|
|
13
13
|
const mongodb_memory_server_1 = require("mongodb-memory-server");
|
|
14
14
|
const mongoose = require("mongoose");
|
|
15
15
|
class MongodbMemoryServerSetup {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.mongoDb = null;
|
|
18
|
+
this.client = null;
|
|
19
|
+
}
|
|
16
20
|
initialize() {
|
|
17
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
22
|
yield this.connectDatabase();
|
|
@@ -21,10 +25,10 @@ class MongodbMemoryServerSetup {
|
|
|
21
25
|
}
|
|
22
26
|
connectDatabase() {
|
|
23
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
if (!
|
|
25
|
-
|
|
28
|
+
if (!this.mongoDb) {
|
|
29
|
+
this.mongoDb = yield mongodb_memory_server_1.MongoMemoryServer.create();
|
|
26
30
|
}
|
|
27
|
-
|
|
31
|
+
this.client = yield mongoose.connect(this.mongoDb.getUri(), {
|
|
28
32
|
dbName: this.databaseName,
|
|
29
33
|
autoCreate: true
|
|
30
34
|
});
|
|
@@ -32,19 +36,17 @@ class MongodbMemoryServerSetup {
|
|
|
32
36
|
}
|
|
33
37
|
disconnectDatabase() {
|
|
34
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
if (
|
|
39
|
+
if (this.client) {
|
|
36
40
|
yield mongoose.connection.dropDatabase();
|
|
37
41
|
yield mongoose.disconnect();
|
|
38
42
|
}
|
|
39
|
-
if (
|
|
40
|
-
yield
|
|
43
|
+
if (this.mongoDb) {
|
|
44
|
+
yield this.mongoDb.stop();
|
|
41
45
|
}
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
this.client = null;
|
|
47
|
+
this.mongoDb = null;
|
|
44
48
|
});
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
51
|
exports.MongodbMemoryServerSetup = MongodbMemoryServerSetup;
|
|
48
|
-
MongodbMemoryServerSetup.mongoDb = null;
|
|
49
|
-
MongodbMemoryServerSetup.client = null;
|
|
50
52
|
//# sourceMappingURL=mongodb-memory-server.setup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb-memory-server.setup.js","sourceRoot":"","sources":["../src/mongodb-memory-server.setup.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAAyD;AACzD,qCAAoC;AAEpC,MAAsB,wBAAwB;
|
|
1
|
+
{"version":3,"file":"mongodb-memory-server.setup.js","sourceRoot":"","sources":["../src/mongodb-memory-server.setup.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAAyD;AACzD,qCAAoC;AAEpC,MAAsB,wBAAwB;IAA9C;QACS,YAAO,GAA6B,IAAI,CAAA;QACxC,WAAM,GAA2B,IAAI,CAAA;IA+B9C,CAAC;IA5Bc,UAAU;;YACrB,MAAM,IAAI,CAAC,eAAe,EAAE,CAAA;YAC5B,MAAM,IAAI,CAAC,eAAe,EAAE,CAAA;QAC9B,CAAC;KAAA;IAEY,eAAe;;YAC1B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBAClB,IAAI,CAAC,OAAO,GAAG,MAAM,yCAAiB,CAAC,MAAM,EAAE,CAAA;YACjD,CAAC;YACD,IAAI,CAAC,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE;gBAC1D,MAAM,EAAE,IAAI,CAAC,YAAY;gBACzB,UAAU,EAAE,IAAI;aACjB,CAAC,CAAA;QACJ,CAAC;KAAA;IAIY,kBAAkB;;YAC7B,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBAChB,MAAM,QAAQ,CAAC,UAAU,CAAC,YAAY,EAAE,CAAA;gBACxC,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAA;YAC7B,CAAC;YACD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBACjB,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAA;YAC3B,CAAC;YACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;YAClB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACrB,CAAC;KAAA;CACF;AAjCD,4DAiCC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apipass/mongo-memory-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.36",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"scripts": {
|
|
23
23
|
"tsc": "tsc"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "a002e65c0404e05a9d0e36fff4a9097f4955d315"
|
|
26
26
|
}
|