@villedemontreal/mongo 6.7.1 → 7.0.0-beta
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.
- package/dist/src/config/configs.d.ts +1 -1
- package/dist/src/config/configs.js.map +1 -1
- package/dist/src/config/constants.d.ts +1 -1
- package/dist/src/config/constants.js +12 -12
- package/dist/src/config/constants.js.map +1 -1
- package/dist/src/config/init.js.map +1 -1
- package/dist/src/config/mongooseConfigs.js +8 -6
- package/dist/src/config/mongooseConfigs.js.map +1 -1
- package/dist/src/index.js +6 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/mongoClient.js +3 -3
- package/dist/src/mongoClient.js.map +1 -1
- package/dist/src/mongoUpdater.js +24 -21
- package/dist/src/mongoUpdater.js.map +1 -1
- package/dist/src/mongoUpdater.test.js +2 -2
- package/dist/src/mongoUpdater.test.js.map +1 -1
- package/dist/src/mongoUtils.d.ts +1 -1
- package/dist/src/mongoUtils.js +11 -11
- package/dist/src/mongoUtils.js.map +1 -1
- package/dist/src/mongoUtils.test.js +0 -1
- package/dist/src/mongoUtils.test.js.map +1 -1
- package/dist/src/plugins/pagination/index.js +9 -12
- package/dist/src/plugins/pagination/index.js.map +1 -1
- package/dist/src/plugins/pagination/index.test.js +20 -12
- package/dist/src/plugins/pagination/index.test.js.map +1 -1
- package/dist/src/utils/logger.js +1 -1
- package/dist/src/utils/logger.js.map +1 -1
- package/dist/src/utils/testingConfigurations.js +1 -1
- package/dist/src/utils/testingConfigurations.js.map +1 -1
- package/dist/tests/testingMongoUpdates/1.0.0.js +3 -3
- package/dist/tests/testingMongoUpdates/1.0.1.js +3 -3
- package/package.json +16 -13
- package/src/config/configs.ts +1 -1
- package/src/config/constants.ts +13 -13
- package/src/config/init.ts +1 -1
- package/src/config/mongooseConfigs.ts +30 -12
- package/src/mongoClient.ts +10 -4
- package/src/mongoUpdater.test.ts +20 -8
- package/src/mongoUpdater.ts +41 -25
- package/src/mongoUtils.ts +20 -14
- package/src/plugins/pagination/index.test.ts +38 -27
- package/src/plugins/pagination/index.ts +19 -14
- package/src/utils/logger.ts +8 -1
|
@@ -25,23 +25,20 @@ class PaginateBuilder {
|
|
|
25
25
|
// only to prevent "'leanWithId' is declared but its value is never read"
|
|
26
26
|
}
|
|
27
27
|
if (limit > 0) {
|
|
28
|
-
itemsQuery = model
|
|
29
|
-
.find(query)
|
|
30
|
-
.select(select)
|
|
31
|
-
.sort(sort)
|
|
32
|
-
.skip(offset)
|
|
33
|
-
.limit(limit)
|
|
34
|
-
.lean(lean);
|
|
28
|
+
itemsQuery = model.find(query).select(select).sort(sort).skip(offset).limit(limit).lean(lean);
|
|
35
29
|
if (populate) {
|
|
36
|
-
[].concat(populate).forEach(item => itemsQuery.populate(item));
|
|
30
|
+
[].concat(populate).forEach((item) => itemsQuery.populate(item));
|
|
37
31
|
}
|
|
38
32
|
}
|
|
39
|
-
return [
|
|
33
|
+
return [
|
|
34
|
+
itemsQuery && limit > 0 ? itemsQuery.exec() : Promise.resolve([]),
|
|
35
|
+
model.countDocuments(query).exec(),
|
|
36
|
+
];
|
|
40
37
|
}
|
|
41
38
|
static processResult(promises, options, callback) {
|
|
42
39
|
const { lean, leanWithId, limit, offset } = options;
|
|
43
40
|
return new Promise((resolve, reject) => {
|
|
44
|
-
Promise.all(promises).then(data => {
|
|
41
|
+
Promise.all(promises).then((data) => {
|
|
45
42
|
const items = data[0];
|
|
46
43
|
const count = data[1];
|
|
47
44
|
const result = { paging: { limit, offset, totalCount: count } };
|
|
@@ -60,7 +57,7 @@ class PaginateBuilder {
|
|
|
60
57
|
return callback(null, result);
|
|
61
58
|
}
|
|
62
59
|
resolve(result);
|
|
63
|
-
}, error => {
|
|
60
|
+
}, (error) => {
|
|
64
61
|
if (typeof callback === 'function') {
|
|
65
62
|
return callback(error, null);
|
|
66
63
|
}
|
|
@@ -74,6 +71,6 @@ PaginateBuilder.defaultOptions = Object.freeze({
|
|
|
74
71
|
lean: false,
|
|
75
72
|
leanWithId: true,
|
|
76
73
|
limit: 10,
|
|
77
|
-
offset: 0
|
|
74
|
+
offset: 0,
|
|
78
75
|
});
|
|
79
76
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/pagination/index.ts"],"names":[],"mappings":";;;AAEA,SAAS,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/pagination/index.ts"],"names":[],"mappings":";;;AAEA,SAAS,QAAQ,CACf,CAAM,EACN,OAAyB,EACzB,QAA6C;IAE7C,MAAM,YAAY,GAAG,eAAe,CAAC,UAAU,CAAE,QAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAEpF,MAAM,KAAK,GAAG,CAAC,IAAI,EAAE,CAAC;IACtB,MAAM,QAAQ,GAAG,eAAe,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;IAE3E,OAAO,eAAe,CAAC,aAAa,CAAC,QAAQ,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC;AACzE,CAAC;AAED;;GAEG;AAEH,SAAgB,gBAAgB,CAAC,MAAW;IAC1C,MAAM,CAAC,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACrC,CAAC;AAFD,4CAEC;AAED,MAAa,eAAe;IAQnB,MAAM,CAAC,UAAU,CAAC,GAAG,OAA2B;QACrD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,eAAe,CAAC,cAAc,EAAE,GAAG,OAAO,CAAC,CAAC;IACvE,CAAC;IAEM,MAAM,CAAC,cAAc,CAC1B,KAAU,EACV,KAAU,EACV,OAAyB;QAEzB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAC5E,IAAI,UAAe,CAAC;QAEpB,IAAI,U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EAAE;oBACtB,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,GAAQ,EAAE,EAAE;wBACpC,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;wBACzB,OAAO,GAAG,CAAC,GAAG,CAAC;wBACf,OAAO,GAAG,CAAC,GAAG,CAAC;wBACf,OAAO,GAAG,CAAC;oBACb,CAAC,CAAC,CAAC;iBACJ;qBAAM;oBACL,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;iBACtB;gBAED,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;oBAClC,OAAO,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;iBAC/B;gBAED,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC,EACD,CAAC,KAAK,EAAE,EAAE;gBACR,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;oBAClC,OAAO,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;iBAC9B;gBACD,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;;AA5EH,0CA6EC;AA5EyB,8BAAc,GAAG,MAAM,CAAC,MAAM,CAAC;IACrD,IAAI,EAAE,KAAK;IACX,UAAU,EAAE,IAAI;IAChB,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,CAAC;CACV,CAAC,CAAC"}
|
|
@@ -15,8 +15,8 @@ const bookSchema = new mongoose.Schema({
|
|
|
15
15
|
date: Date,
|
|
16
16
|
author: {
|
|
17
17
|
type: String,
|
|
18
|
-
ref: 'Author'
|
|
19
|
-
}
|
|
18
|
+
ref: 'Author',
|
|
19
|
+
},
|
|
20
20
|
});
|
|
21
21
|
bookSchema.plugin(index_1.mongoosePaginate);
|
|
22
22
|
const bookModel = mongoose.model('Book', bookSchema);
|
|
@@ -26,19 +26,19 @@ describe('plugin pagination', () => {
|
|
|
26
26
|
// Makes sure Mongoose is mocked, but not in Jenkins as we will start a dedicated mongodb container.
|
|
27
27
|
const mockedDb = await mongoUtils_1.mongoUtils.mockMongoose(this, constants_1.constants.testsConfig.mockServer.serverVersion);
|
|
28
28
|
const connString = mockedDb.getUri();
|
|
29
|
-
await mongoose.connect(connString
|
|
29
|
+
await mongoose.connect(connString);
|
|
30
30
|
});
|
|
31
31
|
before(async function () {
|
|
32
32
|
this.timeout(10000);
|
|
33
33
|
let book;
|
|
34
34
|
const books = [];
|
|
35
35
|
const date = new Date();
|
|
36
|
-
return authorModel.create({ name: 'Arthur Conan Doyle' }).then(author => {
|
|
36
|
+
return authorModel.create({ name: 'Arthur Conan Doyle' }).then((author) => {
|
|
37
37
|
for (let i = 1; i <= 100; i++) {
|
|
38
38
|
book = new bookModel({
|
|
39
39
|
title: 'Book #' + i,
|
|
40
40
|
date: new Date(date.getTime() + i),
|
|
41
|
-
author: author._id
|
|
41
|
+
author: author._id,
|
|
42
42
|
});
|
|
43
43
|
books.push(book);
|
|
44
44
|
}
|
|
@@ -49,7 +49,7 @@ describe('plugin pagination', () => {
|
|
|
49
49
|
const promise = bookModel.paginate();
|
|
50
50
|
expect(promise.then).to.be.an.instanceof(Function);
|
|
51
51
|
});
|
|
52
|
-
it('calls callback', done => {
|
|
52
|
+
it('calls callback', (done) => {
|
|
53
53
|
bookModel.paginate({}, {}, (err, result) => {
|
|
54
54
|
expect(err).to.be.null;
|
|
55
55
|
expect(result).to.be.an.instanceOf(Object);
|
|
@@ -73,7 +73,9 @@ describe('plugin pagination', () => {
|
|
|
73
73
|
});
|
|
74
74
|
});
|
|
75
75
|
it('with offset and limit', () => {
|
|
76
|
-
return bookModel
|
|
76
|
+
return bookModel
|
|
77
|
+
.paginate({}, { offset: 30, limit: 20 })
|
|
78
|
+
.then((result) => {
|
|
77
79
|
expect(result.items).to.have.length(20);
|
|
78
80
|
expect(result.paging.totalCount).to.equal(100);
|
|
79
81
|
expect(result.paging.limit).to.equal(20);
|
|
@@ -94,12 +96,16 @@ describe('plugin pagination', () => {
|
|
|
94
96
|
});
|
|
95
97
|
});
|
|
96
98
|
it('with sort', () => {
|
|
97
|
-
return bookModel
|
|
99
|
+
return bookModel
|
|
100
|
+
.paginate({}, { sort: { date: -1 } })
|
|
101
|
+
.then((result) => {
|
|
98
102
|
expect(result.items[0].title).to.equal('Book #100');
|
|
99
103
|
});
|
|
100
104
|
});
|
|
101
105
|
it('with populate', () => {
|
|
102
|
-
return bookModel
|
|
106
|
+
return bookModel
|
|
107
|
+
.paginate({}, { populate: 'author' })
|
|
108
|
+
.then((result) => {
|
|
103
109
|
expect(result.items[0].author.name).to.equal('Arthur Conan Doyle');
|
|
104
110
|
});
|
|
105
111
|
});
|
|
@@ -112,17 +118,19 @@ describe('plugin pagination', () => {
|
|
|
112
118
|
});
|
|
113
119
|
});
|
|
114
120
|
it('with leanWithId=false', () => {
|
|
115
|
-
return bookModel
|
|
121
|
+
return bookModel
|
|
122
|
+
.paginate({}, { lean: true, leanWithId: false })
|
|
123
|
+
.then((result) => {
|
|
116
124
|
expect(result.items[0]).to.not.be.an.instanceof(mongoose.Document);
|
|
117
125
|
expect(result.items[0]).to.not.have.property('id');
|
|
118
126
|
});
|
|
119
127
|
});
|
|
120
128
|
});
|
|
121
129
|
});
|
|
122
|
-
after(done => {
|
|
130
|
+
after((done) => {
|
|
123
131
|
mongoose.connection.db.dropDatabase(done);
|
|
124
132
|
});
|
|
125
|
-
after(done => {
|
|
133
|
+
after((done) => {
|
|
126
134
|
mongoose.disconnect(done);
|
|
127
135
|
});
|
|
128
136
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../../../src/plugins/pagination/index.test.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,sCAAsC;;AAGtC,6BAA6B;AAC7B,qCAAqC;AACrC,sDAAmD;AACnD,iDAA8C;AAC9C,mCAA2C;AAE3C,MAAM,MAAM,GAAG,IAAI,CA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C,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACtD,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YACH,EAAE,CAAC,uBAAuB,EAAE,GAAG,EAAE;gBAC/B,OAAO,SAAS;qBACb,QAAQ,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;qBAC/C,IAAI,CAAC,CAAC,MAA6B,EAAE,EAAE;oBACtC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAE,QAAgB,CAAC,QAAQ,CAAC,CAAC;oBAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;gBACrD,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE;QACb,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE;QACb,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/src/utils/logger.js
CHANGED
|
@@ -34,7 +34,7 @@ exports.createLogger = createLogger;
|
|
|
34
34
|
function initTestingLoggerConfigs() {
|
|
35
35
|
const loggerConfig = new logger_1.LoggerConfigs(() => 'test-cid');
|
|
36
36
|
loggerConfig.setLogLevel(logger_1.LogLevel.DEBUG);
|
|
37
|
-
logger_1.initLogger(loggerConfig);
|
|
37
|
+
(0, logger_1.initLogger)(loggerConfig);
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* A Logger that uses a dummy cid provider.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/utils/logger.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/utils/logger.ts"],"names":[],"mappings":";;;AAAA,oDAOiC;AACjC,+CAA4C;AAE5C,IAAI,2BAA2B,GAAG,KAAK,CAAC;AAExC;;GAEG;AACH,SAAgB,YAAY,CAAC,IAAY;IACvC,6CAA6C;IAC7C,yCAAyC;IACzC,iCAAiC;IACjC,8CAA8C;IAC9C,4CAA4C;IAC5C,oDAAoD;IACpD,EAAE;IACF,6CAA6C;IAC7C,uCAAuC;IACvC,gCAAgC;IAChC,EAAE;IACF,yCAAyC;IACzC,EAAE;IACF,oDAAoD;IACpD,+CAA+C;IAC/C,qDAAqD;IACrD,mDAAmD;IACnD,6CAA6C;IAC7C,OAAO,IAAI,mBAAU,CAAC,IAAI,EAAE,CAAC,OAAe,EAAE,EAAE;QAC9C,OAAO,iBAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC;AAtBD,oCAsBC;AAED,SAAS,wBAAwB;IAC/B,MAAM,YAAY,GAAkB,IAAI,sBAAa,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC;IACxE,YAAY,CAAC,WAAW,CAAC,iBAAQ,CAAC,KAAK,CAAC,CAAC;IACzC,IAAA,mBAAU,EAAC,YAAY,CAAC,CAAC;AAC3B,CAAC;AAED;;;;GAIG;AACH,SAAgB,uBAAuB;IACrC,OAAO,CAAC,IAAY,EAAW,EAAE;QAC/B,IAAI,CAAC,2BAA2B,EAAE;YAChC,wBAAwB,EAAE,CAAC;YAC3B,2BAA2B,GAAG,IAAI,CAAC;SACpC;QAED,OAAO,IAAI,eAAM,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC,CAAC;AACJ,CAAC;AATD,0DASC"}
|
|
@@ -11,7 +11,7 @@ const logger_1 = require("../utils/logger");
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
function setTestingConfigurations() {
|
|
14
|
-
configs_1.configs.setLoggerCreator(logger_1.getTestingLoggerCreator());
|
|
14
|
+
configs_1.configs.setLoggerCreator((0, logger_1.getTestingLoggerCreator)());
|
|
15
15
|
}
|
|
16
16
|
exports.setTestingConfigurations = setTestingConfigurations;
|
|
17
17
|
//# sourceMappingURL=testingConfigurations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testingConfigurations.js","sourceRoot":"","sources":["../../../src/utils/testingConfigurations.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAC5C,4CAA0D;AAE1D;;;;;;GAMG;AACH,SAAgB,wBAAwB;IACtC,iBAAO,CAAC,gBAAgB,CAAC,gCAAuB,
|
|
1
|
+
{"version":3,"file":"testingConfigurations.js","sourceRoot":"","sources":["../../../src/utils/testingConfigurations.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAC5C,4CAA0D;AAE1D;;;;;;GAMG;AACH,SAAgB,wBAAwB;IACtC,iBAAO,CAAC,gBAAgB,CAAC,IAAA,gCAAuB,GAAE,CAAC,CAAC;AACtD,CAAC;AAFD,4DAEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@villedemontreal/mongo",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-beta",
|
|
4
4
|
"description": "Utilities for Mongo / Mongoose",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"typings": "dist/src",
|
|
@@ -10,12 +10,10 @@
|
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
12
|
"start": "node run test",
|
|
13
|
-
"test": "
|
|
13
|
+
"test": "npm run compile && mocha --require ts-node/register --exit ./**/*.test.ts",
|
|
14
14
|
"compile": "node run compile",
|
|
15
|
-
"lint": "
|
|
16
|
-
"lint-fix": "
|
|
17
|
-
"tslint": "node run tslint",
|
|
18
|
-
"tslint-fix": "node run tslint-fix",
|
|
15
|
+
"lint": "npx eslint .",
|
|
16
|
+
"lint-fix": "npx eslint --fix .",
|
|
19
17
|
"prettier": "node run prettier",
|
|
20
18
|
"prettier-fix": "node run prettier-fix",
|
|
21
19
|
"watch": "node run watch"
|
|
@@ -42,22 +40,27 @@
|
|
|
42
40
|
"fs-extra": "10.0.1",
|
|
43
41
|
"http-status-codes": "2.2.0",
|
|
44
42
|
"lodash": "4.17.21",
|
|
45
|
-
"mongodb": "
|
|
46
|
-
"mongodb-memory-server-core": "
|
|
47
|
-
"mongoose": "5.
|
|
48
|
-
"semver": "7.3.5"
|
|
43
|
+
"mongodb": "4.8.1",
|
|
44
|
+
"mongodb-memory-server-core": "8.8.0",
|
|
45
|
+
"mongoose": "6.5.0",
|
|
46
|
+
"semver": "7.3.5",
|
|
47
|
+
"ts-node": "^10.9.1"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
50
|
"@types/chai": "4.3.0",
|
|
52
51
|
"@types/fs-extra": "9.0.13",
|
|
53
52
|
"@types/mocha": "9.1.0",
|
|
54
53
|
"@types/sinon": "10.0.11",
|
|
55
|
-
"@
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^5.32.0",
|
|
55
|
+
"@typescript-eslint/parser": "^5.32.0",
|
|
56
56
|
"chai": "4.3.6",
|
|
57
|
+
"eslint": "^8.21.0",
|
|
58
|
+
"eslint-config-prettier": "8.5.0",
|
|
59
|
+
"eslint-plugin-prettier": "4.0.0",
|
|
57
60
|
"mocha": "9.2.2",
|
|
58
61
|
"mocha-jenkins-reporter": "0.4.7",
|
|
62
|
+
"prettier": "2.7.1",
|
|
59
63
|
"sinon": "13.0.1",
|
|
60
|
-
"
|
|
61
|
-
"typescript": "3.9.5"
|
|
64
|
+
"typescript": "4.7.4"
|
|
62
65
|
}
|
|
63
66
|
}
|
package/src/config/configs.ts
CHANGED
package/src/config/constants.ts
CHANGED
|
@@ -39,16 +39,16 @@ export class Constants {
|
|
|
39
39
|
connectionString: 'mock',
|
|
40
40
|
connectionOptions: {
|
|
41
41
|
useNewUrlParser: true,
|
|
42
|
-
useUnifiedTopology: true
|
|
42
|
+
useUnifiedTopology: true,
|
|
43
43
|
},
|
|
44
44
|
updater: {
|
|
45
45
|
lockMaxAgeSeconds: 30,
|
|
46
46
|
mongoSchemaUpdatesDirPath: '/dist/tests/testingMongoUpdates',
|
|
47
|
-
appSchemaCollectionName: 'testAppSchema'
|
|
47
|
+
appSchemaCollectionName: 'testAppSchema',
|
|
48
48
|
},
|
|
49
49
|
mockServer: {
|
|
50
|
-
serverVersion: '4.0.16'
|
|
51
|
-
}
|
|
50
|
+
serverVersion: '4.0.16',
|
|
51
|
+
},
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -64,7 +64,7 @@ export class Constants {
|
|
|
64
64
|
* This option is only available on the "development"
|
|
65
65
|
* environment, or when tests are ran.
|
|
66
66
|
*/
|
|
67
|
-
MOCK_CONNECTION_STRING: 'mock'
|
|
67
|
+
MOCK_CONNECTION_STRING: 'mock',
|
|
68
68
|
},
|
|
69
69
|
/**
|
|
70
70
|
* The names of the Mongo collections used in
|
|
@@ -75,7 +75,7 @@ export class Constants {
|
|
|
75
75
|
* Special collection that stores informations about the
|
|
76
76
|
* schema currently installed for the application.
|
|
77
77
|
*/
|
|
78
|
-
APP_SCHEMA: 'appSchema'
|
|
78
|
+
APP_SCHEMA: 'appSchema',
|
|
79
79
|
},
|
|
80
80
|
/**
|
|
81
81
|
* Mongo error codes
|
|
@@ -84,7 +84,7 @@ export class Constants {
|
|
|
84
84
|
/**
|
|
85
85
|
* The code for a Mongo "duplicate key" error.
|
|
86
86
|
*/
|
|
87
|
-
DUPLICATE_KEY: 11000
|
|
87
|
+
DUPLICATE_KEY: 11000,
|
|
88
88
|
},
|
|
89
89
|
|
|
90
90
|
/**
|
|
@@ -98,25 +98,25 @@ export class Constants {
|
|
|
98
98
|
/**
|
|
99
99
|
* The code for a Mongoose "required" error.
|
|
100
100
|
*/
|
|
101
|
-
REQUIRED_FIELD: 'required'
|
|
101
|
+
REQUIRED_FIELD: 'required',
|
|
102
102
|
},
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
105
|
* Mongoose error kinds
|
|
106
106
|
*/
|
|
107
107
|
errorKinds: {
|
|
108
|
-
OBJECT_ID: 'ObjectId'
|
|
108
|
+
OBJECT_ID: 'ObjectId',
|
|
109
109
|
},
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
112
|
* Mongoose error names
|
|
113
113
|
*/
|
|
114
114
|
errorNames: {
|
|
115
|
-
CAST_ERROR: 'CastError'
|
|
116
|
-
}
|
|
117
|
-
}
|
|
115
|
+
CAST_ERROR: 'CastError',
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
export
|
|
122
|
+
export const constants: Constants = new Constants();
|
package/src/config/init.ts
CHANGED
|
@@ -62,14 +62,14 @@ export class MongooseConfigs implements IMongooseConfigs {
|
|
|
62
62
|
* @param applyUpdates Should the database be checked for missing
|
|
63
63
|
* updates and have them applied if required?
|
|
64
64
|
*/
|
|
65
|
-
public applyUpdates
|
|
65
|
+
public applyUpdates = true;
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* If no connectionString is provided, "mock" will be
|
|
69
69
|
* used by default and a temporary Mongo server will
|
|
70
70
|
* be used.
|
|
71
71
|
*/
|
|
72
|
-
public connectionString
|
|
72
|
+
public connectionString = 'mock';
|
|
73
73
|
|
|
74
74
|
public connectionOptions: any = {
|
|
75
75
|
w: 1,
|
|
@@ -77,10 +77,14 @@ export class MongooseConfigs implements IMongooseConfigs {
|
|
|
77
77
|
auto_reconnect: true,
|
|
78
78
|
reconnectTries: 604800,
|
|
79
79
|
reconnectInterval: 1000,
|
|
80
|
-
useNewUrlParser: true
|
|
80
|
+
useNewUrlParser: true,
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
-
public updater: {
|
|
83
|
+
public updater: {
|
|
84
|
+
lockMaxAgeSeconds: number;
|
|
85
|
+
mongoSchemaUpdatesDirPath: string;
|
|
86
|
+
appSchemaCollectionName: string;
|
|
87
|
+
} = {
|
|
84
88
|
appSchemaCollectionName: constants.mongo.collectionNames.APP_SCHEMA,
|
|
85
89
|
lockMaxAgeSeconds: 60,
|
|
86
90
|
|
|
@@ -89,11 +93,11 @@ export class MongooseConfigs implements IMongooseConfigs {
|
|
|
89
93
|
* where the update files are.
|
|
90
94
|
* Required!
|
|
91
95
|
*/
|
|
92
|
-
mongoSchemaUpdatesDirPath: null
|
|
96
|
+
mongoSchemaUpdatesDirPath: null,
|
|
93
97
|
};
|
|
94
98
|
|
|
95
99
|
public mockServer: { serverVersion: string } = {
|
|
96
|
-
serverVersion: '3.2.1'
|
|
100
|
+
serverVersion: '3.2.1',
|
|
97
101
|
};
|
|
98
102
|
|
|
99
103
|
/**
|
|
@@ -142,28 +146,42 @@ export class MongooseConfigs implements IMongooseConfigs {
|
|
|
142
146
|
|
|
143
147
|
if (!_.isNil(overridingConfigs.applyUpdates)) {
|
|
144
148
|
if (!_.isBoolean(overridingConfigs.applyUpdates)) {
|
|
145
|
-
throw new Error(
|
|
149
|
+
throw new Error(
|
|
150
|
+
`The applyUpdates config must be a boolean: ${overridingConfigs.applyUpdates}`
|
|
151
|
+
);
|
|
146
152
|
}
|
|
147
153
|
this.applyUpdates = overridingConfigs.applyUpdates;
|
|
148
154
|
}
|
|
149
155
|
|
|
150
156
|
if (!_.isNil(overridingConfigs.connectionString)) {
|
|
151
|
-
if (
|
|
152
|
-
|
|
157
|
+
if (
|
|
158
|
+
!_.isString(overridingConfigs.connectionString) ||
|
|
159
|
+
utils.isBlank(overridingConfigs.connectionString)
|
|
160
|
+
) {
|
|
161
|
+
throw new Error(
|
|
162
|
+
`The connectionString config is not valid : ${overridingConfigs.connectionString}`
|
|
163
|
+
);
|
|
153
164
|
}
|
|
154
165
|
this.connectionString = overridingConfigs.connectionString;
|
|
155
166
|
} else {
|
|
156
|
-
logger.warning(
|
|
167
|
+
logger.warning(
|
|
168
|
+
`No "connectionString" config was provided: a *mocked* Mongo server will be used!`
|
|
169
|
+
);
|
|
157
170
|
}
|
|
158
171
|
|
|
159
172
|
if (!_.isNil(overridingConfigs.connectionOptions)) {
|
|
160
173
|
if (!_.isObject(overridingConfigs.connectionOptions)) {
|
|
161
|
-
throw new Error(
|
|
174
|
+
throw new Error(
|
|
175
|
+
`The connectionOptions config is not valid : ${overridingConfigs.connectionString}`
|
|
176
|
+
);
|
|
162
177
|
}
|
|
163
178
|
this.connectionOptions = overridingConfigs.connectionOptions;
|
|
164
179
|
}
|
|
165
180
|
|
|
166
|
-
if (
|
|
181
|
+
if (
|
|
182
|
+
!_.isNil(overridingConfigs.mockServer) &&
|
|
183
|
+
!_.isNil(overridingConfigs.mockServer.serverVersion)
|
|
184
|
+
) {
|
|
167
185
|
if (
|
|
168
186
|
!_.isString(overridingConfigs.mockServer.serverVersion) ||
|
|
169
187
|
utils.isBlank(overridingConfigs.mockServer.serverVersion)
|
package/src/mongoClient.ts
CHANGED
|
@@ -36,7 +36,10 @@ export async function initMongoose(mongooseConfig: IMongooseConfigs): Promise<mo
|
|
|
36
36
|
// ==========================================
|
|
37
37
|
// Mock!
|
|
38
38
|
// ==========================================
|
|
39
|
-
const mongoServer = await mongoUtils.mockMongoose(
|
|
39
|
+
const mongoServer = await mongoUtils.mockMongoose(
|
|
40
|
+
null,
|
|
41
|
+
mongooseConfigClean.mockServer.serverVersion
|
|
42
|
+
);
|
|
40
43
|
|
|
41
44
|
connectionString = mongoServer.getUri();
|
|
42
45
|
}
|
|
@@ -49,9 +52,12 @@ export async function initMongoose(mongooseConfig: IMongooseConfigs): Promise<mo
|
|
|
49
52
|
|
|
50
53
|
// Updates Promise for mongoose, avoid warning log emit by mongoose
|
|
51
54
|
(mongoose as any).Promise = global.Promise;
|
|
52
|
-
const mongoOptions: mongoose.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
const mongoOptions: mongoose.ConnectOptions = defaultsDeep(
|
|
56
|
+
mongooseConfigClean.connectionOptions,
|
|
57
|
+
{
|
|
58
|
+
promiseLibrary: global.Promise,
|
|
59
|
+
}
|
|
60
|
+
);
|
|
55
61
|
|
|
56
62
|
// Creates the connection
|
|
57
63
|
mongooseConnection = mongoose.createConnection(connectionString, mongoOptions);
|
package/src/mongoUpdater.test.ts
CHANGED
|
@@ -26,7 +26,7 @@ describe('Mongo Updater', () => {
|
|
|
26
26
|
// "this" value for "MongoUtils.mockMongoose(...)"
|
|
27
27
|
const testconfig: IMongooseConfigs = mongodbConstants.testsConfig;
|
|
28
28
|
|
|
29
|
-
before(async function() {
|
|
29
|
+
before(async function () {
|
|
30
30
|
// Makes sure Mongoose is mocked, but not in Jenkins as we will start a dedicated mongodb container.
|
|
31
31
|
await mongoUtils.mockMongoose(this, testconfig.mockServer.serverVersion);
|
|
32
32
|
const connection = await initMongoose(testconfig);
|
|
@@ -100,7 +100,9 @@ describe('Mongo Updater', () => {
|
|
|
100
100
|
assert.strictEqual(collections.length, 1);
|
|
101
101
|
assert.strictEqual(collections[0].name, testconfig.updater.appSchemaCollectionName);
|
|
102
102
|
|
|
103
|
-
const schema: MongoDb.Collection = mongoDb.collection(
|
|
103
|
+
const schema: MongoDb.Collection = mongoDb.collection(
|
|
104
|
+
testconfig.updater.appSchemaCollectionName
|
|
105
|
+
);
|
|
104
106
|
const schemaDb: any[] = await schema.find().toArray();
|
|
105
107
|
assert.strictEqual(schemaDb[0].version, '0.0.0');
|
|
106
108
|
});
|
|
@@ -115,7 +117,9 @@ describe('Mongo Updater', () => {
|
|
|
115
117
|
|
|
116
118
|
describe('lock', async () => {
|
|
117
119
|
it('lock should be equal to false', async () => {
|
|
118
|
-
const schema: MongoDb.Collection = mongoDb.collection(
|
|
120
|
+
const schema: MongoDb.Collection = mongoDb.collection(
|
|
121
|
+
testconfig.updater.appSchemaCollectionName
|
|
122
|
+
);
|
|
119
123
|
const schemaDb: any[] = await schema.find().toArray();
|
|
120
124
|
assert.strictEqual(schemaDb[0].lock, false);
|
|
121
125
|
});
|
|
@@ -126,7 +130,9 @@ describe('Mongo Updater', () => {
|
|
|
126
130
|
});
|
|
127
131
|
|
|
128
132
|
it('lock should be equal to true', async () => {
|
|
129
|
-
const schema: MongoDb.Collection = mongoDb.collection(
|
|
133
|
+
const schema: MongoDb.Collection = mongoDb.collection(
|
|
134
|
+
testconfig.updater.appSchemaCollectionName
|
|
135
|
+
);
|
|
130
136
|
const schemaDb: any[] = await schema.find().toArray();
|
|
131
137
|
assert.strictEqual(schemaDb[0].lock, true);
|
|
132
138
|
});
|
|
@@ -139,7 +145,9 @@ describe('Mongo Updater', () => {
|
|
|
139
145
|
|
|
140
146
|
describe('unlock', async () => {
|
|
141
147
|
it('lock should be equal to true', async () => {
|
|
142
|
-
const schema: MongoDb.Collection = mongoDb.collection(
|
|
148
|
+
const schema: MongoDb.Collection = mongoDb.collection(
|
|
149
|
+
testconfig.updater.appSchemaCollectionName
|
|
150
|
+
);
|
|
143
151
|
const schemaDb: any[] = await schema.find().toArray();
|
|
144
152
|
assert.strictEqual(schemaDb[0].lock, true);
|
|
145
153
|
});
|
|
@@ -150,7 +158,9 @@ describe('Mongo Updater', () => {
|
|
|
150
158
|
});
|
|
151
159
|
|
|
152
160
|
it('lock should be equal to false', async () => {
|
|
153
|
-
const schema: MongoDb.Collection = mongoDb.collection(
|
|
161
|
+
const schema: MongoDb.Collection = mongoDb.collection(
|
|
162
|
+
testconfig.updater.appSchemaCollectionName
|
|
163
|
+
);
|
|
154
164
|
const schemaDb: any[] = await schema.find().toArray();
|
|
155
165
|
assert.strictEqual(schemaDb[0].lock, false);
|
|
156
166
|
});
|
|
@@ -159,7 +169,9 @@ describe('Mongo Updater', () => {
|
|
|
159
169
|
const isUnlocked: boolean = await mongoUpdater.unlockAppSchemaDocument();
|
|
160
170
|
assert.strictEqual(isUnlocked, false);
|
|
161
171
|
|
|
162
|
-
const schema: MongoDb.Collection = mongoDb.collection(
|
|
172
|
+
const schema: MongoDb.Collection = mongoDb.collection(
|
|
173
|
+
testconfig.updater.appSchemaCollectionName
|
|
174
|
+
);
|
|
163
175
|
const schemaDb: any[] = await schema.find().toArray();
|
|
164
176
|
assert.strictEqual(schemaDb[0].lock, false);
|
|
165
177
|
});
|
|
@@ -222,7 +234,7 @@ describe('Mongo Updater', () => {
|
|
|
222
234
|
// A regular function is *required* to get the proper
|
|
223
235
|
// "this" value to call ".timeout(...)"
|
|
224
236
|
// ==========================================
|
|
225
|
-
it('should wait when is already locked and should delete a lock that is too old', async function() {
|
|
237
|
+
it('should wait when is already locked and should delete a lock that is too old', async function () {
|
|
226
238
|
this.timeout(5000);
|
|
227
239
|
|
|
228
240
|
// Resets version to 0.0.0
|