Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NODE-4336): deprecate old write concern options and add missing writeConcern to MongoClientOptions #3340

Merged
merged 1 commit into from Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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