@villedemontreal/mongo 7.1.0 → 7.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@villedemontreal/mongo",
3
- "version": "7.1.0",
3
+ "version": "7.1.2",
4
4
  "description": "Utilities for Mongo / Mongoose",
5
5
  "main": "dist/src/index.js",
6
6
  "typings": "dist/src",
@@ -29,16 +29,16 @@
29
29
  "author": "Ville de Montréal",
30
30
  "license": "MIT",
31
31
  "dependencies": {
32
- "@villedemontreal/general-utils": "5.16.8",
33
- "@villedemontreal/logger": "6.5.9",
32
+ "@villedemontreal/general-utils": "5.17.4",
33
+ "@villedemontreal/logger": "6.6.2",
34
34
  "app-root-path": "3.1.0",
35
35
  "fs-extra": "10.1.0",
36
36
  "http-status-codes": "2.2.0",
37
37
  "lodash": "4.17.21",
38
- "mongodb": "4.16.0",
38
+ "mongodb": "4.17.2",
39
39
  "mongodb-memory-server-core": "8.6.1",
40
- "mongoose": "6.11.0",
41
- "semver": "7.5.0"
40
+ "mongoose": "6.12.6",
41
+ "semver": "7.5.2"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/http-status-codes": "1.2.0",
@@ -50,11 +50,11 @@
50
50
  "@types/sinon": "10.0.13",
51
51
  "@typescript-eslint/eslint-plugin": "5.59.2",
52
52
  "@typescript-eslint/parser": "5.59.2",
53
- "@villedemontreal/scripting": "2.1.6",
53
+ "@villedemontreal/scripting": "2.1.8",
54
54
  "chai": "4.3.7",
55
55
  "eslint": "8.40.0",
56
56
  "eslint-config-prettier": "8.8.0",
57
- "eslint-plugin-prettier": "4.2.1",
57
+ "eslint-plugin-prettier": "5.1.3",
58
58
  "mocha": "9.2.2",
59
59
  "mocha-jenkins-reporter": "0.4.8",
60
60
  "nyc": "15.1.0",
@@ -126,7 +126,7 @@ export class MongooseConfigs implements IMongooseConfigs {
126
126
  if (!_.isNil(overridingConfigs.updater.lockMaxAgeSeconds)) {
127
127
  if (!utils.isIntegerValue(overridingConfigs.updater.lockMaxAgeSeconds, true, false)) {
128
128
  throw new Error(
129
- `The updater.lockMaxAgeSeconds config is not valid : ${overridingConfigs.updater.lockMaxAgeSeconds}`
129
+ `The updater.lockMaxAgeSeconds config is not valid : ${overridingConfigs.updater.lockMaxAgeSeconds}`,
130
130
  );
131
131
  }
132
132
  this.updater.lockMaxAgeSeconds = Number(overridingConfigs.updater.lockMaxAgeSeconds);
@@ -138,7 +138,7 @@ export class MongooseConfigs implements IMongooseConfigs {
138
138
  utils.isBlank(overridingConfigs.updater.appSchemaCollectionName)
139
139
  ) {
140
140
  throw new Error(
141
- `The appSchemaCollectionName config is not valid : ${overridingConfigs.updater.appSchemaCollectionName}`
141
+ `The appSchemaCollectionName config is not valid : ${overridingConfigs.updater.appSchemaCollectionName}`,
142
142
  );
143
143
  }
144
144
  this.updater.appSchemaCollectionName = overridingConfigs.updater.appSchemaCollectionName;
@@ -147,7 +147,7 @@ export class MongooseConfigs implements IMongooseConfigs {
147
147
  if (!_.isNil(overridingConfigs.applyUpdates)) {
148
148
  if (!_.isBoolean(overridingConfigs.applyUpdates)) {
149
149
  throw new Error(
150
- `The applyUpdates config must be a boolean: ${overridingConfigs.applyUpdates}`
150
+ `The applyUpdates config must be a boolean: ${overridingConfigs.applyUpdates}`,
151
151
  );
152
152
  }
153
153
  this.applyUpdates = overridingConfigs.applyUpdates;
@@ -159,20 +159,20 @@ export class MongooseConfigs implements IMongooseConfigs {
159
159
  utils.isBlank(overridingConfigs.connectionString)
160
160
  ) {
161
161
  throw new Error(
162
- `The connectionString config is not valid : ${overridingConfigs.connectionString}`
162
+ `The connectionString config is not valid : ${overridingConfigs.connectionString}`,
163
163
  );
164
164
  }
165
165
  this.connectionString = overridingConfigs.connectionString;
166
166
  } else {
167
167
  logger.warning(
168
- `No "connectionString" config was provided: a *mocked* Mongo server will be used!`
168
+ `No "connectionString" config was provided: a *mocked* Mongo server will be used!`,
169
169
  );
170
170
  }
171
171
 
172
172
  if (!_.isNil(overridingConfigs.connectionOptions)) {
173
173
  if (!_.isObject(overridingConfigs.connectionOptions)) {
174
174
  throw new Error(
175
- `The connectionOptions config is not valid : ${overridingConfigs.connectionString}`
175
+ `The connectionOptions config is not valid : ${overridingConfigs.connectionString}`,
176
176
  );
177
177
  }
178
178
  this.connectionOptions = overridingConfigs.connectionOptions;
@@ -187,7 +187,7 @@ export class MongooseConfigs implements IMongooseConfigs {
187
187
  utils.isBlank(overridingConfigs.mockServer.serverVersion)
188
188
  ) {
189
189
  throw new Error(
190
- `The mockServer.serverVersion config is not valid : ${overridingConfigs.mockServer.serverVersion}`
190
+ `The mockServer.serverVersion config is not valid : ${overridingConfigs.mockServer.serverVersion}`,
191
191
  );
192
192
  }
193
193
  this.mockServer.serverVersion = overridingConfigs.mockServer.serverVersion;
@@ -13,7 +13,7 @@ let mongooseConnection: mongoose.Connection;
13
13
  async function doInitMongoose(
14
14
  mongooseConfigClean: MongooseConfigs,
15
15
  resolve: (value: mongoose.Connection) => void,
16
- reject: (reason?: any) => void
16
+ reject: (reason?: any) => void,
17
17
  ): Promise<void> {
18
18
  let connectionString = mongooseConfigClean.connectionString;
19
19
 
@@ -26,7 +26,7 @@ async function doInitMongoose(
26
26
  // ==========================================
27
27
  const mongoServer = await mongoUtils.mockMongoose(
28
28
  null,
29
- mongooseConfigClean.mockServer.serverVersion
29
+ mongooseConfigClean.mockServer.serverVersion,
30
30
  );
31
31
 
32
32
  connectionString = mongoServer.getUri();
@@ -113,7 +113,7 @@ async function checkForUpdates(mongooseConfig: IMongooseConfigs): Promise<void>
113
113
  connection.db,
114
114
  mongooseConfig.updater.mongoSchemaUpdatesDirPath,
115
115
  mongooseConfig.updater.lockMaxAgeSeconds,
116
- mongooseConfig.updater.appSchemaCollectionName
116
+ mongooseConfig.updater.appSchemaCollectionName,
117
117
  );
118
118
  await updater.checkInstallation();
119
119
  await updater.checkUpdates();
@@ -39,7 +39,7 @@ describe('Mongo Updater', () => {
39
39
  mongoDb,
40
40
  testconfig.updater.mongoSchemaUpdatesDirPath,
41
41
  testconfig.updater.lockMaxAgeSeconds,
42
- testconfig.updater.appSchemaCollectionName
42
+ testconfig.updater.appSchemaCollectionName,
43
43
  );
44
44
  });
45
45
 
@@ -101,7 +101,7 @@ describe('Mongo Updater', () => {
101
101
  assert.strictEqual(collections[0].name, testconfig.updater.appSchemaCollectionName);
102
102
 
103
103
  const schema: MongoDb.Collection = mongoDb.collection(
104
- testconfig.updater.appSchemaCollectionName
104
+ testconfig.updater.appSchemaCollectionName,
105
105
  );
106
106
  const schemaDb: any[] = await schema.find().toArray();
107
107
  assert.strictEqual(schemaDb[0].version, '0.0.0');
@@ -118,7 +118,7 @@ describe('Mongo Updater', () => {
118
118
  describe('lock', () => {
119
119
  it('lock should be equal to false', async () => {
120
120
  const schema: MongoDb.Collection = mongoDb.collection(
121
- testconfig.updater.appSchemaCollectionName
121
+ testconfig.updater.appSchemaCollectionName,
122
122
  );
123
123
  const schemaDb: any[] = await schema.find().toArray();
124
124
  assert.strictEqual(schemaDb[0].lock, false);
@@ -131,7 +131,7 @@ describe('Mongo Updater', () => {
131
131
 
132
132
  it('lock should be equal to true', async () => {
133
133
  const schema: MongoDb.Collection = mongoDb.collection(
134
- testconfig.updater.appSchemaCollectionName
134
+ testconfig.updater.appSchemaCollectionName,
135
135
  );
136
136
  const schemaDb: any[] = await schema.find().toArray();
137
137
  assert.strictEqual(schemaDb[0].lock, true);
@@ -146,7 +146,7 @@ describe('Mongo Updater', () => {
146
146
  describe('unlock', () => {
147
147
  it('lock should be equal to true', async () => {
148
148
  const schema: MongoDb.Collection = mongoDb.collection(
149
- testconfig.updater.appSchemaCollectionName
149
+ testconfig.updater.appSchemaCollectionName,
150
150
  );
151
151
  const schemaDb: any[] = await schema.find().toArray();
152
152
  assert.strictEqual(schemaDb[0].lock, true);
@@ -159,7 +159,7 @@ describe('Mongo Updater', () => {
159
159
 
160
160
  it('lock should be equal to false', async () => {
161
161
  const schema: MongoDb.Collection = mongoDb.collection(
162
- testconfig.updater.appSchemaCollectionName
162
+ testconfig.updater.appSchemaCollectionName,
163
163
  );
164
164
  const schemaDb: any[] = await schema.find().toArray();
165
165
  assert.strictEqual(schemaDb[0].lock, false);
@@ -170,7 +170,7 @@ describe('Mongo Updater', () => {
170
170
  assert.strictEqual(isUnlocked, false);
171
171
 
172
172
  const schema: MongoDb.Collection = mongoDb.collection(
173
- testconfig.updater.appSchemaCollectionName
173
+ testconfig.updater.appSchemaCollectionName,
174
174
  );
175
175
  const schemaDb: any[] = await schema.find().toArray();
176
176
  assert.strictEqual(schemaDb[0].lock, false);
@@ -89,7 +89,7 @@ export class MongoUpdater implements IMongoUpdater {
89
89
  */
90
90
  private mongoSchemaUpdatesDirPath: string,
91
91
  private lockMaxAgeSeconds: number,
92
- private appSchemaCollectionName: string
92
+ private appSchemaCollectionName: string,
93
93
  ) {}
94
94
 
95
95
  public async installAppSchemaCollection(): Promise<any> {
@@ -98,7 +98,7 @@ export class MongoUpdater implements IMongoUpdater {
98
98
  // tslint:disable-next-line: prefer-template
99
99
  logger.info(' > Installing the "' + this.appSchemaCollectionName + '" collection.');
100
100
  const collection: MongoDb.Collection = await this.mongoDb.createCollection(
101
- this.appSchemaCollectionName
101
+ this.appSchemaCollectionName,
102
102
  );
103
103
 
104
104
  // ==========================================
@@ -162,13 +162,13 @@ export class MongoUpdater implements IMongoUpdater {
162
162
  await appSchemaCollection.updateOne({}, { $set: { version: newVersion } });
163
163
  // tslint:disable-next-line: prefer-template
164
164
  logger.info(
165
- ' > MongoDB App Schema updagred from version ' + currentVersion + ' to version ' + newVersion
165
+ ' > MongoDB App Schema updagred from version ' + currentVersion + ' to version ' + newVersion,
166
166
  );
167
167
  }
168
168
 
169
169
  public async getAppSchemaUpdateFiles(
170
170
  currentAppSchemaVersion: string,
171
- targetAppSchemaVersion: string
171
+ targetAppSchemaVersion: string,
172
172
  ): Promise<string[]> {
173
173
  return new Promise<string[]>((resolve, reject) => {
174
174
  fs.readdir(this.getAppSchemaFilesDirPath(), (err, files) => {
@@ -206,7 +206,7 @@ export class MongoUpdater implements IMongoUpdater {
206
206
  public async applyAppSchemaUpdates(currentVersion: string, newVersion: string): Promise<void> {
207
207
  const updateFileNames: string[] = await this.getAppSchemaUpdateFiles(
208
208
  currentVersion,
209
- newVersion
209
+ newVersion,
210
210
  );
211
211
  if (updateFileNames.length > 0) {
212
212
  for (const updateFileName of updateFileNames) {
@@ -224,7 +224,7 @@ export class MongoUpdater implements IMongoUpdater {
224
224
  if (!isFunction(updateFunction)) {
225
225
  return Promise.reject(
226
226
  'The default export for an app schema update file must be a function! Was not for file : ' +
227
- updateFilePath
227
+ updateFilePath,
228
228
  );
229
229
  }
230
230
 
@@ -269,7 +269,7 @@ export class MongoUpdater implements IMongoUpdater {
269
269
  lock: true,
270
270
  lockTimestamp: new Date().getTime(),
271
271
  },
272
- }
272
+ },
273
273
  );
274
274
 
275
275
  if (document.value !== null) {
@@ -301,7 +301,7 @@ export class MongoUpdater implements IMongoUpdater {
301
301
  lock: true,
302
302
  lockTimestamp: new Date().getTime(),
303
303
  },
304
- }
304
+ },
305
305
  );
306
306
 
307
307
  // ==========================================
@@ -331,7 +331,7 @@ export class MongoUpdater implements IMongoUpdater {
331
331
  lock: false,
332
332
  lockTimestamp: 0,
333
333
  },
334
- }
334
+ },
335
335
  );
336
336
 
337
337
  if (document.value !== null) {
@@ -345,7 +345,7 @@ export class MongoUpdater implements IMongoUpdater {
345
345
 
346
346
  public async checkInstallation(): Promise<void> {
347
347
  logger.info(
348
- `Validating that the "${this.appSchemaCollectionName}" collection required by the application has been installed.`
348
+ `Validating that the "${this.appSchemaCollectionName}" collection required by the application has been installed.`,
349
349
  );
350
350
  const collections: any[] = await this.mongoDb
351
351
  .listCollections({ name: this.appSchemaCollectionName })
@@ -353,12 +353,12 @@ export class MongoUpdater implements IMongoUpdater {
353
353
 
354
354
  if (collections.length === 0) {
355
355
  logger.info(
356
- ` > The "${this.appSchemaCollectionName}" collection was not found... Starting a new installation.`
356
+ ` > The "${this.appSchemaCollectionName}" collection was not found... Starting a new installation.`,
357
357
  );
358
358
  await this.installAppSchemaCollection();
359
359
  } else {
360
360
  logger.info(
361
- ` > The "${this.appSchemaCollectionName}" collection was found. No installation required.`
361
+ ` > The "${this.appSchemaCollectionName}" collection was found. No installation required.`,
362
362
  );
363
363
  }
364
364
  }
@@ -379,7 +379,7 @@ export class MongoUpdater implements IMongoUpdater {
379
379
  if (semver.gte(currentAppSchemaVersion, targetVersion)) {
380
380
  // tslint:disable-next-line: prefer-template
381
381
  logger.info(
382
- ' > Current database app schema is up to date : ' + currentAppSchemaVersion + ').'
382
+ ' > Current database app schema is up to date : ' + currentAppSchemaVersion + ').',
383
383
  );
384
384
  return;
385
385
  }
@@ -395,7 +395,7 @@ export class MongoUpdater implements IMongoUpdater {
395
395
  const wait = 1000;
396
396
  logger.warning(
397
397
  `The lock can't be acquired. The maximum age it can be before being considered ` +
398
- `to be too old is ${this.lockMaxAgeSeconds} seconds. Waiting for ${wait} milliseconds...`
398
+ `to be too old is ${this.lockMaxAgeSeconds} seconds. Waiting for ${wait} milliseconds...`,
399
399
  );
400
400
  await utils.sleep(wait);
401
401
  } else {
package/src/mongoUtils.ts CHANGED
@@ -54,7 +54,7 @@ export class MongoUtils {
54
54
  public async mockMongoose(
55
55
  mochaInstance: mocha.Context,
56
56
  mongoServerVersion: string,
57
- useReplSet = false
57
+ useReplSet = false,
58
58
  ): Promise<MongoMemoryServer | MongoMemoryReplSet> {
59
59
  // ==========================================
60
60
  // We only mock the database if it's
@@ -96,7 +96,7 @@ export class MongoUtils {
96
96
  `The "mocha" parameter passed to the "mockMongoose(...)" method ` +
97
97
  `doesn't seems to be of the correct type. Make sure the function in which you ` +
98
98
  `call "mockMongoose(...)" is itself a *regular* function, not an *arrow* function. ` +
99
- `Have a look at https://github.com/mochajs/mocha/issues/2018 for more infos.`
99
+ `Have a look at https://github.com/mochajs/mocha/issues/2018 for more infos.`,
100
100
  );
101
101
  }
102
102
 
@@ -219,7 +219,7 @@ export class MongoUtils {
219
219
  */
220
220
  public convertMongoOrMongooseErrorToApiError(
221
221
  err: any,
222
- publicMessage: string
222
+ publicMessage: string,
223
223
  ): ApiErrorAndInfo | any {
224
224
  if (!err) {
225
225
  return createServerError('Empty error object');
@@ -239,7 +239,7 @@ export class MongoUtils {
239
239
  if (errClean.code === constants.mongo.mongoErrorCodes.DUPLICATE_KEY) {
240
240
  return createError(
241
241
  globalConstants.errors.apiGeneralErrors.codes.DUPLICATE_KEY,
242
- publicMessage
242
+ publicMessage,
243
243
  )
244
244
  .httpStatus(HttpStatusCodes.CONFLICT)
245
245
  .publicMessage(publicMessage)
@@ -32,7 +32,7 @@ describe('plugin pagination', () => {
32
32
  // Makes sure Mongoose is mocked, but not in Jenkins as we will start a dedicated mongodb container.
33
33
  const mockedDb = await mongoUtils.mockMongoose(
34
34
  this,
35
- constants.testsConfig.mockServer.serverVersion
35
+ constants.testsConfig.mockServer.serverVersion,
36
36
  );
37
37
  const connString = mockedDb.getUri();
38
38
  await mongoose.connect(connString);
@@ -3,7 +3,7 @@ import { IPaginateOptions } from './specs/IPaginateOptions';
3
3
  function paginate(
4
4
  q: any,
5
5
  options: IPaginateOptions,
6
- callback: (error: Error, result: any) => void
6
+ callback: (error: Error, result: any) => void,
7
7
  ) {
8
8
  const optionsClean = PaginateBuilder.getOptions((paginate as any).options, options);
9
9
 
@@ -36,7 +36,7 @@ export class PaginateBuilder {
36
36
  public static executeQueries(
37
37
  model: any,
38
38
  query: any,
39
- options: IPaginateOptions
39
+ options: IPaginateOptions,
40
40
  ): [Promise<any[]>, Promise<number>] {
41
41
  const { select, sort, populate, lean, leanWithId, limit, offset } = options;
42
42
  let itemsQuery: any;
@@ -62,7 +62,7 @@ export class PaginateBuilder {
62
62
  public static processResult(
63
63
  promises: any[],
64
64
  options: IPaginateOptions,
65
- callback: (error: Error, result: any) => void
65
+ callback: (error: Error, result: any) => void,
66
66
  ): Promise<any> {
67
67
  const { lean, leanWithId, limit, offset } = options;
68
68
  return new Promise((resolve, reject) => {
@@ -94,7 +94,7 @@ export class PaginateBuilder {
94
94
  return callback(error, null);
95
95
  }
96
96
  reject(error);
97
- }
97
+ },
98
98
  );
99
99
  });
100
100
  }