From e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d Mon Sep 17 00:00:00 2001 From: Piotr Russ Date: Mon, 16 Nov 2020 00:10:28 +0100 Subject: api, login, auth --- node_modules/mongodb/lib/write_concern.js | 76 +++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 node_modules/mongodb/lib/write_concern.js (limited to 'node_modules/mongodb/lib/write_concern.js') diff --git a/node_modules/mongodb/lib/write_concern.js b/node_modules/mongodb/lib/write_concern.js new file mode 100644 index 0000000..1ba0380 --- /dev/null +++ b/node_modules/mongodb/lib/write_concern.js @@ -0,0 +1,76 @@ +'use strict'; + +const kWriteConcernKeys = new Set(['w', 'wtimeout', 'j', 'fsync']); + +/** + * The **WriteConcern** class is a class that represents a MongoDB WriteConcern. + * @class + * @property {(number|string)} w The write concern + * @property {number} wtimeout The write concern timeout + * @property {boolean} j The journal write concern + * @property {boolean} fsync The file sync write concern + * @see https://docs.mongodb.com/manual/reference/write-concern/index.html + */ +class WriteConcern { + /** + * Constructs a WriteConcern from the write concern properties. + * @param {(number|string)} [w] The write concern + * @param {number} [wtimeout] The write concern timeout + * @param {boolean} [j] The journal write concern + * @param {boolean} [fsync] The file sync write concern + */ + constructor(w, wtimeout, j, fsync) { + if (w != null) { + this.w = w; + } + if (wtimeout != null) { + this.wtimeout = wtimeout; + } + if (j != null) { + this.j = j; + } + if (fsync != null) { + this.fsync = fsync; + } + } + + /** + * Construct a WriteConcern given an options object. + * + * @param {object} options The options object from which to extract the write concern. + * @return {WriteConcern} + */ + static fromOptions(options) { + if ( + options == null || + (options.writeConcern == null && + options.w == null && + options.wtimeout == null && + options.j == 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.fsync + ); + } + + return new WriteConcern(options.w, options.wtimeout, options.j, options.fsync); + } +} + +module.exports = WriteConcern; -- cgit v1.2.3