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-4547): mark all callback APIs as deprecated #3388

Merged
merged 7 commits into from Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
47 changes: 28 additions & 19 deletions src/admin.ts
Expand Up @@ -29,26 +29,15 @@ export interface AdminPrivate {
* @public
*
* @example
* ```js
* const MongoClient = require('mongodb').MongoClient;
* const test = require('assert');
* // Connection url
* const url = 'mongodb://localhost:27017';
* // Database Name
* const dbName = 'test';
* ```ts
* import { MongoClient } from 'mongodb';
*
* // Connect using MongoClient
* MongoClient.connect(url, function(err, client) {
* // Use the admin database for the operation
* const adminDb = client.db(dbName).admin();
*
* // List all the available databases
* adminDb.listDatabases(function(err, dbs) {
* expect(err).to.not.exist;
* test.ok(dbs.databases.length > 0);
* client.close();
* });
* });
* const client = new MongoClient('mongodb://localhost:27017');
* const admin = client.db().admin();
* const dbInfo = await admin.listDatabases();
baileympearson marked this conversation as resolved.
Show resolved Hide resolved
* for (const db of dbInfo.databases) {
* console.log(db.name);
* }
* ```
*/
export class Admin {
Expand All @@ -71,8 +60,10 @@ export class Admin {
* @param callback - An optional callback, a Promise will be returned if none is provided
*/
command(command: Document): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
command(command: Document, callback: Callback<Document>): void;
command(command: Document, options: RunCommandOptions): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
command(command: Document, options: RunCommandOptions, callback: Callback<Document>): void;
command(
command: Document,
Expand All @@ -96,8 +87,10 @@ export class Admin {
* @param callback - An optional callback, a Promise will be returned if none is provided
*/
buildInfo(): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
buildInfo(callback: Callback<Document>): void;
buildInfo(options: CommandOperationOptions): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
buildInfo(options: CommandOperationOptions, callback: Callback<Document>): void;
buildInfo(
options?: CommandOperationOptions | Callback<Document>,
Expand All @@ -115,8 +108,10 @@ export class Admin {
* @param callback - An optional callback, a Promise will be returned if none is provided
*/
serverInfo(): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
serverInfo(callback: Callback<Document>): void;
serverInfo(options: CommandOperationOptions): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
serverInfo(options: CommandOperationOptions, callback: Callback<Document>): void;
serverInfo(
options?: CommandOperationOptions | Callback<Document>,
Expand All @@ -134,8 +129,10 @@ export class Admin {
* @param callback - An optional callback, a Promise will be returned if none is provided
*/
serverStatus(): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
serverStatus(callback: Callback<Document>): void;
serverStatus(options: CommandOperationOptions): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
serverStatus(options: CommandOperationOptions, callback: Callback<Document>): void;
serverStatus(
options?: CommandOperationOptions | Callback<Document>,
Expand All @@ -153,8 +150,10 @@ export class Admin {
* @param callback - An optional callback, a Promise will be returned if none is provided
*/
ping(): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
ping(callback: Callback<Document>): void;
ping(options: CommandOperationOptions): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
ping(options: CommandOperationOptions, callback: Callback<Document>): void;
ping(
options?: CommandOperationOptions | Callback<Document>,
Expand All @@ -174,12 +173,16 @@ export class Admin {
* @param callback - An optional callback, a Promise will be returned if none is provided
*/
addUser(username: string): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
addUser(username: string, callback: Callback<Document>): void;
addUser(username: string, password: string): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
addUser(username: string, password: string, callback: Callback<Document>): void;
addUser(username: string, options: AddUserOptions): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
addUser(username: string, options: AddUserOptions, callback: Callback<Document>): void;
addUser(username: string, password: string, options: AddUserOptions): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
addUser(
username: string,
password: string,
Expand Down Expand Up @@ -247,8 +250,10 @@ export class Admin {
* @param callback - An optional callback, a Promise will be returned if none is provided
baileympearson marked this conversation as resolved.
Show resolved Hide resolved
*/
validateCollection(collectionName: string): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
validateCollection(collectionName: string, callback: Callback<Document>): void;
validateCollection(collectionName: string, options: ValidateCollectionOptions): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
validateCollection(
collectionName: string,
options: ValidateCollectionOptions,
Expand Down Expand Up @@ -276,8 +281,10 @@ export class Admin {
* @param callback - An optional callback, a Promise will be returned if none is provided
*/
listDatabases(): Promise<ListDatabasesResult>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
listDatabases(callback: Callback<ListDatabasesResult>): void;
listDatabases(options: ListDatabasesOptions): Promise<ListDatabasesResult>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
listDatabases(options: ListDatabasesOptions, callback: Callback<ListDatabasesResult>): void;
listDatabases(
options?: ListDatabasesOptions | Callback<ListDatabasesResult>,
Expand All @@ -300,8 +307,10 @@ export class Admin {
* @param callback - An optional callback, a Promise will be returned if none is provided
*/
replSetGetStatus(): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
replSetGetStatus(callback: Callback<Document>): void;
replSetGetStatus(options: CommandOperationOptions): Promise<Document>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
replSetGetStatus(options: CommandOperationOptions, callback: Callback<Document>): void;
replSetGetStatus(
options?: CommandOperationOptions | Callback<Document>,
Expand Down
6 changes: 4 additions & 2 deletions src/bulk/common.ts
Expand Up @@ -1065,7 +1065,7 @@ export abstract class BulkOperationBase {
* Add a single insert document to the bulk operation
*
* @example
* ```js
* ```ts
* const bulkOp = collection.initializeOrderedBulkOp();
*
* // Adds three inserts to the bulkOp.
Expand All @@ -1089,7 +1089,7 @@ export abstract class BulkOperationBase {
* Returns a builder object used to complete the definition of the operation.
*
* @example
* ```js
* ```ts
* const bulkOp = collection.initializeOrderedBulkOp();
*
* // Add an updateOne to the bulkOp
Expand Down Expand Up @@ -1247,7 +1247,9 @@ export abstract class BulkOperationBase {
}

execute(options?: BulkWriteOptions): Promise<BulkWriteResult>;
baileympearson marked this conversation as resolved.
Show resolved Hide resolved
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
execute(callback: Callback<BulkWriteResult>): void;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
execute(options: BulkWriteOptions | undefined, callback: Callback<BulkWriteResult>): void;
execute(
options?: BulkWriteOptions | Callback<BulkWriteResult>,
Expand Down
3 changes: 3 additions & 0 deletions src/change_stream.ts
Expand Up @@ -645,6 +645,7 @@ export class ChangeStream<

/** Check if there is any document still available in the Change Stream */
hasNext(): Promise<boolean>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
hasNext(callback: Callback<boolean>): void;
hasNext(callback?: Callback): Promise<boolean> | void {
this._setIsIterator();
Expand Down Expand Up @@ -675,6 +676,7 @@ export class ChangeStream<

/** Get the next available document from the Change Stream. */
next(): Promise<TChange>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
next(callback: Callback<TChange>): void;
next(callback?: Callback<TChange>): Promise<TChange> | void {
this._setIsIterator();
Expand Down Expand Up @@ -709,6 +711,7 @@ export class ChangeStream<
* Try to get the next available document from the Change Stream's cursor or `null` if an empty batch is returned
*/
tryNext(): Promise<Document | null>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version */
tryNext(callback: Callback<Document | null>): void;
tryNext(callback?: Callback<Document | null>): Promise<Document | null> | void {
this._setIsIterator();
Expand Down