From e1246db8c94d1019d42d20c8905379c120e5ccd3 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 15 Dec 2020 11:44:43 -0500 Subject: [PATCH] Fix wc spread at the mongoclient level remains --- src/connection_string.ts | 39 +++++++++++++++++++++++++-------------- src/mongo_client.ts | 16 +++++++++++----- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/connection_string.ts b/src/connection_string.ts index 5307776d021..c0676bf2125 100644 --- a/src/connection_string.ts +++ b/src/connection_string.ts @@ -1199,8 +1199,10 @@ export const OPTIONS = { target: 'writeConcern', transform({ name, options, values: [value] }): WriteConcern { const wc = WriteConcern.fromOptions({ - ...options.writeConcern, - fsync: getBoolean(name, value) + writeConcern: { + ...options.writeConcern, + fsync: getBoolean(name, value) + } }); if (!wc) throw new TypeError(`Unable to make a writeConcern from fsync=${value}`); return wc; @@ -1216,10 +1218,11 @@ export const OPTIONS = { j: { target: 'writeConcern', transform({ name, options, values: [value] }): WriteConcern { - console.warn('j is deprecated'); const wc = WriteConcern.fromOptions({ - ...options.writeConcern, - journal: getBoolean(name, value) + writeConcern: { + ...options.writeConcern, + journal: getBoolean(name, value) + } }); if (!wc) throw new TypeError(`Unable to make a writeConcern from journal=${value}`); return wc; @@ -1229,8 +1232,10 @@ export const OPTIONS = { target: 'writeConcern', transform({ name, options, values: [value] }): WriteConcern { const wc = WriteConcern.fromOptions({ - ...options.writeConcern, - journal: getBoolean(name, value) + writeConcern: { + ...options.writeConcern, + journal: getBoolean(name, value) + } }); if (!wc) throw new TypeError(`Unable to make a writeConcern from journal=${value}`); return wc; @@ -1516,7 +1521,7 @@ export const OPTIONS = { w: { target: 'writeConcern', transform({ values: [value], options }) { - return WriteConcern.fromOptions({ ...options.writeConcern, w: value as W }); + return WriteConcern.fromOptions({ writeConcern: { ...options.writeConcern, w: value as W } }); } }, waitQueueTimeoutMS: { @@ -1528,8 +1533,10 @@ export const OPTIONS = { transform({ values: [value], options }) { if (isRecord(value)) { return WriteConcern.fromOptions({ - ...options.writeConcern, - ...value + writeConcern: { + ...options.writeConcern, + ...value + } }); } throw new MongoParseError(`WriteConcern must be an object, got ${JSON.stringify(value)}`); @@ -1539,8 +1546,10 @@ export const OPTIONS = { target: 'writeConcern', transform({ values: [value], options }) { const wc = WriteConcern.fromOptions({ - ...options.writeConcern, - wtimeout: getUint('wtimeout', value) + writeConcern: { + ...options.writeConcern, + wtimeout: getUint('wtimeout', value) + } }); if (wc) return wc; throw new MongoParseError(`Cannot make WriteConcern from wtimeout`); @@ -1550,8 +1559,10 @@ export const OPTIONS = { target: 'writeConcern', transform({ values: [value], options }) { const wc = WriteConcern.fromOptions({ - ...options.writeConcern, - wtimeoutMS: getUint('wtimeoutMS', value) + writeConcern: { + ...options.writeConcern, + wtimeoutMS: getUint('wtimeoutMS', value) + } }); if (wc) return wc; throw new MongoParseError(`Cannot make WriteConcern from wtimeout`); diff --git a/src/mongo_client.ts b/src/mongo_client.ts index ebf0152925e..cdfc8f984cd 100644 --- a/src/mongo_client.ts +++ b/src/mongo_client.ts @@ -3,7 +3,7 @@ import { EventEmitter } from 'events'; import { ChangeStream, ChangeStreamOptions } from './change_stream'; import { ReadPreference, ReadPreferenceModeId } from './read_preference'; import { MongoError, AnyError } from './error'; -import { WriteConcern, WriteConcernOptions, W } from './write_concern'; +import { WriteConcern, W, WriteConcernSettings } from './write_concern'; import { maybePromise, MongoDBNamespace, Callback, resolveOptions } from './utils'; import { deprecate } from 'util'; import { connect, validOptions } from './operations/connect'; @@ -134,13 +134,19 @@ export interface MongoURIOptions { // username and password in Authority section not query string. username?: string; password?: string; + + // remove in NODE-2704 + fsync?: boolean; + w?: W; + j?: boolean; + journal?: boolean; + wtimeout?: number; + wtimeoutMS?: number; + writeConcern?: WriteConcern | WriteConcernSettings; } /** @public */ -export interface MongoClientOptions - extends WriteConcernOptions, - MongoURIOptions, - BSONSerializeOptions { +export interface MongoClientOptions extends MongoURIOptions, BSONSerializeOptions { /** Validate mongod server certificate against Certificate Authority */ sslValidate?: boolean; /** SSL Certificate store binary buffer. */