diff --git a/src/index.ts b/src/index.ts index 9e94d18dca7..cbe08602526 100644 --- a/src/index.ts +++ b/src/index.ts @@ -389,7 +389,6 @@ export type { CommandOperationOptions, OperationParent } from './operations/command'; -export type { CommandCallbackOperation } from './operations/command'; export type { IndexInformationOptions } from './operations/common_functions'; export type { CountOptions } from './operations/count'; export type { CountDocumentsOptions } from './operations/count_documents'; @@ -421,12 +420,7 @@ export type { export type { InsertManyResult, InsertOneOptions, InsertOneResult } from './operations/insert'; export type { CollectionInfo, ListCollectionsOptions } from './operations/list_collections'; export type { ListDatabasesOptions, ListDatabasesResult } from './operations/list_databases'; -export type { - AbstractCallbackOperation, - AbstractOperation, - Hint, - OperationOptions -} from './operations/operation'; +export type { AbstractOperation, Hint, OperationOptions } from './operations/operation'; export type { ProfilingLevelOptions } from './operations/profiling_level'; export type { RemoveUserOptions } from './operations/remove_user'; export type { RenameOptions } from './operations/rename'; diff --git a/src/operations/aggregate.ts b/src/operations/aggregate.ts index 868dac6e1c1..313bd37f39e 100644 --- a/src/operations/aggregate.ts +++ b/src/operations/aggregate.ts @@ -3,7 +3,7 @@ import { MongoInvalidArgumentError } from '../error'; import { type TODO_NODE_3286 } from '../mongo_types'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import { type Callback, maxWireVersion, type MongoDBNamespace } from '../utils'; +import { maxWireVersion, type MongoDBNamespace } from '../utils'; import { WriteConcern } from '../write_concern'; import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command'; import { Aspect, defineAspects, type Hint } from './operation'; @@ -132,14 +132,6 @@ export class AggregateOperation extends CommandOperation { return super.executeCommand(server, session, command) as TODO_NODE_3286; } - - protected override executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } defineAspects(AggregateOperation, [ diff --git a/src/operations/collections.ts b/src/operations/collections.ts index e7991357369..9a8cdf0e58a 100644 --- a/src/operations/collections.ts +++ b/src/operations/collections.ts @@ -19,7 +19,10 @@ export class CollectionsOperation extends AbstractOperation { this.db = db; } - async execute(server: Server, session: ClientSession | undefined): Promise { + override async execute( + server: Server, + session: ClientSession | undefined + ): Promise { // Let's get the collection names const documents = await this.db .listCollections( diff --git a/src/operations/command.ts b/src/operations/command.ts index f6ec6cbe021..4cff77eb174 100644 --- a/src/operations/command.ts +++ b/src/operations/command.ts @@ -7,7 +7,6 @@ import type { Server } from '../sdam/server'; import { MIN_SECONDARY_WRITE_WIRE_VERSION } from '../sdam/server_selection'; import type { ClientSession } from '../sessions'; import { - type Callback, commandSupportsReadConcern, decorateWithExplain, maxWireVersion, @@ -15,7 +14,7 @@ import { } from '../utils'; import { WriteConcern, type WriteConcernOptions } from '../write_concern'; import type { ReadConcernLike } from './../read_concern'; -import { AbstractCallbackOperation, Aspect, type OperationOptions } from './operation'; +import { AbstractOperation, Aspect, type OperationOptions } from './operation'; /** @public */ export interface CollationOptions { @@ -68,7 +67,7 @@ export interface OperationParent { } /** @internal */ -export abstract class CommandOperation extends AbstractCallbackOperation { +export abstract class CommandOperation extends AbstractOperation { override options: CommandOperationOptions; readConcern?: ReadConcern; writeConcern?: WriteConcern; @@ -156,22 +155,3 @@ export abstract class CommandOperation extends AbstractCallbackOperation { return server.commandAsync(this.ns, cmd, options); } } - -/** @internal */ -export abstract class CommandCallbackOperation extends CommandOperation { - constructor(parent?: OperationParent, options?: CommandOperationOptions) { - super(parent, options); - } - - executeCommandCallback( - server: Server, - session: ClientSession | undefined, - cmd: Document, - callback: Callback - ): void { - super.executeCommand(server, session, cmd).then( - res => callback(undefined, res), - err => callback(err, undefined) - ); - } -} diff --git a/src/operations/count.ts b/src/operations/count.ts index 736a69d9bda..f9ad49f0dcc 100644 --- a/src/operations/count.ts +++ b/src/operations/count.ts @@ -2,7 +2,7 @@ import type { Document } from '../bson'; import type { Collection } from '../collection'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import type { Callback, MongoDBNamespace } from '../utils'; +import type { MongoDBNamespace } from '../utils'; import { CommandOperation, type CommandOperationOptions } from './command'; import { Aspect, defineAspects } from './operation'; @@ -58,14 +58,6 @@ export class CountOperation extends CommandOperation { const result = await super.executeCommand(server, session, cmd); return result ? result.n : 0; } - - protected override executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } defineAspects(CountOperation, [Aspect.READ_OPERATION, Aspect.RETRYABLE]); diff --git a/src/operations/create_collection.ts b/src/operations/create_collection.ts index 0f59041df13..6ea988b8f9a 100644 --- a/src/operations/create_collection.ts +++ b/src/operations/create_collection.ts @@ -9,7 +9,6 @@ import { MongoCompatibilityError } from '../error'; import type { PkFactory } from '../mongo_client'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import { type Callback } from '../utils'; import { CommandOperation, type CommandOperationOptions } from './command'; import { CreateIndexOperation } from './indexes'; import { Aspect, defineAspects } from './operation'; @@ -171,14 +170,6 @@ export class CreateCollectionOperation extends CommandOperation { return coll; } - protected executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } - private async executeWithoutEncryptedFieldsCheck( server: Server, session: ClientSession | undefined diff --git a/src/operations/delete.ts b/src/operations/delete.ts index fde22924b20..dc4d0bc13eb 100644 --- a/src/operations/delete.ts +++ b/src/operations/delete.ts @@ -4,7 +4,7 @@ import { MongoCompatibilityError, MongoServerError } from '../error'; import { type TODO_NODE_3286 } from '../mongo_types'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import type { Callback, MongoDBNamespace } from '../utils'; +import type { MongoDBNamespace } from '../utils'; import type { WriteConcernOptions } from '../write_concern'; import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command'; import { Aspect, defineAspects, type Hint } from './operation'; @@ -93,14 +93,6 @@ export class DeleteOperation extends CommandOperation { return super.executeCommand(server, session, command) as TODO_NODE_3286; } - - protected override executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } export class DeleteOneOperation extends DeleteOperation { diff --git a/src/operations/distinct.ts b/src/operations/distinct.ts index fae192e4354..900abd6afa2 100644 --- a/src/operations/distinct.ts +++ b/src/operations/distinct.ts @@ -2,7 +2,7 @@ import type { Document } from '../bson'; import type { Collection } from '../collection'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import { type Callback, decorateWithCollation, decorateWithReadConcern } from '../utils'; +import { decorateWithCollation, decorateWithReadConcern } from '../utils'; import { CommandOperation, type CommandOperationOptions } from './command'; import { Aspect, defineAspects } from './operation'; @@ -72,14 +72,6 @@ export class DistinctOperation extends CommandOperation { return this.explain ? result : result.values; } - - protected override executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } defineAspects(DistinctOperation, [Aspect.READ_OPERATION, Aspect.RETRYABLE, Aspect.EXPLAINABLE]); diff --git a/src/operations/drop.ts b/src/operations/drop.ts index 1dcaa490eaf..dbbfa7fea04 100644 --- a/src/operations/drop.ts +++ b/src/operations/drop.ts @@ -3,7 +3,6 @@ import type { Db } from '../db'; import { MONGODB_ERROR_CODES, MongoServerError } from '../error'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import { type Callback } from '../utils'; import { CommandOperation, type CommandOperationOptions } from './command'; import { Aspect, defineAspects } from './operation'; @@ -69,14 +68,6 @@ export class DropCollectionOperation extends CommandOperation { return this.executeWithoutEncryptedFieldsCheck(server, session); } - protected executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } - private async executeWithoutEncryptedFieldsCheck( server: Server, session: ClientSession | undefined @@ -101,14 +92,6 @@ export class DropDatabaseOperation extends CommandOperation { await super.executeCommand(server, session, { dropDatabase: 1 }); return true; } - - protected executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } defineAspects(DropCollectionOperation, [Aspect.WRITE_OPERATION]); diff --git a/src/operations/estimated_document_count.ts b/src/operations/estimated_document_count.ts index 3b023639523..44e70bbaef0 100644 --- a/src/operations/estimated_document_count.ts +++ b/src/operations/estimated_document_count.ts @@ -2,7 +2,6 @@ import type { Document } from '../bson'; import type { Collection } from '../collection'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import type { Callback } from '../utils'; import { CommandOperation, type CommandOperationOptions } from './command'; import { Aspect, defineAspects } from './operation'; @@ -44,14 +43,6 @@ export class EstimatedDocumentCountOperation extends CommandOperation { return response?.n || 0; } - - protected override executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } defineAspects(EstimatedDocumentCountOperation, [ diff --git a/src/operations/eval.ts b/src/operations/eval.ts index a32a618891f..3f7699e067c 100644 --- a/src/operations/eval.ts +++ b/src/operations/eval.ts @@ -5,8 +5,7 @@ import { MongoServerError } from '../error'; import { ReadPreference } from '../read_preference'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import type { Callback } from '../utils'; -import { CommandCallbackOperation, type CommandOperationOptions } from './command'; +import { CommandOperation, type CommandOperationOptions } from './command'; /** @public */ export interface EvalOptions extends CommandOperationOptions { @@ -14,7 +13,7 @@ export interface EvalOptions extends CommandOperationOptions { } /** @internal */ -export class EvalOperation extends CommandCallbackOperation { +export class EvalOperation extends CommandOperation { override options: EvalOptions; code: Code; parameters?: Document | Document[]; @@ -38,11 +37,7 @@ export class EvalOperation extends CommandCallbackOperation { }); } - override executeCallback( - server: Server, - session: ClientSession | undefined, - callback: Callback - ): void { + override async execute(server: Server, session: ClientSession | undefined): Promise { let finalCode = this.code; let finalParameters: Document[] = []; @@ -65,18 +60,15 @@ export class EvalOperation extends CommandCallbackOperation { } // Execute the command - super.executeCommandCallback(server, session, cmd, (err, result) => { - if (err) return callback(err); - if (result && result.ok === 1) { - return callback(undefined, result.retval); - } + const result = await super.executeCommand(server, session, cmd); + if (result && result.ok === 1) { + return result.retval; + } - if (result) { - callback(new MongoServerError({ message: `eval failed: ${result.errmsg}` })); - return; - } + if (result) { + throw new MongoServerError({ message: `eval failed: ${result.errmsg}` }); + } - callback(err, result); - }); + return result; } } diff --git a/src/operations/find.ts b/src/operations/find.ts index 731c661c29e..278cead138c 100644 --- a/src/operations/find.ts +++ b/src/operations/find.ts @@ -5,12 +5,7 @@ import { ReadConcern } from '../read_concern'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; import { formatSort, type Sort } from '../sort'; -import { - type Callback, - decorateWithExplain, - type MongoDBNamespace, - normalizeHintField -} from '../utils'; +import { decorateWithExplain, type MongoDBNamespace, normalizeHintField } from '../utils'; import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command'; import { Aspect, defineAspects, type Hint } from './operation'; @@ -119,14 +114,6 @@ export class FindOperation extends CommandOperation { session }); } - - protected executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } function makeFindCommand(ns: MongoDBNamespace, filter: Document, options: FindOptions): Document { diff --git a/src/operations/find_and_modify.ts b/src/operations/find_and_modify.ts index b49f02b9fbe..2d97ffb23e2 100644 --- a/src/operations/find_and_modify.ts +++ b/src/operations/find_and_modify.ts @@ -5,7 +5,7 @@ import { ReadPreference } from '../read_preference'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; import { formatSort, type Sort, type SortForCmd } from '../sort'; -import { type Callback, decorateWithCollation, hasAtomicOperators, maxWireVersion } from '../utils'; +import { decorateWithCollation, hasAtomicOperators, maxWireVersion } from '../utils'; import type { WriteConcern, WriteConcernSettings } from '../write_concern'; import { CommandOperation, type CommandOperationOptions } from './command'; import { Aspect, defineAspects } from './operation'; @@ -215,14 +215,6 @@ class FindAndModifyOperation extends CommandOperation { const result = await super.executeCommand(server, session, cmd); return options.includeResultMetadata ? result : result.value ?? null; } - - protected override executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } /** @internal */ diff --git a/src/operations/get_more.ts b/src/operations/get_more.ts index e2e6f86f32a..0a3693d57b9 100644 --- a/src/operations/get_more.ts +++ b/src/operations/get_more.ts @@ -52,7 +52,7 @@ export class GetMoreOperation extends AbstractOperation { * Although there is a server already associated with the get more operation, the signature * for execute passes a server so we will just use that one. */ - async execute(server: Server, _session: ClientSession | undefined): Promise { + override async execute(server: Server, _session: ClientSession | undefined): Promise { if (server !== this.server) { throw new MongoRuntimeError('Getmore must run on the same server operation began on'); } diff --git a/src/operations/indexes.ts b/src/operations/indexes.ts index 69f998fd130..b147b67cbed 100644 --- a/src/operations/indexes.ts +++ b/src/operations/indexes.ts @@ -6,7 +6,7 @@ import { type OneOrMore } from '../mongo_types'; import { ReadPreference } from '../read_preference'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import { type Callback, isObject, maxWireVersion, type MongoDBNamespace } from '../utils'; +import { isObject, maxWireVersion, type MongoDBNamespace } from '../utils'; import { type CollationOptions, CommandOperation, @@ -186,7 +186,7 @@ export class IndexesOperation extends AbstractOperation { this.collection = collection; } - override execute(_server: Server, session: ClientSession | undefined): Promise { + override async execute(_server: Server, session: ClientSession | undefined): Promise { const coll = this.collection; const options = this.options; @@ -260,14 +260,6 @@ export class CreateIndexesOperation< const indexNames = indexes.map(index => index.name || ''); return indexNames as T; } - - protected executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } /** @internal */ @@ -340,14 +332,6 @@ export class DropIndexOperation extends CommandOperation { const cmd = { dropIndexes: this.collection.collectionName, index: this.indexName }; return super.executeCommand(server, session, cmd); } - - protected executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } /** @public */ @@ -391,14 +375,6 @@ export class ListIndexesOperation extends CommandOperation { return super.executeCommand(server, session, command); } - - protected executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } /** @internal */ @@ -447,7 +423,7 @@ export class IndexInformationOperation extends AbstractOperation { this.name = name; } - override execute(server: Server, session: ClientSession | undefined): Promise { + override async execute(server: Server, session: ClientSession | undefined): Promise { const db = this.db; const name = this.name; diff --git a/src/operations/insert.ts b/src/operations/insert.ts index 2f0710be1f1..8a63ad4f4dd 100644 --- a/src/operations/insert.ts +++ b/src/operations/insert.ts @@ -5,7 +5,7 @@ import { MongoInvalidArgumentError, MongoServerError } from '../error'; import type { InferIdType } from '../mongo_types'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import type { Callback, MongoDBNamespace } from '../utils'; +import type { MongoDBNamespace } from '../utils'; import { WriteConcern } from '../write_concern'; import { BulkWriteOperation } from './bulk_write'; import { CommandOperation, type CommandOperationOptions } from './command'; @@ -45,14 +45,6 @@ export class InsertOperation extends CommandOperation { return super.executeCommand(server, session, command); } - - protected override executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } /** @public */ diff --git a/src/operations/kill_cursors.ts b/src/operations/kill_cursors.ts index 34f2d2211f1..b9085464569 100644 --- a/src/operations/kill_cursors.ts +++ b/src/operations/kill_cursors.ts @@ -25,7 +25,7 @@ export class KillCursorsOperation extends AbstractOperation { this.server = server; } - async execute(server: Server, session: ClientSession | undefined): Promise { + override async execute(server: Server, session: ClientSession | undefined): Promise { if (server !== this.server) { throw new MongoRuntimeError('Killcursor must run on the same server operation began on'); } diff --git a/src/operations/list_collections.ts b/src/operations/list_collections.ts index 871fd6c7687..4947ca7862f 100644 --- a/src/operations/list_collections.ts +++ b/src/operations/list_collections.ts @@ -2,7 +2,7 @@ import type { Binary, Document } from '../bson'; import type { Db } from '../db'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import { type Callback, maxWireVersion } from '../utils'; +import { maxWireVersion } from '../utils'; import { CommandOperation, type CommandOperationOptions } from './command'; import { Aspect, defineAspects } from './operation'; @@ -51,14 +51,6 @@ export class ListCollectionsOperation extends CommandOperation { return super.executeCommand(server, session, this.generateCommand(maxWireVersion(server))); } - protected executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } - /* This is here for the purpose of unit testing the final command that gets sent. */ generateCommand(wireVersion: number): Document { const command: Document = { diff --git a/src/operations/list_databases.ts b/src/operations/list_databases.ts index b6c62882237..f51da41bd27 100644 --- a/src/operations/list_databases.ts +++ b/src/operations/list_databases.ts @@ -3,7 +3,7 @@ import type { Db } from '../db'; import { type TODO_NODE_3286 } from '../mongo_types'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import { type Callback, maxWireVersion, MongoDBNamespace } from '../utils'; +import { maxWireVersion, MongoDBNamespace } from '../utils'; import { CommandOperation, type CommandOperationOptions } from './command'; import { Aspect, defineAspects } from './operation'; @@ -61,14 +61,6 @@ export class ListDatabasesOperation extends CommandOperation - ): void { - throw new Error('Method not implemented.'); - } } defineAspects(ListDatabasesOperation, [Aspect.READ_OPERATION, Aspect.RETRYABLE]); diff --git a/src/operations/operation.ts b/src/operations/operation.ts index 7a86f392a1e..40722b4ec99 100644 --- a/src/operations/operation.ts +++ b/src/operations/operation.ts @@ -1,10 +1,8 @@ -import { promisify } from 'util'; - import { type BSONSerializeOptions, type Document, resolveBSONOptions } from '../bson'; import { ReadPreference, type ReadPreferenceLike } from '../read_preference'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import type { Callback, MongoDBNamespace } from '../utils'; +import type { MongoDBNamespace } from '../utils'; export const Aspect = { READ_OPERATION: Symbol('READ_OPERATION'), @@ -104,25 +102,6 @@ export abstract class AbstractOperation { } } -/** @internal */ -export abstract class AbstractCallbackOperation extends AbstractOperation { - constructor(options: OperationOptions = {}) { - super(options); - } - - execute(server: Server, session: ClientSession | undefined): Promise { - return promisify((callback: (e: Error, r: TResult) => void) => { - this.executeCallback(server, session, callback as any); - })(); - } - - protected abstract executeCallback( - server: Server, - session: ClientSession | undefined, - callback: Callback - ): void; -} - export function defineAspects( operation: OperationConstructor, aspects: symbol | symbol[] | Set diff --git a/src/operations/profiling_level.ts b/src/operations/profiling_level.ts index ed9eeb11d01..f96f0303764 100644 --- a/src/operations/profiling_level.ts +++ b/src/operations/profiling_level.ts @@ -2,7 +2,6 @@ import type { Db } from '../db'; import { MongoUnexpectedServerResponseError } from '../error'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import { type Callback } from '../utils'; import { CommandOperation, type CommandOperationOptions } from './command'; /** @public */ @@ -29,12 +28,4 @@ export class ProfilingLevelOperation extends CommandOperation { throw new MongoUnexpectedServerResponseError('Error with profile command'); } } - - protected executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } diff --git a/src/operations/remove_user.ts b/src/operations/remove_user.ts index c6db9b71590..042c9925e01 100644 --- a/src/operations/remove_user.ts +++ b/src/operations/remove_user.ts @@ -1,7 +1,6 @@ import type { Db } from '../db'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import { type Callback } from '../utils'; import { CommandOperation, type CommandOperationOptions } from './command'; import { Aspect, defineAspects } from './operation'; @@ -23,14 +22,6 @@ export class RemoveUserOperation extends CommandOperation { await super.executeCommand(server, session, { dropUser: this.username }); return true; } - - protected executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } defineAspects(RemoveUserOperation, [Aspect.WRITE_OPERATION]); diff --git a/src/operations/rename.ts b/src/operations/rename.ts index d0de350e61a..e3702598992 100644 --- a/src/operations/rename.ts +++ b/src/operations/rename.ts @@ -42,10 +42,6 @@ export class RenameOperation extends CommandOperation { await super.executeCommand(server, session, command); return new Collection(this.collection.s.db, this.newName, this.collection.s.options); } - - protected executeCallback(_server: any, _session: any, _callback: any): void { - throw new Error('Method not implemented.'); - } } defineAspects(RenameOperation, [Aspect.WRITE_OPERATION]); diff --git a/src/operations/set_profiling_level.ts b/src/operations/set_profiling_level.ts index 56bf473c5ef..9c738f20571 100644 --- a/src/operations/set_profiling_level.ts +++ b/src/operations/set_profiling_level.ts @@ -2,7 +2,7 @@ import type { Db } from '../db'; import { MongoInvalidArgumentError } from '../error'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import { type Callback, enumToString } from '../utils'; +import { enumToString } from '../utils'; import { CommandOperation, type CommandOperationOptions } from './command'; const levelValues = new Set(['off', 'slow_only', 'all']); @@ -63,12 +63,4 @@ export class SetProfilingLevelOperation extends CommandOperation await super.executeCommand(server, session, { profile: this.profile }); return level; } - - protected executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } diff --git a/src/operations/stats.ts b/src/operations/stats.ts index d538460582f..4717e3eb38b 100644 --- a/src/operations/stats.ts +++ b/src/operations/stats.ts @@ -2,7 +2,6 @@ import type { Document } from '../bson'; import type { Db } from '../db'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import type { Callback } from '../utils'; import { CommandOperation, type CommandOperationOptions } from './command'; import { Aspect, defineAspects } from './operation'; @@ -29,14 +28,6 @@ export class DbStatsOperation extends CommandOperation { return super.executeCommand(server, session, command); } - - protected executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } defineAspects(DbStatsOperation, [Aspect.READ_OPERATION]); diff --git a/src/operations/update.ts b/src/operations/update.ts index e58b5c95202..fc03424cbc8 100644 --- a/src/operations/update.ts +++ b/src/operations/update.ts @@ -4,7 +4,7 @@ import { MongoCompatibilityError, MongoInvalidArgumentError, MongoServerError } import type { InferIdType, TODO_NODE_3286 } from '../mongo_types'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import { type Callback, hasAtomicOperators, type MongoDBNamespace } from '../utils'; +import { hasAtomicOperators, type MongoDBNamespace } from '../utils'; import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command'; import { Aspect, defineAspects, type Hint } from './operation'; @@ -120,14 +120,6 @@ export class UpdateOperation extends CommandOperation { return super.executeCommand(server, session, command); } - - protected override executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } /** @internal */ diff --git a/src/operations/validate_collection.ts b/src/operations/validate_collection.ts index 91f28f6b6a1..866e3df575b 100644 --- a/src/operations/validate_collection.ts +++ b/src/operations/validate_collection.ts @@ -3,7 +3,6 @@ import type { Document } from '../bson'; import { MongoUnexpectedServerResponseError } from '../error'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import { type Callback } from '../utils'; import { CommandOperation, type CommandOperationOptions } from './command'; /** @public */ @@ -47,12 +46,4 @@ export class ValidateCollectionOperation extends CommandOperation { return doc; } - - protected executeCallback( - _server: Server, - _session: ClientSession | undefined, - _callback: Callback - ): void { - throw new Error('Method not implemented.'); - } } diff --git a/test/unit/operations/abstract_command.test.ts b/test/unit/operations/abstract_command.test.ts deleted file mode 100644 index c024db08a9c..00000000000 --- a/test/unit/operations/abstract_command.test.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { expect } from 'chai'; -import * as sinon from 'sinon'; - -import { - type Callback, - type ClientSession, - CommandCallbackOperation, - CommandOperation, - type CommandOperationOptions, - type OperationParent, - Server, - ServerDescription -} from '../../mongodb'; -import { topologyWithPlaceholderClient } from '../../tools/utils'; - -class ConcreteCommand extends CommandCallbackOperation { - constructor(parent?: OperationParent, options?: CommandOperationOptions) { - super(parent, options); - } - - protected executeCallback( - server: Server, - session: ClientSession | undefined, - callback: Callback - ) { - super.execute(server, session).then( - res => callback(undefined, res), - err => callback(err, undefined) - ); - } -} - -describe('class CommandOperation', () => { - let server: Server; - beforeEach(() => { - server = new Server( - topologyWithPlaceholderClient([], {} as any), - new ServerDescription('a:1'), - {} as any - ); - }); - - context('when an operation uses CommandCallbackOperation', () => { - it('calls executeCommand when executeCommandCallback is invoked', done => { - const operation = new ConcreteCommand(); - const operationSpy = sinon.spy(CommandOperation.prototype, 'executeCommand'); - operation.executeCommandCallback(server, undefined, { ping: 1 }, () => { - try { - expect(operationSpy).to.have.been.calledOnceWithExactly(server, undefined, { ping: 1 }); - done(); - } catch (error) { - done(error); - } - }); - }); - }); -});