12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- 'use strict';
- const kWriteConcernKeys = new Set(['w', 'wtimeout', 'j', 'journal', 'fsync']);
- let utils;
- class WriteConcern {
-
- 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;
- }
- }
-
- static fromOptions(options) {
- if (
- options == null ||
- (options.writeConcern == null &&
- 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.journal,
- options.writeConcern.fsync
- );
- }
-
- 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
- );
- }
- }
- module.exports = WriteConcern;
|