diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cbfd71..a209ca4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Move `writeConcern` away from top-level option to fix deprecation warning [#422](https://github.com/jdesboeufs/connect-mongo/issues/422) + ## [4.4.1] - 2021-03-23 ### Fixed diff --git a/package.json b/package.json index 88d6657..cd69d45 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "@istanbuljs/nyc-config-typescript": "^1.0.1", "@types/express": "^4.17.9", "@types/express-session": "^1.17.3", - "@types/mongodb": "^3.6.3", + "@types/mongodb": "^3.6.18", "@types/node": "^14.14.20", "@types/supertest": "^2.0.10", "@typescript-eslint/eslint-plugin": "^4.12.0", diff --git a/src/lib/MongoStore.ts b/src/lib/MongoStore.ts index 97b9037..d0bc3e1 100644 --- a/src/lib/MongoStore.ts +++ b/src/lib/MongoStore.ts @@ -38,7 +38,7 @@ export type ConnectMongoOptions = { // FIXME: remove those any serialize?: (a: any) => any unserialize?: (a: any) => any - writeOperationOptions?: CommonOptions + writeOperationOptions?: CommonOptions['writeConcern'] transformId?: (a: any) => any crypto?: CryptoOptions } @@ -61,7 +61,7 @@ type ConcretConnectMongoOptions = { // FIXME: remove those any serialize?: (a: any) => any unserialize?: (a: any) => any - writeOperationOptions?: CommonOptions + writeOperationOptions?: CommonOptions['writeConcern'] transformId?: (a: any) => any // FIXME: remove above any crypto: ConcretCryptoOptions @@ -225,7 +225,10 @@ export default class MongoStore extends session.Store { debug('Creating MongoDB TTL index') collection.createIndex( { expires: 1 }, - { expireAfterSeconds: 0, ...this.options.writeOperationOptions } + { + expireAfterSeconds: 0, + writeConcern: this.options.writeOperationOptions, + } ) break case 'interval': @@ -233,9 +236,10 @@ export default class MongoStore extends session.Store { this.timer = setInterval( () => collection.deleteMany(removeQuery(), { - ...this.options.writeOperationOptions, - w: 0, - j: false, + writeConcern: { + w: 0, + j: false, + }, }), this.options.autoRemoveInterval * 1000 * 60 ) @@ -382,7 +386,7 @@ export default class MongoStore extends session.Store { { $set: s }, { upsert: true, - ...this.options.writeOperationOptions, + writeConcern: this.options.writeOperationOptions, } ) if (rawResp.upsertedCount > 0) { @@ -438,7 +442,7 @@ export default class MongoStore extends session.Store { const rawResp = await collection.updateOne( { _id: this.computeStorageId(sid) }, { $set: updateFields }, - this.options.writeOperationOptions + { writeConcern: this.options.writeOperationOptions } ) if (rawResp.matchedCount === 0) { return callback(new Error('Unable to find the session to touch')) @@ -499,7 +503,7 @@ export default class MongoStore extends session.Store { .then((colleciton) => colleciton.deleteOne( { _id: this.computeStorageId(sid) }, - this.options.writeOperationOptions + { writeConcern: this.options.writeOperationOptions } ) ) .then(() => { diff --git a/yarn.lock b/yarn.lock index d78af77..dbee52d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -658,10 +658,10 @@ resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.1.tgz#283f669ff76d7b8260df8ab7a4262cc83d988256" integrity sha512-fZQQafSREFyuZcdWFAExYjBiCL7AUCdgsk80iO0q4yihYYdcIiH28CcuPTGFgLOCC8RlW49GSQxdHwZP+I7CNg== -"@types/mongodb@^3.6.3": - version "3.6.3" - resolved "https://registry.yarnpkg.com/@types/mongodb/-/mongodb-3.6.3.tgz#5655af409d9e32d5d5ae9a653abf3e5f9c83eb7a" - integrity sha512-6YNqGP1hk5bjUFaim+QoFFuI61WjHiHE1BNeB41TA00Xd2K7zG4lcWyLLq/XtIp36uMavvS5hoAUJ+1u/GcX2Q== +"@types/mongodb@^3.6.18": + version "3.6.18" + resolved "https://registry.yarnpkg.com/@types/mongodb/-/mongodb-3.6.18.tgz#7524c462fc7e3b67892afda8211cd045edee65eb" + integrity sha512-JSVFt9p0rTfZ4EgzXmVHUB3ue00xe3CRbQho8nXfImzEDDM4O7I3po1bwbWl/EIbLENxUreZxqLOc8lvcnLVPA== dependencies: "@types/bson" "*" "@types/node" "*"