Skip to content

Commit

Permalink
feat(NODE-4336): deprecate old write concern options and add missing …
Browse files Browse the repository at this point in the history
…writeConcern to MongoClientOptions (#3340)
  • Loading branch information
nbbeeken committed Jul 29, 2022
1 parent bff37aa commit d2b6ad8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/connection_string.ts
Expand Up @@ -1188,7 +1188,7 @@ export const OPTIONS = {

throw new MongoParseError(`Invalid WriteConcern cannot parse: ${JSON.stringify(value)}`);
}
} as OptionDescriptor,
},
wtimeout: {
deprecated: 'Please use wtimeoutMS instead',
target: 'writeConcern',
Expand Down
26 changes: 20 additions & 6 deletions src/mongo_client.ts
Expand Up @@ -33,7 +33,7 @@ import {
ns,
resolveOptions
} from './utils';
import type { W, WriteConcern } from './write_concern';
import type { W, WriteConcern, WriteConcernSettings } from './write_concern';

/** @public */
export const ServerApiVersion = Object.freeze({
Expand Down Expand Up @@ -183,14 +183,28 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
directConnection?: boolean;
/** Instruct the driver it is connecting to a load balancer fronting a mongos like service */
loadBalanced?: boolean;

/** The write concern w value */
/**
* The write concern w value
* @deprecated Please use the `writeConcern` option instead
*/
w?: W;
/** The write concern timeout */
/**
* The write concern timeout
* @deprecated Please use the `writeConcern` option instead
*/
wtimeoutMS?: number;
/** The journal write concern */
/**
* The journal write concern
* @deprecated Please use the `writeConcern` option instead
*/
journal?: boolean;

/**
* A MongoDB WriteConcern, which describes the level of acknowledgement
* requested from MongoDB for write operations.
*
* @see https://docs.mongodb.com/manual/reference/write-concern/
*/
writeConcern?: WriteConcern | WriteConcernSettings;
/** Validate mongod server certificate against Certificate Authority */
sslValidate?: boolean;
/** SSL Certificate file path. */
Expand Down
9 changes: 8 additions & 1 deletion test/types/mongodb.test-d.ts
@@ -1,7 +1,7 @@
import type { Document } from 'bson';
import { expectDeprecated, expectError, expectNotDeprecated, expectType } from 'tsd';

import { Db, WithId } from '../../src';
import { Db, WithId, WriteConcern, WriteConcernSettings } from '../../src';
import * as MongoDBDriver from '../../src';
import type { ChangeStreamDocument } from '../../src/change_stream';
import { Collection } from '../../src/collection';
Expand All @@ -23,6 +23,13 @@ expectDeprecated(Db.prototype.unref);
expectDeprecated(MongoDBDriver.ObjectID);
expectNotDeprecated(MongoDBDriver.ObjectId);

declare const options: MongoDBDriver.MongoClientOptions;
expectDeprecated(options.w);
expectDeprecated(options.journal);
expectDeprecated(options.wtimeoutMS);
expectNotDeprecated(options.writeConcern);
expectType<WriteConcernSettings | WriteConcern | undefined>(options.writeConcern);

interface TSchema extends Document {
name: string;
}
Expand Down

0 comments on commit d2b6ad8

Please sign in to comment.