Skip to content

Commit

Permalink
feat(NODE-4925)!: remove deprecated options and types (#3513)
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson authored Jan 5, 2023
1 parent fe65746 commit 8f8ea45
Show file tree
Hide file tree
Showing 25 changed files with 323 additions and 398 deletions.
45 changes: 44 additions & 1 deletion etc/notes/CHANGES_5.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,50 @@ The following is a detailed collection of the changes in the major v5 release of

## Changes

### salveOk options removed
### `AddUserOptions.digestPassword` removed

The `digestPassword` option has been removed from the add user helper.

### Removal of Internal Types from Public API

The following types are used internally the driver but were accidentally exported. They have now been
marked internal and are no longer exported.

- ServerSelector
- PipeOptions
- ServerOptions

### `DeleteOptions.single` Option Removed

TODO - merge in Neal's removal of `collection.remove` and combine notes

### Remove of `ObjectID` Type in Favor Of `ObjectId`

For clarity the deprecated and duplicate export ObjectID has been removed. ObjectId matches the class name and is equal in every way to the capital "D" export.

### Kerberos Option `gssapiCanonicalizeHostName` Removed

`gssapiCanonicalizeHostName` has been removed in favor of the `CANONICALIZE_HOST_NAME` value.

### `Projection` and `ProjectionOperations` Types Removed

Both of these types were unused but exported. These types have been removed. Please
use `Document` instead.

### `CommandOperationOptions.fullResponse` Option Removed

The `fullResponse` option on the `CommandOperationOptions` as unused in the driver and has been removed.

### `BulkWriteOptions.keepGoing` Option Removed

The `keepGoing` option on the `BulkWriteOptions` has been removed. Please use the `ordered` option instead.

### `WriteConcernError.err()` Removed

The `err()` getter on the WriteConcernError class has been removed. The `toJSON()` method can be in place
of `err()`.

### slaveOk options removed

The deprecated `slaveOk` option and `slaveOk()` method on the `Collection` class have been removed. Please
now use `secondaryOk` as the replacement for the option and the method.
Expand Down
495 changes: 262 additions & 233 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@aws-sdk/credential-providers": "^3.201.0",
"@iarna/toml": "^2.2.5",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@microsoft/api-extractor": "^7.33.3",
"@microsoft/api-extractor": "^7.33.7",
"@microsoft/tsdoc-config": "^0.16.2",
"@mongodb-js/zstd": "^1.0.0",
"@types/chai": "^4.3.3",
Expand All @@ -62,12 +62,12 @@
"@types/sinon": "^10.0.13",
"@types/sinon-chai": "^3.2.8",
"@types/whatwg-url": "^11.0.0",
"@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.40.0",
"@typescript-eslint/eslint-plugin": "^5.48.0",
"@typescript-eslint/parser": "^5.48.0",
"chai": "^4.3.6",
"chai-subset": "^1.6.0",
"chalk": "^4.1.2",
"eslint": "^8.25.0",
"eslint": "^8.31.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
Expand All @@ -87,8 +87,8 @@
"source-map-support": "^0.5.21",
"standard-version": "^9.5.0",
"ts-node": "^10.9.1",
"tsd": "^0.24.1",
"typescript": "^4.8.4",
"tsd": "^0.25.0",
"typescript": "^4.9.4",
"typescript-cached-transpile": "^0.0.6",
"xml2js": "^0.4.23",
"yargs": "^17.6.0"
Expand Down
7 changes: 0 additions & 7 deletions src/bulk/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,6 @@ export class WriteConcernError {
return this[kServerError].errInfo;
}

/** @deprecated The `err` prop that contained a MongoServerError has been deprecated. */
get err(): WriteConcernErrorData {
return this[kServerError];
}

toJSON(): WriteConcernErrorData {
return this[kServerError];
}
Expand Down Expand Up @@ -876,8 +871,6 @@ export interface BulkWriteOptions extends CommandOperationOptions {
bypassDocumentValidation?: boolean;
/** If true, when an insert fails, don't execute the remaining writes. If false, continue with remaining inserts when one fails. */
ordered?: boolean;
/** @deprecated use `ordered` instead */
keepGoing?: boolean;
/** Force server to assign _id values instead of driver. */
forceServerObjectId?: boolean;
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
Expand Down
8 changes: 0 additions & 8 deletions src/change_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,6 @@ export type ResumeToken = unknown;
*/
export type OperationTime = Timestamp;

/**
* @public
* @deprecated This interface is unused and will be removed in the next major version of the driver.
*/
export interface PipeOptions {
end?: boolean;
}

/**
* Options that can be passed to a ChangeStream. Note that startAfter, resumeAfter, and startAtOperationTime are all mutually exclusive, and the server will error if more than one is specified.
* @public
Expand Down
2 changes: 0 additions & 2 deletions src/cmap/auth/gssapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export type GSSAPICanonicalizationValue =
typeof GSSAPICanonicalizationValue[keyof typeof GSSAPICanonicalizationValue];

type MechanismProperties = {
/** @deprecated use `CANONICALIZE_HOST_NAME` instead */
gssapiCanonicalizeHostName?: boolean;
CANONICALIZE_HOST_NAME?: GSSAPICanonicalizationValue;
SERVICE_HOST?: string;
SERVICE_NAME?: string;
Expand Down
9 changes: 0 additions & 9 deletions src/cmap/auth/mongo_credentials.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Resolves the default auth mechanism according to
import type { Document } from '../../bson';
import { MongoAPIError, MongoMissingCredentialsError } from '../../error';
import { emitWarningOnce } from '../../utils';
import { GSSAPICanonicalizationValue } from './gssapi';
import { AUTH_MECHS_AUTH_SRC_EXTERNAL, AuthMechanism } from './providers';

Expand Down Expand Up @@ -91,14 +90,6 @@ export class MongoCredentials {
}
}

if ('gssapiCanonicalizeHostName' in this.mechanismProperties) {
emitWarningOnce(
'gssapiCanonicalizeHostName is deprecated. Please use CANONICALIZE_HOST_NAME instead.'
);
this.mechanismProperties.CANONICALIZE_HOST_NAME =
this.mechanismProperties.gssapiCanonicalizeHostName;
}

Object.freeze(this.mechanismProperties);
Object.freeze(this);
}
Expand Down
4 changes: 0 additions & 4 deletions src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1652,10 +1652,6 @@ export class Collection<TSchema extends Document = Document> {
options = options || { ordered: false };
docs = !Array.isArray(docs) ? [docs] : docs;

if (options.keepGoing === true) {
options.ordered = false;
}

return this.insertMany(docs, options, callback);
}

