@villedemontreal/mongo 6.7.1 → 6.7.2
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/scripts/index.js +16 -0
- package/dist/scripts/index.js.map +1 -0
- package/dist/scripts/lint.js +18 -0
- package/dist/scripts/lint.js.map +1 -0
- package/dist/scripts/lintFix.js +21 -0
- package/dist/scripts/lintFix.js.map +1 -0
- package/dist/scripts/showCoverage.js +40 -0
- package/dist/scripts/showCoverage.js.map +1 -0
- package/dist/scripts/test.js +29 -0
- package/dist/scripts/test.js.map +1 -0
- package/dist/scripts/testUnits.js +95 -0
- package/dist/scripts/testUnits.js.map +1 -0
- package/dist/scripts/watch.js +96 -0
- package/dist/scripts/watch.js.map +1 -0
- package/dist/src/config/configs.js +6 -0
- package/dist/src/config/configs.js.map +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 +64 -59
- package/dist/src/mongoClient.js.map +1 -1
- package/dist/src/mongoUpdater.js +30 -27
- package/dist/src/mongoUpdater.js.map +1 -1
- package/dist/src/mongoUpdater.test.js +11 -11
- package/dist/src/mongoUpdater.test.js.map +1 -1
- package/dist/src/mongoUtils.js +15 -12
- package/dist/src/mongoUtils.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 +4 -4
- package/dist/tests/testingMongoUpdates/1.0.1.js.map +1 -1
- package/package.json +20 -15
- package/src/config/configs.ts +10 -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 +80 -63
- package/src/mongoUpdater.test.ts +29 -17
- package/src/mongoUpdater.ts +47 -32
- 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
- package/dist/src/config/configs.d.ts +0 -16
- package/dist/src/config/constants.d.ts +0 -85
- package/dist/src/config/init.d.ts +0 -9
- package/dist/src/config/mongooseConfigs.d.ts +0 -73
- package/dist/src/index.d.ts +0 -6
- package/dist/src/mongoClient.d.ts +0 -19
- package/dist/src/mongoUpdater.d.ts +0 -103
- package/dist/src/mongoUpdater.test.d.ts +0 -1
- package/dist/src/mongoUtils.d.ts +0 -68
- package/dist/src/mongoUtils.test.d.ts +0 -0
- package/dist/src/plugins/pagination/index.d.ts +0 -11
- package/dist/src/plugins/pagination/index.test.d.ts +0 -1
- package/dist/src/plugins/pagination/specs/IPaginateOptions.d.ts +0 -51
- package/dist/src/utils/logger.d.ts +0 -11
- package/dist/src/utils/testingConfigurations.d.ts +0 -8
- package/dist/tests/testingMongoUpdates/1.0.0.d.ts +0 -5
- package/dist/tests/testingMongoUpdates/1.0.1.d.ts +0 -5
|
@@ -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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BAClC,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);
|
|
@@ -33,12 +33,12 @@ describe('plugin pagination', () => {
|
|
|
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
|
-
title:
|
|
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,CAAC,MAAM,CAAC;AAE3B,MAAM,YAAY,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AAC3D,MAAM,WAAW,GAAG,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;AAE3D,MAAM,UAAU,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC;IACrC,KAAK,EAAE,MAAM;IACb,IAAI,EAAE,IAAI;IACV,MAAM,EAAE;QACN,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,QAAQ;KACd;CACF,CAAC,CAAC;AAEH,UAAU,CAAC,MAAM,CAAC,wBAAgB,CAAC,CAAC;AACpC,MAAM,SAAS,GAAQ,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAE1D,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,MAAM,CAAC,KAAK;QACV,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAErB,oGAAoG;QACpG,MAAM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;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"}
|
|
@@ -7,15 +7,15 @@ async function update(db) {
|
|
|
7
7
|
// ==========================================
|
|
8
8
|
// Adding extra indexes on the "test" collection.
|
|
9
9
|
// ==========================================
|
|
10
|
-
const testUserCollection =
|
|
10
|
+
const testUserCollection = db.collection('test');
|
|
11
11
|
await testUserCollection.createIndexes([
|
|
12
12
|
{
|
|
13
13
|
key: {
|
|
14
14
|
firstName: 1,
|
|
15
|
-
lastName: 1
|
|
15
|
+
lastName: 1,
|
|
16
16
|
},
|
|
17
|
-
name: 'firstName_lastName'
|
|
18
|
-
}
|
|
17
|
+
name: 'firstName_lastName',
|
|
18
|
+
},
|
|
19
19
|
]);
|
|
20
20
|
}
|
|
21
21
|
exports.default = update;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"1.0.1.js","sourceRoot":"","sources":["../../../tests/testingMongoUpdates/1.0.1.ts"],"names":[],"mappings":";;AAEA;;GAEG;AACY,KAAK,UAAU,MAAM,CAAC,EAAc;IACjD,6CAA6C;IAC7C,iDAAiD;IACjD,6CAA6C;IAC7C,MAAM,kBAAkB,GAAuB,
|
|
1
|
+
{"version":3,"file":"1.0.1.js","sourceRoot":"","sources":["../../../tests/testingMongoUpdates/1.0.1.ts"],"names":[],"mappings":";;AAEA;;GAEG;AACY,KAAK,UAAU,MAAM,CAAC,EAAc;IACjD,6CAA6C;IAC7C,iDAAiD;IACjD,6CAA6C;IAC7C,MAAM,kBAAkB,GAAuB,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAErE,MAAM,kBAAkB,CAAC,aAAa,CAAC;QACrC;YACE,GAAG,EAAE;gBACH,SAAS,EAAE,CAAC;gBACZ,QAAQ,EAAE,CAAC;aACZ;YACD,IAAI,EAAE,oBAAoB;SAC3B;KACF,CAAC,CAAC;AACL,CAAC;AAfD,yBAeC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@villedemontreal/mongo",
|
|
3
|
-
"version": "6.7.
|
|
3
|
+
"version": "6.7.2",
|
|
4
4
|
"description": "Utilities for Mongo / Mongoose",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"typings": "dist/src",
|
|
@@ -34,30 +34,35 @@
|
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@types/http-status-codes": "1.2.0",
|
|
37
|
-
"@types/lodash": "4.14.
|
|
38
|
-
"@types/semver": "7.3.
|
|
39
|
-
"@villedemontreal/general-utils": "5.16.
|
|
40
|
-
"@villedemontreal/logger": "6.5.
|
|
41
|
-
"
|
|
42
|
-
"fs-extra": "10.0
|
|
37
|
+
"@types/lodash": "4.14.184",
|
|
38
|
+
"@types/semver": "7.3.12",
|
|
39
|
+
"@villedemontreal/general-utils": "5.16.7",
|
|
40
|
+
"@villedemontreal/logger": "6.5.7",
|
|
41
|
+
"app-root-path": "3.1.0",
|
|
42
|
+
"fs-extra": "10.1.0",
|
|
43
43
|
"http-status-codes": "2.2.0",
|
|
44
44
|
"lodash": "4.17.21",
|
|
45
45
|
"mongodb": "3.6.12",
|
|
46
46
|
"mongodb-memory-server-core": "7.2.1",
|
|
47
47
|
"mongoose": "5.13.13",
|
|
48
|
-
"semver": "7.3.
|
|
48
|
+
"semver": "7.3.7"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@types/chai": "4.3.
|
|
51
|
+
"@types/chai": "4.3.3",
|
|
52
52
|
"@types/fs-extra": "9.0.13",
|
|
53
|
-
"@types/mocha": "9.1.
|
|
54
|
-
"@types/sinon": "10.0.
|
|
55
|
-
"@
|
|
53
|
+
"@types/mocha": "9.1.1",
|
|
54
|
+
"@types/sinon": "10.0.13",
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "5.36.1",
|
|
56
|
+
"@typescript-eslint/parser": "5.36.1",
|
|
57
|
+
"@villedemontreal/scripting": "2.1.6",
|
|
56
58
|
"chai": "4.3.6",
|
|
59
|
+
"eslint": "8.23.0",
|
|
60
|
+
"eslint-config-prettier": "8.5.0",
|
|
61
|
+
"eslint-plugin-prettier": "4.2.1",
|
|
57
62
|
"mocha": "9.2.2",
|
|
58
63
|
"mocha-jenkins-reporter": "0.4.7",
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"typescript": "
|
|
64
|
+
"nyc": "15.1.0",
|
|
65
|
+
"sinon": "14.0.0",
|
|
66
|
+
"typescript": "4.8.2"
|
|
62
67
|
}
|
|
63
68
|
}
|
package/src/config/configs.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { ILogger } from '@villedemontreal/logger';
|
|
2
|
+
import * as os from 'os';
|
|
3
|
+
import * as path from 'path';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Lib configs
|
|
5
7
|
*/
|
|
6
8
|
export class Configs {
|
|
9
|
+
public isWindows: boolean;
|
|
10
|
+
public libRoot: string;
|
|
7
11
|
private _loggerCreator: (name: string) => ILogger;
|
|
8
12
|
|
|
13
|
+
constructor() {
|
|
14
|
+
this.libRoot = path.normalize(__dirname + '/../../..');
|
|
15
|
+
this.isWindows = os.platform() === 'win32';
|
|
16
|
+
}
|
|
17
|
+
|
|
9
18
|
/**
|
|
10
19
|
* The Logger creator
|
|
11
20
|
*/
|
|
@@ -24,4 +33,4 @@ export class Configs {
|
|
|
24
33
|
}
|
|
25
34
|
}
|
|
26
35
|
|
|
27
|
-
export
|
|
36
|
+
export const configs: Configs = new Configs();
|
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)
|