Cleanup
This commit is contained in:
34
node_modules/mongodb/lib/write_concern.js
generated
vendored
34
node_modules/mongodb/lib/write_concern.js
generated
vendored
@@ -1,5 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
const kWriteConcernKeys = new Set(['w', 'wtimeout', 'j', 'journal', 'fsync']);
|
||||
let utils;
|
||||
|
||||
/**
|
||||
* The **WriteConcern** class is a class that represents a MongoDB WriteConcern.
|
||||
* @class
|
||||
@@ -35,7 +38,12 @@ class WriteConcern {
|
||||
/**
|
||||
* Construct a WriteConcern given an options object.
|
||||
*
|
||||
* @param {object} options The options object from which to extract the write concern.
|
||||
* @param {object} [options] The options object from which to extract the write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** Use `options.writeConcern` instead
|
||||
* @param {number} [options.wtimeout] **Deprecated** Use `options.writeConcern` instead
|
||||
* @param {boolean} [options.j] **Deprecated** Use `options.writeConcern` instead
|
||||
* @param {boolean} [options.fsync] **Deprecated** Use `options.writeConcern` instead
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @return {WriteConcern}
|
||||
*/
|
||||
static fromOptions(options) {
|
||||
@@ -45,21 +53,41 @@ class WriteConcern {
|
||||
options.w == null &&
|
||||
options.wtimeout == null &&
|
||||
options.j == null &&
|
||||
options.journal == null &&
|
||||
options.fsync == null)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.writeConcern) {
|
||||
if (typeof options.writeConcern === 'string') {
|
||||
return new WriteConcern(options.writeConcern);
|
||||
}
|
||||
|
||||
if (!Object.keys(options.writeConcern).some(key => kWriteConcernKeys.has(key))) {
|
||||
return;
|
||||
}
|
||||
|
||||
return new WriteConcern(
|
||||
options.writeConcern.w,
|
||||
options.writeConcern.wtimeout,
|
||||
options.writeConcern.j,
|
||||
options.writeConcern.j || options.writeConcern.journal,
|
||||
options.writeConcern.fsync
|
||||
);
|
||||
}
|
||||
|
||||
return new WriteConcern(options.w, options.wtimeout, options.j, options.fsync);
|
||||
// this is down here to prevent circular dependency
|
||||
if (!utils) utils = require('./utils');
|
||||
|
||||
utils.emitWarningOnce(
|
||||
`Top-level use of w, wtimeout, j, and fsync is deprecated. Use writeConcern instead.`
|
||||
);
|
||||
return new WriteConcern(
|
||||
options.w,
|
||||
options.wtimeout,
|
||||
options.j || options.journal,
|
||||
options.fsync
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user