Expand Down
12 changes: 1 addition & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Admin } from './admin';
import { ObjectId } from './bson';
import { OrderedBulkOperation } from './bulk/ordered';
import { UnorderedBulkOperation } from './bulk/unordered';
import { ChangeStream } from './change_stream';
Expand Down Expand Up @@ -36,14 +35,8 @@ export {
ObjectId,
Timestamp
} from './bson';
export { ChangeStreamCursor } from './cursor/change_stream_cursor';
/**
* @public
* @deprecated Please use `ObjectId`
*/
export const ObjectID = ObjectId;

export { AnyBulkWriteOperation, BulkWriteOptions, MongoBulkWriteError } from './bulk/common';
export { ChangeStreamCursor } from './cursor/change_stream_cursor';
export {
MongoAPIError,
MongoAWSError,
Expand Down Expand Up @@ -204,7 +197,6 @@ export type {
ChangeStreamShardCollectionDocument,
ChangeStreamUpdateDocument,
OperationTime,
PipeOptions,
ResumeOptions,
ResumeToken,
UpdateDescription
Expand Down Expand Up @@ -339,8 +331,6 @@ export type {
OnlyFieldsOfType,
OptionalId,
OptionalUnlessRequiredId,
Projection,
ProjectionOperators,
PropertyType,
PullAllOperator,
PullOperator,
Expand Down
14 changes: 0 additions & 14 deletions src/mongo_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,6 @@ export type BSONType = typeof BSONType[keyof typeof BSONType];
/** @public */
export type BSONTypeAlias = keyof typeof BSONType;

/**
* @public
* Projection is flexible to permit the wide array of aggregation operators
* @deprecated since v4.1.0: Since projections support all aggregation operations we have no plans to narrow this type further
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export type Projection<TSchema extends Document = Document> = Document;

/**
* @public
* @deprecated since v4.1.0: Since projections support all aggregation operations we have no plans to narrow this type further
*/
export type ProjectionOperators = Document;

/** @public */
export type IsAny<Type, ResultIfAny, ResultIfNotAny> = true extends false & Type
? ResultIfAny
Expand Down
6 changes: 3 additions & 3 deletions src/operations/add_user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ export interface RoleSpecification {

/** @public */
export interface AddUserOptions extends CommandOperationOptions {
/** @deprecated Please use db.command('createUser', ...) instead for this option */
digestPassword?: null;
/** Roles associated with the created user */
roles?: string | string[] | RoleSpecification | RoleSpecification[];
/** Custom data associated with the user (only Mongodb 2.6 or higher) */
Expand Down Expand Up @@ -57,7 +55,9 @@ export class AddUserOperation extends CommandOperation<Document> {
const options = this.options;

// Error out if digestPassword set
if (options.digestPassword != null) {
// v5 removed the digestPassword option from AddUserOptions but we still want to throw
// an error when digestPassword is provided.
if ('digestPassword' in options && options.digestPassword != null) {
return callback(
new MongoInvalidArgumentError(
'Option "digestPassword" not supported via addUser, use db.command(...) instead'
Expand Down
2 changes: 0 additions & 2 deletions src/operations/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ export interface CommandOperationOptions
extends OperationOptions,
WriteConcernOptions,
ExplainOptions {
/** @deprecated This option does nothing */
fullResponse?: boolean;
/** Specify a read concern and level for the collection. (only MongoDB 3.2 or higher supported) */
readConcern?: ReadConcernLike;
/** Collation */
Expand Down
7 changes: 0 additions & 7 deletions src/operations/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ export interface DeleteOptions extends CommandOperationOptions, WriteConcernOpti
hint?: string | Document;
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
let?: Document;

/** @deprecated use `removeOne` or `removeMany` to implicitly specify the limit */
single?: boolean;
}

/** @public */
Expand Down Expand Up @@ -152,10 +149,6 @@ export function makeDeleteStatement(
limit: typeof options.limit === 'number' ? options.limit : 0
};

if (options.single === true) {
op.limit = 1;
}

if (options.collation) {
op.collation = options.collation;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sdam/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const stateTransition = makeStateMachine({
/** @internal */
const kMonitor = Symbol('monitor');

/** @public */
/** @internal */
export type ServerOptions = Omit<ConnectionPoolOptions, 'id' | 'generation' | 'hostAddress'> &
MonitorOptions;

Expand Down
2 changes: 1 addition & 1 deletion src/sdam/server_selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const SMALLEST_MAX_STALENESS_SECONDS = 90;
// Minimum version to try writes on secondaries.
export const MIN_SECONDARY_WRITE_WIRE_VERSION = 13;

/** @public */
/** @internal */
export type ServerSelector = (
topologyDescription: TopologyDescription,
servers: ServerDescription[]
Expand Down
2 changes: 1 addition & 1 deletion src/sdam/topology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export interface TopologyPrivate {
detectSrvRecords: (event: SrvPollingEvent) => void;
}

/** @public */
/** @internal */
export interface TopologyOptions extends BSONSerializeOptions, ServerOptions {
srvMaxHosts: number;
srvServiceName: string;
Expand Down
16 changes: 1 addition & 15 deletions test/integration/crud/crud_api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,21 +670,7 @@ describe('CRUD API', function () {
// Legacy update method
// -------------------------------------------------
const legacyRemove = function () {
db.collection('t4_1').insertMany(
[{ a: 1 }, { a: 1 }],
{ writeConcern: { w: 1 } },
function (err, r) {
expect(err).to.not.exist;
test.equal(2, r.insertedCount);

db.collection('t4_1').remove({ a: 1 }, { single: true }, function (err, r) {
expect(err).to.not.exist;
test.equal(1, r.deletedCount);

deleteOne();
});
}
);
deleteOne();
};

//
Expand Down
46 changes: 0 additions & 46 deletions test/integration/crud/remove.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,52 +107,6 @@ describe('Remove', function () {
}
});

it('should correctly remove only first document', {
metadata: {
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
},

test: function (done) {
const self = this;
const client = self.configuration.newClient(self.configuration.writeConcernMax(), {
maxPoolSize: 1
});

client.connect(function (err, client) {
const db = client.db(self.configuration.db);
expect(err).to.not.exist;

db.createCollection('shouldCorrectlyRemoveOnlyFirstDocument', function (err) {
expect(err).to.not.exist;

const collection = db.collection('shouldCorrectlyRemoveOnlyFirstDocument');

collection.insert(
[{ a: 1 }, { a: 1 }, { a: 1 }, { a: 1 }],
{ writeConcern: { w: 1 } },
function (err) {
expect(err).to.not.exist;

// Remove the first
collection.remove(
{ a: 1 },
{ writeConcern: { w: 1 }, single: true },
function (err, r) {
expect(r).property('deletedCount').to.equal(1);

collection.find({ a: 1 }).count(function (err, result) {
expect(result).to.equal(3);
client.close(done);
});
}
);
}
);
});
});
}
});

it('should not error on empty remove', {
metadata: {
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
Expand Down
2 changes: 1 addition & 1 deletion test/integration/node-specific/operation_example.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2541,7 +2541,7 @@ describe('Operation Examples', function () {
{ name: 'Sarah', title: 'Princess' },
{ name: 'Gump', title: 'Gump' }
],
{ writeConcern: { w: 1 }, keepGoing: true },
{ writeConcern: { w: 1 }, ordered: false },
function (err, result) {
expect(result).to.not.exist;
test.ok(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,7 @@ describe('Operation (Promises)', function () {
{ name: 'Sarah', title: 'Princess' },
{ name: 'Gump', title: 'Gump' }
],
{ writeConcern: { w: 1 }, keepGoing: true }
{ writeConcern: { w: 1 }, ordered: false }
);
})
.catch(function () {
Expand Down
Loading

0 comments on commit 8f8ea45

Please sign in to comment.