Skip to content

Commit 42d05ae

Browse files
committed
refactor(NODE-5473): remove unused callback inheritance in operations layer (#3793)
1 parent 8b0c86a commit 42d05ae

27 files changed

+24
-317
lines changed

src/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ export type {
389389
CommandOperationOptions,
390390
OperationParent
391391
} from './operations/command';
392-
export type { CommandCallbackOperation } from './operations/command';
393392
export type { IndexInformationOptions } from './operations/common_functions';
394393
export type { CountOptions } from './operations/count';
395394
export type { CountDocumentsOptions } from './operations/count_documents';
@@ -420,12 +419,7 @@ export type {
420419
export type { InsertManyResult, InsertOneOptions, InsertOneResult } from './operations/insert';
421420
export type { CollectionInfo, ListCollectionsOptions } from './operations/list_collections';
422421
export type { ListDatabasesOptions, ListDatabasesResult } from './operations/list_databases';
423-
export type {
424-
AbstractCallbackOperation,
425-
AbstractOperation,
426-
Hint,
427-
OperationOptions
428-
} from './operations/operation';
422+
export type { AbstractOperation, Hint, OperationOptions } from './operations/operation';
429423
export type { ProfilingLevelOptions } from './operations/profiling_level';
430424
export type { RemoveUserOptions } from './operations/remove_user';
431425
export type { RenameOptions } from './operations/rename';

src/operations/aggregate.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { MongoInvalidArgumentError } from '../error';
33
import { type TODO_NODE_3286 } from '../mongo_types';
44
import type { Server } from '../sdam/server';
55
import type { ClientSession } from '../sessions';
6-
import { type Callback, maxWireVersion, type MongoDBNamespace } from '../utils';
6+
import { maxWireVersion, type MongoDBNamespace } from '../utils';
77
import { WriteConcern } from '../write_concern';
88
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
99
import { Aspect, defineAspects, type Hint } from './operation';
@@ -132,14 +132,6 @@ export class AggregateOperation<T = Document> extends CommandOperation<T> {
132132

133133
return super.executeCommand(server, session, command) as TODO_NODE_3286;
134134
}
135-
136-
protected override executeCallback(
137-
_server: Server,
138-
_session: ClientSession | undefined,
139-
_callback: Callback<T>
140-
): void {
141-
throw new Error('Method not implemented.');
142-
}
143135
}
144136

145137
defineAspects(AggregateOperation, [

src/operations/collections.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ export class CollectionsOperation extends AbstractOperation<Collection[]> {
1919
this.db = db;
2020
}
2121

22-
async execute(server: Server, session: ClientSession | undefined): Promise<Collection[]> {
22+
override async execute(
23+
server: Server,
24+
session: ClientSession | undefined
25+
): Promise<Collection[]> {
2326
// Let's get the collection names
2427
const documents = await this.db
2528
.listCollections(

src/operations/command.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ import type { Server } from '../sdam/server';
77
import { MIN_SECONDARY_WRITE_WIRE_VERSION } from '../sdam/server_selection';
88
import type { ClientSession } from '../sessions';
99
import {
10-
type Callback,
1110
commandSupportsReadConcern,
1211
decorateWithExplain,
1312
maxWireVersion,
1413
MongoDBNamespace
1514
} from '../utils';
1615
import { WriteConcern, type WriteConcernOptions } from '../write_concern';
1716
import type { ReadConcernLike } from './../read_concern';
18-
import { AbstractCallbackOperation, Aspect, type OperationOptions } from './operation';
17+
import { AbstractOperation, Aspect, type OperationOptions } from './operation';
1918

2019
/** @public */
2120
export interface CollationOptions {
@@ -68,7 +67,7 @@ export interface OperationParent {
6867
}
6968

7069
/** @internal */
71-
export abstract class CommandOperation<T> extends AbstractCallbackOperation<T> {
70+
export abstract class CommandOperation<T> extends AbstractOperation<T> {
7271
override options: CommandOperationOptions;
7372
readConcern?: ReadConcern;
7473
writeConcern?: WriteConcern;
@@ -156,22 +155,3 @@ export abstract class CommandOperation<T> extends AbstractCallbackOperation<T> {
156155
return server.commandAsync(this.ns, cmd, options);
157156
}
158157
}
159-
160-
/** @internal */
161-
export abstract class CommandCallbackOperation<T = any> extends CommandOperation<T> {
162-
constructor(parent?: OperationParent, options?: CommandOperationOptions) {
163-
super(parent, options);
164-
}
165-
166-
executeCommandCallback(
167-
server: Server,
168-
session: ClientSession | undefined,
169-
cmd: Document,
170-
callback: Callback
171-
): void {
172-
super.executeCommand(server, session, cmd).then(
173-
res => callback(undefined, res),
174-
err => callback(err, undefined)
175-
);
176-
}
177-
}

src/operations/count.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Document } from '../bson';
22
import type { Collection } from '../collection';
33
import type { Server } from '../sdam/server';
44
import type { ClientSession } from '../sessions';
5-
import type { Callback, MongoDBNamespace } from '../utils';
5+
import type { MongoDBNamespace } from '../utils';
66
import { CommandOperation, type CommandOperationOptions } from './command';
77
import { Aspect, defineAspects } from './operation';
88

@@ -58,14 +58,6 @@ export class CountOperation extends CommandOperation<number> {
5858
const result = await super.executeCommand(server, session, cmd);
5959
return result ? result.n : 0;
6060
}
61-
62-
protected override executeCallback(
63-
_server: Server,
64-
_session: ClientSession | undefined,
65-
_callback: Callback<number>
66-
): void {
67-
throw new Error('Method not implemented.');
68-
}
6961
}
7062

7163
defineAspects(CountOperation, [Aspect.READ_OPERATION, Aspect.RETRYABLE]);

src/operations/create_collection.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { MongoCompatibilityError } from '../error';
99
import type { PkFactory } from '../mongo_client';
1010
import type { Server } from '../sdam/server';
1111
import type { ClientSession } from '../sessions';
12-
import { type Callback } from '../utils';
1312
import { CommandOperation, type CommandOperationOptions } from './command';
1413
import { CreateIndexOperation } from './indexes';
1514
import { Aspect, defineAspects } from './operation';
@@ -171,14 +170,6 @@ export class CreateCollectionOperation extends CommandOperation<Collection> {
171170
return coll;
172171
}
173172

174-
protected executeCallback(
175-
_server: Server,
176-
_session: ClientSession | undefined,
177-
_callback: Callback<Collection>
178-
): void {
179-
throw new Error('Method not implemented.');
180-
}
181-
182173
private async executeWithoutEncryptedFieldsCheck(
183174
server: Server,
184175
session: ClientSession | undefined

src/operations/delete.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MongoCompatibilityError, MongoServerError } from '../error';
44
import { type TODO_NODE_3286 } from '../mongo_types';
55
import type { Server } from '../sdam/server';
66
import type { ClientSession } from '../sessions';
7-
import type { Callback, MongoDBNamespace } from '../utils';
7+
import type { MongoDBNamespace } from '../utils';
88
import type { WriteConcernOptions } from '../write_concern';
99
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
1010
import { Aspect, defineAspects, type Hint } from './operation';
@@ -93,14 +93,6 @@ export class DeleteOperation extends CommandOperation<DeleteResult> {
9393

9494
return super.executeCommand(server, session, command) as TODO_NODE_3286;
9595
}
96-
97-
protected override executeCallback(
98-
_server: Server,
99-
_session: ClientSession | undefined,
100-
_callback: Callback<DeleteResult>
101-
): void {
102-
throw new Error('Method not implemented.');
103-
}
10496
}
10597

10698
export class DeleteOneOperation extends DeleteOperation {

src/operations/distinct.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Document } from '../bson';
22
import type { Collection } from '../collection';
33
import type { Server } from '../sdam/server';
44
import type { ClientSession } from '../sessions';
5-
import { type Callback, decorateWithCollation, decorateWithReadConcern } from '../utils';
5+
import { decorateWithCollation, decorateWithReadConcern } from '../utils';
66
import { CommandOperation, type CommandOperationOptions } from './command';
77
import { Aspect, defineAspects } from './operation';
88

@@ -72,14 +72,6 @@ export class DistinctOperation extends CommandOperation<any[]> {
7272

7373
return this.explain ? result : result.values;
7474
}
75-
76-
protected override executeCallback(
77-
_server: Server,
78-
_session: ClientSession | undefined,
79-
_callback: Callback<any[]>
80-
): void {
81-
throw new Error('Method not implemented.');
82-
}
8375
}
8476

8577
defineAspects(DistinctOperation, [Aspect.READ_OPERATION, Aspect.RETRYABLE, Aspect.EXPLAINABLE]);

src/operations/drop.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { Db } from '../db';
33
import { MONGODB_ERROR_CODES, MongoServerError } from '../error';
44
import type { Server } from '../sdam/server';
55
import type { ClientSession } from '../sessions';
6-
import { type Callback } from '../utils';
76
import { CommandOperation, type CommandOperationOptions } from './command';
87
import { Aspect, defineAspects } from './operation';
98

@@ -69,14 +68,6 @@ export class DropCollectionOperation extends CommandOperation<boolean> {
6968
return this.executeWithoutEncryptedFieldsCheck(server, session);
7069
}
7170

72-
protected executeCallback(
73-
_server: Server,
74-
_session: ClientSession | undefined,
75-
_callback: Callback<boolean>
76-
): void {
77-
throw new Error('Method not implemented.');
78-
}
79-
8071
private async executeWithoutEncryptedFieldsCheck(
8172
server: Server,
8273
session: ClientSession | undefined
@@ -101,14 +92,6 @@ export class DropDatabaseOperation extends CommandOperation<boolean> {
10192
await super.executeCommand(server, session, { dropDatabase: 1 });
10293
return true;
10394
}
104-
105-
protected executeCallback(
106-
_server: Server,
107-
_session: ClientSession | undefined,
108-
_callback: Callback<boolean>
109-
): void {
110-
throw new Error('Method not implemented.');
111-
}
11295
}
11396

11497
defineAspects(DropCollectionOperation, [Aspect.WRITE_OPERATION]);

src/operations/estimated_document_count.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { Document } from '../bson';
22
import type { Collection } from '../collection';
33
import type { Server } from '../sdam/server';
44
import type { ClientSession } from '../sessions';
5-
import type { Callback } from '../utils';
65
import { CommandOperation, type CommandOperationOptions } from './command';
76
import { Aspect, defineAspects } from './operation';
87

@@ -44,14 +43,6 @@ export class EstimatedDocumentCountOperation extends CommandOperation<number> {
4443

4544
return response?.n || 0;
4645
}
47-
48-
protected override executeCallback(
49-
_server: Server,
50-
_session: ClientSession | undefined,
51-
_callback: Callback<number>
52-
): void {
53-
throw new Error('Method not implemented.');
54-
}
5546
}
5647

5748
defineAspects(EstimatedDocumentCountOperation, [

src/operations/find.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ import { ReadConcern } from '../read_concern';
55
import type { Server } from '../sdam/server';
66
import type { ClientSession } from '../sessions';
77
import { formatSort, type Sort } from '../sort';
8-
import {
9-
type Callback,
10-
decorateWithExplain,
11-
type MongoDBNamespace,
12-
normalizeHintField
13-
} from '../utils';
8+
import { decorateWithExplain, type MongoDBNamespace, normalizeHintField } from '../utils';
149
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
1510
import { Aspect, defineAspects, type Hint } from './operation';
1611

@@ -119,14 +114,6 @@ export class FindOperation extends CommandOperation<Document> {
119114
session
120115
});
121116
}
122-
123-
protected executeCallback(
124-
_server: Server,
125-
_session: ClientSession | undefined,
126-
_callback: Callback<Document>
127-
): void {
128-
throw new Error('Method not implemented.');
129-
}
130117
}
131118

132119
function makeFindCommand(ns: MongoDBNamespace, filter: Document, options: FindOptions): Document {

src/operations/find_and_modify.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ReadPreference } from '../read_preference';
55
import type { Server } from '../sdam/server';
66
import type { ClientSession } from '../sessions';
77
import { formatSort, type Sort, type SortForCmd } from '../sort';
8-
import { type Callback, decorateWithCollation, hasAtomicOperators, maxWireVersion } from '../utils';
8+
import { decorateWithCollation, hasAtomicOperators, maxWireVersion } from '../utils';
99
import type { WriteConcern, WriteConcernSettings } from '../write_concern';
1010
import { CommandOperation, type CommandOperationOptions } from './command';
1111
import { Aspect, defineAspects } from './operation';
@@ -215,14 +215,6 @@ class FindAndModifyOperation extends CommandOperation<Document> {
215215
const result = await super.executeCommand(server, session, cmd);
216216
return options.includeResultMetadata ? result : result.value ?? null;
217217
}
218-
219-
protected override executeCallback(
220-
_server: Server,
221-
_session: ClientSession | undefined,
222-
_callback: Callback<Document>
223-
): void {
224-
throw new Error('Method not implemented.');
225-
}
226218
}
227219

228220
/** @internal */

src/operations/get_more.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class GetMoreOperation extends AbstractOperation {
5252
* Although there is a server already associated with the get more operation, the signature
5353
* for execute passes a server so we will just use that one.
5454
*/
55-
async execute(server: Server, _session: ClientSession | undefined): Promise<Document> {
55+
override async execute(server: Server, _session: ClientSession | undefined): Promise<Document> {
5656
if (server !== this.server) {
5757
throw new MongoRuntimeError('Getmore must run on the same server operation began on');
5858
}

src/operations/indexes.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { type OneOrMore } from '../mongo_types';
66
import { ReadPreference } from '../read_preference';
77
import type { Server } from '../sdam/server';
88
import type { ClientSession } from '../sessions';
9-
import { type Callback, isObject, maxWireVersion, type MongoDBNamespace } from '../utils';
9+
import { isObject, maxWireVersion, type MongoDBNamespace } from '../utils';
1010
import {
1111
type CollationOptions,
1212
CommandOperation,
@@ -186,7 +186,7 @@ export class IndexesOperation extends AbstractOperation<Document[]> {
186186
this.collection = collection;
187187
}
188188

189-
override execute(_server: Server, session: ClientSession | undefined): Promise<Document[]> {
189+
override async execute(_server: Server, session: ClientSession | undefined): Promise<Document[]> {
190190
const coll = this.collection;
191191
const options = this.options;
192192

@@ -260,14 +260,6 @@ export class CreateIndexesOperation<
260260
const indexNames = indexes.map(index => index.name || '');
261261
return indexNames as T;
262262
}
263-
264-
protected executeCallback(
265-
_server: Server,
266-
_session: ClientSession | undefined,
267-
_callback: Callback<T>
268-
): void {
269-
throw new Error('Method not implemented.');
270-
}
271263
}
272264

273265
/** @internal */
@@ -340,14 +332,6 @@ export class DropIndexOperation extends CommandOperation<Document> {
340332
const cmd = { dropIndexes: this.collection.collectionName, index: this.indexName };
341333
return super.executeCommand(server, session, cmd);
342334
}
343-
344-
protected executeCallback(
345-
_server: Server,
346-
_session: ClientSession | undefined,
347-
_callback: Callback<Document>
348-
): void {
349-
throw new Error('Method not implemented.');
350-
}
351335
}
352336

353337
/** @public */
@@ -391,14 +375,6 @@ export class ListIndexesOperation extends CommandOperation<Document> {
391375

392376
return super.executeCommand(server, session, command);
393377
}
394-
395-
protected executeCallback(
396-
_server: Server,
397-
_session: ClientSession | undefined,
398-
_callback: Callback<Document>
399-
): void {
400-
throw new Error('Method not implemented.');
401-
}
402378
}
403379

404380
/** @internal */
@@ -447,7 +423,7 @@ export class IndexInformationOperation extends AbstractOperation<Document> {
447423
this.name = name;
448424
}
449425

450-
override execute(server: Server, session: ClientSession | undefined): Promise<Document> {
426+
override async execute(server: Server, session: ClientSession | undefined): Promise<Document> {
451427
const db = this.db;
452428
const name = this.name;
453429

0 commit comments

Comments
 (0)