@villedemontreal/mongo 8.3.0 → 9.0.0
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.js +1 -1
- package/dist/src/config/configs.js.map +1 -1
- package/dist/src/config/constants.js +1 -1
- package/dist/src/config/constants.js.map +1 -1
- package/dist/src/config/mongooseConfigs.d.ts.map +1 -1
- package/dist/src/config/mongooseConfigs.js +0 -1
- package/dist/src/config/mongooseConfigs.js.map +1 -1
- package/dist/src/mongoClient.d.ts.map +1 -1
- package/dist/src/mongoClient.js +1 -0
- package/dist/src/mongoClient.js.map +1 -1
- package/dist/src/mongoUpdater.d.ts.map +1 -1
- package/dist/src/mongoUpdater.js +10 -11
- package/dist/src/mongoUpdater.js.map +1 -1
- package/dist/src/mongoUpdater.test.js +0 -3
- package/dist/src/mongoUpdater.test.js.map +1 -1
- package/dist/src/mongoUtils.d.ts +1 -2
- package/dist/src/mongoUtils.d.ts.map +1 -1
- package/dist/src/mongoUtils.js +0 -3
- package/dist/src/mongoUtils.js.map +1 -1
- package/dist/src/plugins/pagination/index.d.ts.map +1 -1
- package/dist/src/plugins/pagination/index.js +1 -0
- package/dist/src/plugins/pagination/index.js.map +1 -1
- package/dist/src/plugins/pagination/index.test.js +0 -2
- package/dist/src/plugins/pagination/index.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +28 -17
- package/src/config/configs.ts +1 -1
- package/src/config/constants.ts +1 -1
- package/src/config/mongooseConfigs.ts +0 -1
- package/src/mongoClient.ts +1 -0
- package/src/mongoUpdater.test.ts +0 -4
- package/src/mongoUpdater.ts +10 -11
- package/src/mongoUtils.ts +1 -8
- package/src/plugins/pagination/index.test.ts +0 -3
- package/src/plugins/pagination/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@villedemontreal/mongo",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "Utilities for Mongo / Mongoose",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"typings": "dist/src",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"compile": "tsc --build",
|
|
15
15
|
"show-tsconfig": "tsc --showConfig",
|
|
16
16
|
"show-coverage": "open output/coverage/lcov-report/index.html",
|
|
17
|
-
"lint": "eslint
|
|
18
|
-
"lint-fix": "eslint
|
|
17
|
+
"lint": "eslint",
|
|
18
|
+
"lint-fix": "eslint --fix",
|
|
19
19
|
"ncu": "ncu --target minor -x @types/node",
|
|
20
20
|
"ncu-fix": "ncu -u --target minor -x @types/node"
|
|
21
21
|
},
|
|
@@ -33,39 +33,50 @@
|
|
|
33
33
|
"author": "Ville de Montréal",
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@villedemontreal/general-utils": "
|
|
37
|
-
"@villedemontreal/logger": "
|
|
36
|
+
"@villedemontreal/general-utils": "6.0.0",
|
|
37
|
+
"@villedemontreal/logger": "8.0.0",
|
|
38
38
|
"app-root-path": "3.1.0",
|
|
39
|
-
"fs-extra": "11.3.
|
|
39
|
+
"fs-extra": "11.3.3",
|
|
40
40
|
"http-status-codes": "2.3.0",
|
|
41
41
|
"lodash": "4.17.21",
|
|
42
|
-
"mongodb": "
|
|
43
|
-
"mongodb-memory-server-core": "
|
|
44
|
-
"mongoose": "
|
|
42
|
+
"mongodb": "7.0.0",
|
|
43
|
+
"mongodb-memory-server-core": "11.0.1",
|
|
44
|
+
"mongoose": "9.0.2",
|
|
45
45
|
"semver": "7.7.3"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@
|
|
48
|
+
"@eslint/eslintrc": "3.3.3",
|
|
49
|
+
"@eslint/js": "^9.39.2",
|
|
50
|
+
"@types/chai": "5.2.3",
|
|
49
51
|
"@types/fs-extra": "11.0.4",
|
|
50
52
|
"@types/http-status-codes": "1.2.0",
|
|
51
53
|
"@types/lodash": "4.17.21",
|
|
52
54
|
"@types/mocha": "10.0.10",
|
|
53
55
|
"@types/semver": "7.7.1",
|
|
54
|
-
"@types/sinon": "
|
|
55
|
-
"@typescript-eslint/eslint-plugin": "
|
|
56
|
-
"@typescript-eslint/parser": "
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"eslint
|
|
56
|
+
"@types/sinon": "21.0.0",
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "8.50.1",
|
|
58
|
+
"@typescript-eslint/parser": "8.50.1",
|
|
59
|
+
"@typescript-eslint/utils": "^8.50.1",
|
|
60
|
+
"chai": "6.2.2",
|
|
61
|
+
"eslint": "^9.39.2",
|
|
62
|
+
"eslint-config-prettier": "10.1.8",
|
|
60
63
|
"eslint-plugin-prettier": "5.5.4",
|
|
64
|
+
"globals": "^16.5.0",
|
|
61
65
|
"mocha": "11.7.5",
|
|
62
66
|
"nyc": "17.1.0",
|
|
63
67
|
"prettier": "3.7.4",
|
|
64
|
-
"sinon": "21.0.
|
|
68
|
+
"sinon": "21.0.1",
|
|
65
69
|
"ts-node": "^10.9.2",
|
|
66
70
|
"typescript": "5.9.3"
|
|
67
71
|
},
|
|
68
72
|
"override": {
|
|
69
73
|
"mongodb": "$mongodb"
|
|
74
|
+
},
|
|
75
|
+
"config": {
|
|
76
|
+
"mongodbMemoryServer": {
|
|
77
|
+
"resumeDownload": true,
|
|
78
|
+
"maxRetries": 5,
|
|
79
|
+
"debug": false
|
|
80
|
+
}
|
|
70
81
|
}
|
|
71
82
|
}
|
package/src/config/configs.ts
CHANGED
|
@@ -11,7 +11,7 @@ export class Configs {
|
|
|
11
11
|
private _loggerCreator: (name: string) => ILogger;
|
|
12
12
|
|
|
13
13
|
constructor() {
|
|
14
|
-
this.libRoot = path.normalize(__dirname
|
|
14
|
+
this.libRoot = path.normalize(path.join(__dirname, '../..'));
|
|
15
15
|
this.isWindows = os.platform() === 'win32';
|
|
16
16
|
}
|
|
17
17
|
|
package/src/config/constants.ts
CHANGED
|
@@ -103,7 +103,6 @@ export class MongooseConfigs implements IMongooseConfigs {
|
|
|
103
103
|
* Overrides default configurations using the ones passed
|
|
104
104
|
* as parameters.
|
|
105
105
|
*/
|
|
106
|
-
// tslint:disable-next-line:cyclomatic-complexity
|
|
107
106
|
constructor(overridingConfigs: IMongooseConfigs) {
|
|
108
107
|
// ==========================================
|
|
109
108
|
// Required configs
|
package/src/mongoClient.ts
CHANGED
|
@@ -98,6 +98,7 @@ export async function initMongoose(mongooseConfig: IMongooseConfigs): Promise<mo
|
|
|
98
98
|
|
|
99
99
|
return new Promise<mongoose.Connection>((resolve, reject) => {
|
|
100
100
|
doInitMongoose(mongooseConfigClean, resolve, reject).catch((err) => {
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
101
102
|
reject(`Error initializing Mongo: ${err}`);
|
|
102
103
|
});
|
|
103
104
|
});
|
package/src/mongoUpdater.test.ts
CHANGED
package/src/mongoUpdater.ts
CHANGED
|
@@ -96,8 +96,7 @@ export class MongoUpdater implements IMongoUpdater {
|
|
|
96
96
|
public async installAppSchemaCollection(): Promise<any> {
|
|
97
97
|
try {
|
|
98
98
|
// Installing the "appSchema" collection.
|
|
99
|
-
|
|
100
|
-
logger.info(' > Installing the "' + this.appSchemaCollectionName + '" collection.');
|
|
99
|
+
logger.info(` > Installing the "${this.appSchemaCollectionName}" collection.`);
|
|
101
100
|
const collection: MongoDb.Collection = await this.mongoDb.createCollection(
|
|
102
101
|
this.appSchemaCollectionName,
|
|
103
102
|
);
|
|
@@ -161,9 +160,8 @@ export class MongoUpdater implements IMongoUpdater {
|
|
|
161
160
|
const appSchemaCollection: MongoDb.Collection = await this.getAppSchemaCollection();
|
|
162
161
|
|
|
163
162
|
await appSchemaCollection.updateOne({}, { $set: { version: newVersion } });
|
|
164
|
-
// tslint:disable-next-line: prefer-template
|
|
165
163
|
logger.info(
|
|
166
|
-
|
|
164
|
+
` > MongoDB App Schema updagred from version ${currentVersion} to version ${newVersion}`,
|
|
167
165
|
);
|
|
168
166
|
}
|
|
169
167
|
|
|
@@ -197,6 +195,7 @@ export class MongoUpdater implements IMongoUpdater {
|
|
|
197
195
|
return false;
|
|
198
196
|
});
|
|
199
197
|
} catch (err2) {
|
|
198
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
200
199
|
return reject(err2);
|
|
201
200
|
}
|
|
202
201
|
return resolve(filesClean.sort(semver.compare));
|
|
@@ -211,21 +210,22 @@ export class MongoUpdater implements IMongoUpdater {
|
|
|
211
210
|
);
|
|
212
211
|
if (updateFileNames.length > 0) {
|
|
213
212
|
for (const updateFileName of updateFileNames) {
|
|
214
|
-
logger.info(
|
|
213
|
+
logger.info(` > Pending app schema update: ${updateFileName}`);
|
|
215
214
|
|
|
216
|
-
// tslint:disable-next-line: prefer-template
|
|
217
215
|
const updateFilePath = path.join(this.getAppSchemaFilesDirPath(), updateFileName);
|
|
218
216
|
let updateFunction: (db: MongoDb.Db) => Promise<void>;
|
|
219
217
|
try {
|
|
220
|
-
|
|
218
|
+
const pkg = await import(updateFilePath);
|
|
219
|
+
updateFunction = pkg.default;
|
|
221
220
|
} catch (e) {
|
|
221
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
222
222
|
return Promise.reject(e);
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
if (!isFunction(updateFunction)) {
|
|
226
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
226
227
|
return Promise.reject(
|
|
227
|
-
|
|
228
|
-
updateFilePath,
|
|
228
|
+
`The default export for an app schema update file must be a function! Was not for file : '${updateFilePath}'`,
|
|
229
229
|
);
|
|
230
230
|
}
|
|
231
231
|
|
|
@@ -378,9 +378,8 @@ export class MongoUpdater implements IMongoUpdater {
|
|
|
378
378
|
// ==========================================
|
|
379
379
|
currentAppSchemaVersion = await this.getAppSchemaVersion();
|
|
380
380
|
if (semver.gte(currentAppSchemaVersion, targetVersion)) {
|
|
381
|
-
// tslint:disable-next-line: prefer-template
|
|
382
381
|
logger.info(
|
|
383
|
-
|
|
382
|
+
` > Current database app schema is up to date : ${currentAppSchemaVersion}).`,
|
|
384
383
|
);
|
|
385
384
|
return;
|
|
386
385
|
}
|
package/src/mongoUtils.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// Mongo utilities
|
|
3
3
|
// ==========================================
|
|
4
4
|
import {
|
|
5
|
-
ApiErrorAndInfo,
|
|
6
5
|
createError,
|
|
7
6
|
createInvalidParameterError,
|
|
8
7
|
createNotFoundError,
|
|
@@ -215,10 +214,7 @@ export class MongoUtils {
|
|
|
215
214
|
* @param publicMessage a public message to be used in the
|
|
216
215
|
* generated error. Fopr example : "The user is invalid".
|
|
217
216
|
*/
|
|
218
|
-
public convertMongoOrMongooseErrorToApiError(
|
|
219
|
-
err: any,
|
|
220
|
-
publicMessage: string,
|
|
221
|
-
): ApiErrorAndInfo | any {
|
|
217
|
+
public convertMongoOrMongooseErrorToApiError(err: any, publicMessage: string): any {
|
|
222
218
|
if (!err) {
|
|
223
219
|
return createServerError('Empty error object');
|
|
224
220
|
}
|
|
@@ -309,15 +305,12 @@ export class MongoUtils {
|
|
|
309
305
|
// ==========================================
|
|
310
306
|
// Converts the "_id" property to "id"
|
|
311
307
|
// ==========================================
|
|
312
|
-
// tslint:disable-next-line:no-string-literal
|
|
313
308
|
pojoObj['id'] = pojoObj['_id'].toString();
|
|
314
|
-
// tslint:disable-next-line:no-string-literal
|
|
315
309
|
delete pojoObj['_id'];
|
|
316
310
|
|
|
317
311
|
// ==========================================
|
|
318
312
|
// Removes the "__v"
|
|
319
313
|
// ==========================================
|
|
320
|
-
// tslint:disable-next-line:no-string-literal
|
|
321
314
|
delete pojoObj['__v'];
|
|
322
315
|
|
|
323
316
|
return pojo;
|