@villedemontreal/mongo 8.2.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 +13 -13
- 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 +4 -6
- 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 +29 -18
- 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 +13 -13
- package/src/mongoUtils.ts +5 -11
- 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
|
-
"prettier": "3.7.
|
|
64
|
-
"sinon": "21.0.
|
|
67
|
+
"prettier": "3.7.4",
|
|
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
|
@@ -5,6 +5,7 @@ import * as MongoDb from 'mongodb';
|
|
|
5
5
|
import * as semver from 'semver';
|
|
6
6
|
import { constants as mongodbConstants } from './config/constants';
|
|
7
7
|
import { createLogger } from './utils/logger';
|
|
8
|
+
import * as path from 'path';
|
|
8
9
|
|
|
9
10
|
const logger = createLogger('MongoUpdater');
|
|
10
11
|
|
|
@@ -95,8 +96,7 @@ export class MongoUpdater implements IMongoUpdater {
|
|
|
95
96
|
public async installAppSchemaCollection(): Promise<any> {
|
|
96
97
|
try {
|
|
97
98
|
// Installing the "appSchema" collection.
|
|
98
|
-
|
|
99
|
-
logger.info(' > Installing the "' + this.appSchemaCollectionName + '" collection.');
|
|
99
|
+
logger.info(` > Installing the "${this.appSchemaCollectionName}" collection.`);
|
|
100
100
|
const collection: MongoDb.Collection = await this.mongoDb.createCollection(
|
|
101
101
|
this.appSchemaCollectionName,
|
|
102
102
|
);
|
|
@@ -160,9 +160,8 @@ export class MongoUpdater implements IMongoUpdater {
|
|
|
160
160
|
const appSchemaCollection: MongoDb.Collection = await this.getAppSchemaCollection();
|
|
161
161
|
|
|
162
162
|
await appSchemaCollection.updateOne({}, { $set: { version: newVersion } });
|
|
163
|
-
// tslint:disable-next-line: prefer-template
|
|
164
163
|
logger.info(
|
|
165
|
-
|
|
164
|
+
` > MongoDB App Schema updagred from version ${currentVersion} to version ${newVersion}`,
|
|
166
165
|
);
|
|
167
166
|
}
|
|
168
167
|
|
|
@@ -196,6 +195,7 @@ export class MongoUpdater implements IMongoUpdater {
|
|
|
196
195
|
return false;
|
|
197
196
|
});
|
|
198
197
|
} catch (err2) {
|
|
198
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
199
199
|
return reject(err2);
|
|
200
200
|
}
|
|
201
201
|
return resolve(filesClean.sort(semver.compare));
|
|
@@ -210,21 +210,22 @@ export class MongoUpdater implements IMongoUpdater {
|
|
|
210
210
|
);
|
|
211
211
|
if (updateFileNames.length > 0) {
|
|
212
212
|
for (const updateFileName of updateFileNames) {
|
|
213
|
-
logger.info(
|
|
213
|
+
logger.info(` > Pending app schema update: ${updateFileName}`);
|
|
214
214
|
|
|
215
|
-
|
|
216
|
-
const updateFilePath = this.getAppSchemaFilesDirPath() + '/' + updateFileName;
|
|
215
|
+
const updateFilePath = path.join(this.getAppSchemaFilesDirPath(), updateFileName);
|
|
217
216
|
let updateFunction: (db: MongoDb.Db) => Promise<void>;
|
|
218
217
|
try {
|
|
219
|
-
|
|
218
|
+
const pkg = await import(updateFilePath);
|
|
219
|
+
updateFunction = pkg.default;
|
|
220
220
|
} catch (e) {
|
|
221
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
221
222
|
return Promise.reject(e);
|
|
222
223
|
}
|
|
223
224
|
|
|
224
225
|
if (!isFunction(updateFunction)) {
|
|
226
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
225
227
|
return Promise.reject(
|
|
226
|
-
|
|
227
|
-
updateFilePath,
|
|
228
|
+
`The default export for an app schema update file must be a function! Was not for file : '${updateFilePath}'`,
|
|
228
229
|
);
|
|
229
230
|
}
|
|
230
231
|
|
|
@@ -377,9 +378,8 @@ export class MongoUpdater implements IMongoUpdater {
|
|
|
377
378
|
// ==========================================
|
|
378
379
|
currentAppSchemaVersion = await this.getAppSchemaVersion();
|
|
379
380
|
if (semver.gte(currentAppSchemaVersion, targetVersion)) {
|
|
380
|
-
// tslint:disable-next-line: prefer-template
|
|
381
381
|
logger.info(
|
|
382
|
-
|
|
382
|
+
` > Current database app schema is up to date : ${currentAppSchemaVersion}).`,
|
|
383
383
|
);
|
|
384
384
|
return;
|
|
385
385
|
}
|
|
@@ -415,7 +415,7 @@ export class MongoUpdater implements IMongoUpdater {
|
|
|
415
415
|
};
|
|
416
416
|
|
|
417
417
|
protected getAppSchemaFilesDirPath(): string {
|
|
418
|
-
return mongodbConstants.appRoot
|
|
418
|
+
return path.join(mongodbConstants.appRoot, this.mongoSchemaUpdatesDirPath);
|
|
419
419
|
}
|
|
420
420
|
|
|
421
421
|
/**
|
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,
|
|
@@ -19,6 +18,7 @@ import * as mocha from 'mocha';
|
|
|
19
18
|
import { MongoMemoryReplSet, MongoMemoryServer } from 'mongodb-memory-server-core';
|
|
20
19
|
import * as mongoose from 'mongoose';
|
|
21
20
|
import { constants } from './config/constants';
|
|
21
|
+
import * as path from 'path';
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Mongo utilities
|
|
@@ -67,7 +67,7 @@ export class MongoUtils {
|
|
|
67
67
|
// container, the server will not be downloaded
|
|
68
68
|
// over and over.
|
|
69
69
|
// ==========================================
|
|
70
|
-
const downloadDirPath = constants.appRoot
|
|
70
|
+
const downloadDirPath = path.join(constants.appRoot, 'temp', 'mockServer');
|
|
71
71
|
if (!fs.existsSync(downloadDirPath)) {
|
|
72
72
|
fs.mkdirsSync(downloadDirPath);
|
|
73
73
|
}
|
|
@@ -75,13 +75,13 @@ export class MongoUtils {
|
|
|
75
75
|
// ==========================================
|
|
76
76
|
// Data directory
|
|
77
77
|
// ==========================================
|
|
78
|
-
const dataRootPath = downloadDirPath
|
|
78
|
+
const dataRootPath = path.join(downloadDirPath, 'data');
|
|
79
79
|
if (!fs.existsSync(dataRootPath)) {
|
|
80
80
|
fs.mkdirsSync(dataRootPath);
|
|
81
81
|
} else {
|
|
82
82
|
await utils.clearDir(dataRootPath);
|
|
83
83
|
}
|
|
84
|
-
const dataPath =
|
|
84
|
+
const dataPath = path.join(dataRootPath, Date.now().toString());
|
|
85
85
|
fs.mkdirsSync(dataPath);
|
|
86
86
|
|
|
87
87
|
// ==========================================
|
|
@@ -214,10 +214,7 @@ export class MongoUtils {
|
|
|
214
214
|
* @param publicMessage a public message to be used in the
|
|
215
215
|
* generated error. Fopr example : "The user is invalid".
|
|
216
216
|
*/
|
|
217
|
-
public convertMongoOrMongooseErrorToApiError(
|
|
218
|
-
err: any,
|
|
219
|
-
publicMessage: string,
|
|
220
|
-
): ApiErrorAndInfo | any {
|
|
217
|
+
public convertMongoOrMongooseErrorToApiError(err: any, publicMessage: string): any {
|
|
221
218
|
if (!err) {
|
|
222
219
|
return createServerError('Empty error object');
|
|
223
220
|
}
|
|
@@ -308,15 +305,12 @@ export class MongoUtils {
|
|
|
308
305
|
// ==========================================
|
|
309
306
|
// Converts the "_id" property to "id"
|
|
310
307
|
// ==========================================
|
|
311
|
-
// tslint:disable-next-line:no-string-literal
|
|
312
308
|
pojoObj['id'] = pojoObj['_id'].toString();
|
|
313
|
-
// tslint:disable-next-line:no-string-literal
|
|
314
309
|
delete pojoObj['_id'];
|
|
315
310
|
|
|
316
311
|
// ==========================================
|
|
317
312
|
// Removes the "__v"
|
|
318
313
|
// ==========================================
|
|
319
|
-
// tslint:disable-next-line:no-string-literal
|
|
320
314
|
delete pojoObj['__v'];
|
|
321
315
|
|
|
322
316
|
return pojo;
|