Skip to content

Commit

Permalink
feat(NODE-5432)!: remove addUser and collection.stats
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Jul 21, 2023
1 parent fbb2db2 commit 039bd01
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 410 deletions.
51 changes: 3 additions & 48 deletions mongodb-legacy.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
// Dependencies (options, etc.)
import type {
AbstractCursorEvents,
AddUserOptions,
AggregateOptions,
AnyBulkWriteOperation,
BulkWriteOptions,
Expand All @@ -31,8 +30,6 @@ import type {
ClientSessionOptions,
CollectionInfo,
CollectionOptions,
CollStats,
CollStatsOptions,
CommandOperationOptions,
CountDocumentsOptions,
CountOptions,
Expand Down Expand Up @@ -93,10 +90,10 @@ import type {
type NonConstructorKeys<T> = { [P in keyof T]: T[P] extends new () => any ? never : P }[keyof T];
type NonConstructor<T> = Pick<T, NonConstructorKeys<T>>;

declare const Admin: new () => Omit<MDBAdmin, 'addUser' | 'buildInfo' | 'command' | 'listDatabases' | 'ping' | 'removeUser' | 'replSetGetStatus' | 'serverInfo' | 'serverStatus' | 'validateCollection'>;
declare const Admin: new () => Omit<MDBAdmin, 'buildInfo' | 'command' | 'listDatabases' | 'ping' | 'removeUser' | 'replSetGetStatus' | 'serverInfo' | 'serverStatus' | 'validateCollection'>;
declare const ChangeStream: new <TSchema extends Document = Document, TChange extends Document = ChangeStreamDocument<TSchema>>() => Omit<MDBChangeStream<TSchema, TChange>, 'close' | 'hasNext' | 'next' | 'tryNext'>;
declare const Collection: new <TSchema>() => Omit<MDBCollection<TSchema>, 'initializeUnorderedBulkOp' | 'initializeOrderedBulkOp' | 'bulkWrite'| 'count'| 'countDocuments'| 'estimatedDocumentCount'| 'createIndex'| 'createIndexes'| 'dropIndex'| 'dropIndexes'| 'deleteMany'| 'deleteOne'| 'distinct'| 'drop'| 'findOne'| 'findOneAndDelete'| 'findOneAndReplace'| 'findOneAndUpdate'| 'indexExists'| 'indexInformation'| 'indexes'| 'insertMany'| 'insertOne'| 'isCapped'| 'options'| 'rename'| 'replaceOne'| 'stats'| 'updateMany'| 'updateOne'| 'aggregate'| 'find'| 'listIndexes'| 'watch'>;
declare const Db: new () => Omit<MDBDb, 'command' | 'addUser' | 'removeUser' | 'createCollection' | 'dropCollection' | 'createIndex' | 'dropDatabase' | 'indexInformation' | 'profilingLevel' | 'setProfilingLevel' | 'renameCollection' | 'stats' | 'collections' | 'collection' | 'admin' | 'aggregate' | 'listCollections' | 'watch'>;
declare const Collection: new <TSchema>() => Omit<MDBCollection<TSchema>, 'initializeUnorderedBulkOp' | 'initializeOrderedBulkOp' | 'bulkWrite'| 'count'| 'countDocuments'| 'estimatedDocumentCount'| 'createIndex'| 'createIndexes'| 'dropIndex'| 'dropIndexes'| 'deleteMany'| 'deleteOne'| 'distinct'| 'drop'| 'findOne'| 'findOneAndDelete'| 'findOneAndReplace'| 'findOneAndUpdate'| 'indexExists'| 'indexInformation'| 'indexes'| 'insertMany'| 'insertOne'| 'isCapped'| 'options'| 'rename'| 'replaceOne'| 'updateMany'| 'updateOne'| 'aggregate'| 'find'| 'listIndexes'| 'watch'>;
declare const Db: new () => Omit<MDBDb, 'command' | 'removeUser' | 'createCollection' | 'dropCollection' | 'createIndex' | 'dropDatabase' | 'indexInformation' | 'profilingLevel' | 'setProfilingLevel' | 'renameCollection' | 'stats' | 'collections' | 'collection' | 'admin' | 'aggregate' | 'listCollections' | 'watch'>;
declare const GridFSBucket: new (db: LegacyDb, options: GridFSBucketOptions) => Omit<NonConstructor<MDBGridFSBucket>, 'delete' | 'rename' | 'drop' | 'find'>;
declare const MongoClient: new (url: string, options?: MongoClientOptions) => Omit<NonConstructor<MDBMongoClient>, 'connect' | 'close' | 'db' | 'watch' | 'withSession' | 'startSession'>;
declare const ClientSession: new () => Omit<MDBClientSession, 'endSession' | 'abortTransaction' | 'commitTransaction' | 'withTransaction'>
Expand Down Expand Up @@ -156,22 +153,6 @@ declare class LegacyAdmin extends Admin {
ping(callback: Callback<Document>): void;
ping(options: CommandOperationOptions): Promise<Document>;
ping(options: CommandOperationOptions, callback: Callback<Document>): void;
/**
* Add a user to the database
*
* @param username - The username for the new user
* @param password - An optional password for the new user
* @param options - Optional settings for the command
* @param callback - An optional callback, a Promise will be returned if none is provided
*/
addUser(username: string): Promise<Document>;
addUser(username: string, callback: Callback<Document>): void;
addUser(username: string, password: string): Promise<Document>;
addUser(username: string, password: string, callback: Callback<Document>): void;
addUser(username: string, options: AddUserOptions): Promise<Document>;
addUser(username: string, options: AddUserOptions, callback: Callback<Document>): void;
addUser(username: string, password: string, options: AddUserOptions): Promise<Document>;
addUser(username: string, password: string, options: AddUserOptions, callback: Callback<Document>): void;
/**
* Remove a user from a database
*
Expand Down Expand Up @@ -637,16 +618,6 @@ declare class LegacyCollection<TSchema extends Document = Document> extends Coll
indexes(callback: Callback<Document[]>): void;
indexes(options: IndexInformationOptions): Promise<Document[]>;
indexes(options: IndexInformationOptions, callback: Callback<Document[]>): void;
/**
* Get all the collection statistics.
*
* @param options - Optional settings for the command
* @param callback - An optional callback, a Promise will be returned if none is provided
*/
stats(): Promise<CollStats>;
stats(callback: Callback<CollStats>): void;
stats(options: CollStatsOptions): Promise<CollStats>;
stats(options: CollStatsOptions, callback: Callback<CollStats>): void;
/**
* Find a document and delete it in one atomic operation. Requires a write lock for the duration of the operation.
*
Expand Down Expand Up @@ -868,22 +839,6 @@ declare class LegacyDb extends Db {
createIndex(name: string, indexSpec: IndexSpecification, callback?: Callback<string>): void;
createIndex(name: string, indexSpec: IndexSpecification, options: CreateIndexesOptions): Promise<string>;
createIndex(name: string, indexSpec: IndexSpecification, options: CreateIndexesOptions, callback: Callback<string>): void;
/**
* Add a user to the database
*
* @param username - The username for the new user
* @param password - An optional password for the new user
* @param options - Optional settings for the command
* @param callback - An optional callback, a Promise will be returned if none is provided
*/
addUser(username: string): Promise<Document>;
addUser(username: string, callback: Callback<Document>): void;
addUser(username: string, password: string): Promise<Document>;
addUser(username: string, password: string, callback: Callback<Document>): void;
addUser(username: string, options: AddUserOptions): Promise<Document>;
addUser(username: string, options: AddUserOptions, callback: Callback<Document>): void;
addUser(username: string, password: string, options: AddUserOptions): Promise<Document>;
addUser(username: string, password: string, options: AddUserOptions, callback: Callback<Document>): void;
/**
* Remove a user from a database
*
Expand Down
19 changes: 0 additions & 19 deletions src/legacy_wrappers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,6 @@ Object.defineProperty(module.exports, '__esModule', { value: true });

module.exports.makeLegacyAdmin = function (baseClass) {
class LegacyAdmin extends baseClass {
addUser(username, password, options, callback) {
callback =
typeof callback === 'function'
? callback
: typeof options === 'function'
? options
: typeof password === 'function'
? password
: undefined;
options =
options != null && typeof options === 'object'
? options
: password != null && typeof password === 'object'
? password
: undefined;
password = typeof password === 'string' ? password : undefined;
return maybeCallback(super.addUser(username, password, options), callback);
}

buildInfo(options, callback) {
callback =
typeof callback === 'function'
Expand Down
11 changes: 0 additions & 11 deletions src/legacy_wrappers/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,6 @@ module.exports.makeLegacyCollection = function (baseClass) {
return maybeCallback(super.replaceOne(filter, replacement, options), callback);
}

stats(options, callback) {
callback =
typeof callback === 'function'
? callback
: typeof options === 'function'
? options
: undefined;
options = typeof options !== 'function' ? options : undefined;
return maybeCallback(super.stats(options), callback);
}

updateMany(filter, update, options, callback) {
callback =
typeof callback === 'function'
Expand Down
20 changes: 0 additions & 20 deletions src/legacy_wrappers/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,6 @@ module.exports.makeLegacyDb = function (baseClass) {
return maybeCallback(super.command(command, options), callback);
}

// Async APIs
addUser(username, password, options, callback) {
callback =
typeof callback === 'function'
? callback
: typeof options === 'function'
? options
: typeof password === 'function'
? password
: undefined;
options =
options != null && typeof options === 'object'
? options
: password != null && typeof password === 'object'
? password
: undefined;
password = typeof password === 'string' ? password : undefined;
return maybeCallback(super.addUser(username, password, options), callback);
}

removeUser(username, options, callback) {
callback =
typeof callback === 'function'
Expand Down
3 changes: 0 additions & 3 deletions test/tools/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const api = [
// Super class of cursors, we do not directly override these but override them in the inherited classes
...commonCursorApis.flatMap(({ method, returnType, possibleCallbackPositions }) => cursorClasses.map(cursorClass => ({ className: cursorClass, method, returnType, possibleCallbackPositions }))),

{ className: 'Admin', method: 'addUser', returnType: 'Promise<Document>', special: 'addUser takes 4 arguments: [username, password, options, callback] the last 3 are optional, unlike other functions with this length password needs to be filtered to only be a string, this is the only case where we make a decision to pass an argument based on its type (instead of what type it is not)' },
{ className: 'Admin', method: 'buildInfo', returnType: 'Promise<Document>' },
{ className: 'Admin', method: 'command', returnType: 'Promise<Document>' },
{ className: 'Admin', method: 'listDatabases', returnType: 'Promise<ListDatabasesResult>' },
Expand Down Expand Up @@ -88,7 +87,6 @@ const api = [
{ className: 'Collection', method: 'options', returnType: 'Promise<Document>' },
{ className: 'Collection', method: 'rename', returnType: 'Promise<Collection>', changesPromise: true },
{ className: 'Collection', method: 'replaceOne', returnType: 'Promise<UpdateResult | Document>' },
{ className: 'Collection', method: 'stats', returnType: 'Promise<CollStats>' },
{ className: 'Collection', method: 'updateMany', returnType: 'Promise<UpdateResult | Document>' },
{ className: 'Collection', method: 'updateOne', returnType: 'Promise<UpdateResult>' },
{ className: 'Collection', method: 'initializeOrderedBulkOp', returnType: 'OrderedBulkOperation', notAsync: true },
Expand All @@ -98,7 +96,6 @@ const api = [
{ className: 'Collection', method: 'listIndexes', returnType: 'ListIndexesCursor', notAsync: true },
{ className: 'Collection', method: 'watch', returnType: 'ChangeStream', notAsync: true },

{ className: 'Db', method: 'addUser', returnType: 'Promise<Document>', special: 'see Admin.addUser' },
{ className: 'Db', method: 'collections', returnType: 'Promise<Collection[]>', changesPromise: true },
{ className: 'Db', method: 'command', returnType: 'Promise<Document>' },
{ className: 'Db', method: 'createCollection', returnType: 'Promise<Collection<TSchema>>', changesPromise: true },
Expand Down
163 changes: 0 additions & 163 deletions test/unit/legacy_wrappers/admin.test.js

This file was deleted.

Loading

0 comments on commit 039bd01

Please sign in to comment.