Skip to content

Commit c482c5c

Browse files
committed
remove generic default for AbstractOperation and CommandOperation
1 parent 6680b9f commit c482c5c

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

src/operations/command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface OperationParent {
4848
}
4949

5050
/** @internal */
51-
export abstract class CommandOperation<TResult = Document> extends AbstractOperation {
51+
export abstract class CommandOperation<T> extends AbstractOperation<T> {
5252
options: CommandOperationOptions;
5353
ns: MongoDBNamespace;
5454
readConcern?: ReadConcern;
@@ -97,7 +97,7 @@ export abstract class CommandOperation<TResult = Document> extends AbstractOpera
9797
return true;
9898
}
9999

100-
abstract execute(server: Server, callback: Callback<TResult>): void;
100+
abstract execute(server: Server, callback: Callback<T>): void;
101101

102102
executeCommand(server: Server, cmd: Document, callback: Callback): void {
103103
// TODO: consider making this a non-enumerable property

src/operations/operation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const kSession = Symbol('session');
3737
* a specific aspect.
3838
* @internal
3939
*/
40-
export abstract class AbstractOperation<T = Document> {
40+
export abstract class AbstractOperation<T> {
4141
ns!: MongoDBNamespace;
4242
cmd!: Document;
4343
readPreference: ReadPreference;
@@ -56,6 +56,10 @@ export abstract class AbstractOperation<T = Document> {
5656

5757
// Pull the BSON serialize options from the already-resolved options
5858
this.bsonOptions = resolveBSONOptions(options);
59+
60+
if (options.session) {
61+
this[kSession] = options.session;
62+
}
5963
}
6064

6165
abstract execute(server: Server, callback: Callback<T>): void;

src/sdam/server.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,6 @@ export class Server extends EventEmitter {
261261
return;
262262
}
263263

264-
const error = basicReadValidations(this, options);
265-
if (error) {
266-
return callback(error);
267-
}
268-
269264
// Clone the options
270265
const finalOptions = Object.assign({}, options, { wireProtocolCommand: false });
271266

@@ -424,12 +419,6 @@ function calculateRoundTripTime(oldRtt: number, duration: number): number {
424419
return alpha * duration + (1 - alpha) * oldRtt;
425420
}
426421

427-
function basicReadValidations(server: Server, options?: CommandOptions) {
428-
if (options?.readPreference && !(options.readPreference instanceof ReadPreference)) {
429-
return new MongoError('readPreference must be an instance of ReadPreference');
430-
}
431-
}
432-
433422
function executeWriteOperation(
434423
args: { server: Server; op: string; ns: string; ops: Document[] | Document },
435424
options: WriteCommandOptions,

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { Topology } from './sdam/topology';
88
import type { EventEmitter } from 'events';
99
import type { Db } from './db';
1010
import type { Collection } from './collection';
11-
import type { OperationOptions, AbstractOperation, Hint } from './operations/operation';
11+
import type { OperationOptions, Hint } from './operations/operation';
1212
import type { ClientSession } from './sessions';
1313
import { ReadConcern } from './read_concern';
1414
import type { Connection } from './cmap/connection';
@@ -232,7 +232,7 @@ export function filterOptions(options: AnyOptions, names: string[]): AnyOptions
232232
* @param args - Arguments to apply the provided operation
233233
* @param options - Options that modify the behavior of the method
234234
*/
235-
export function executeLegacyOperation<T extends AbstractOperation>(
235+
export function executeLegacyOperation<T>(
236236
topology: Topology,
237237
operation: (...args: any[]) => void | Promise<Document>,
238238
args: any[],

test/functional/sessions.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ describe('Sessions', function () {
113113

114114
return client
115115
.withSession(testCase.operation(client))
116-
.catch(() => expect(client.topology.s.sessionPool.sessions).to.have.length(1))
117-
.then(() => expect(client.topology.s.sessionPool.sessions).to.have.length(1))
116+
.then(
117+
() => expect(client.topology.s.sessionPool.sessions).to.have.length(1),
118+
() => expect(client.topology.s.sessionPool.sessions).to.have.length(1)
119+
)
118120
.then(() => client.close())
119121
.then(() => {
120122
// verify that the `endSessions` command was sent

0 commit comments

Comments
 (0)