Skip to content

Commit 22af28a

Browse files
remove abstrct operation
1 parent 84f964e commit 22af28a

File tree

13 files changed

+67
-105
lines changed

13 files changed

+67
-105
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ export type { ListDatabasesOptions, ListDatabasesResult } from './operations/lis
547547
export type {
548548
AbstractOperation,
549549
Hint,
550-
ModernizedOperation,
550+
AbstractOperation as ModernizedOperation,
551551
OperationOptions
552552
} from './operations/operation';
553553
export type { ProfilingLevelOptions } from './operations/profiling_level';

src/mongo_client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import {
4444
} from './operations/client_bulk_write/common';
4545
import { ClientBulkWriteExecutor } from './operations/client_bulk_write/executor';
4646
import { executeOperation } from './operations/execute_operation';
47-
import { ModernizedOperation } from './operations/operation';
47+
import { AbstractOperation } from './operations/operation';
4848
import type { ReadConcern, ReadConcernLevel, ReadConcernLike } from './read_concern';
4949
import { ReadPreference, type ReadPreferenceMode } from './read_preference';
5050
import { type AsyncDisposable, configureResourceManagement } from './resource_management';
@@ -792,7 +792,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
792792
const endSessions = Array.from(this.s.sessionPool.sessions, ({ id }) => id);
793793
if (endSessions.length !== 0) {
794794
try {
795-
class EndSessionsOperation extends ModernizedOperation<void> {
795+
class EndSessionsOperation extends AbstractOperation<void> {
796796
override ns = MongoDBNamespace.fromString('admin.$cmd');
797797
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
798798
override buildCommand(_connection: Connection, _session?: ClientSession): Document {

src/operations/command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { type TimeoutContext } from '../timeout';
1515
import { commandSupportsReadConcern, MongoDBNamespace } from '../utils';
1616
import { WriteConcern, type WriteConcernOptions } from '../write_concern';
1717
import type { ReadConcernLike } from './../read_concern';
18-
import { Aspect, ModernizedOperation, type OperationOptions } from './operation';
18+
import { AbstractOperation, Aspect, type OperationOptions } from './operation';
1919

2020
/** @public */
2121
export interface CollationOptions {
@@ -76,7 +76,7 @@ export interface OperationParent {
7676
}
7777

7878
/** @internal */
79-
export abstract class CommandOperation<T> extends ModernizedOperation<T> {
79+
export abstract class CommandOperation<T> extends AbstractOperation<T> {
8080
override options: CommandOperationOptions;
8181
readConcern?: ReadConcern;
8282
writeConcern?: WriteConcern;

src/operations/execute_operation.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,15 @@ import type { ClientSession } from '../sessions';
2727
import { TimeoutContext } from '../timeout';
2828
import { abortable, supportsRetryableWrites } from '../utils';
2929
import { AggregateOperation } from './aggregate';
30-
import { AbstractOperation, Aspect, ModernizedOperation } from './operation';
30+
import { AbstractOperation, Aspect } from './operation';
3131

3232
const MMAPv1_RETRY_WRITES_ERROR_CODE = MONGODB_ERROR_CODES.IllegalOperation;
3333
const MMAPv1_RETRY_WRITES_ERROR_MESSAGE =
3434
'This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.';
3535

36-
type ResultTypeFromOperation<TOperation> =
37-
TOperation extends ModernizedOperation<infer _>
38-
? ReturnType<TOperation['handleOk']>
39-
: TOperation extends AbstractOperation<infer K>
40-
? K
41-
: never;
36+
type ResultTypeFromOperation<TOperation extends AbstractOperation> = ReturnType<
37+
TOperation['handleOk']
38+
>;
4239

4340
/**
4441
* Executes the given operation with provided arguments.
@@ -235,8 +232,6 @@ async function tryOperation<T extends AbstractOperation, TResult = ResultTypeFro
235232
let previousOperationError: MongoError | undefined;
236233
let previousServer: ServerDescription | undefined;
237234

238-
const isModernOperation = operation instanceof ModernizedOperation;
239-
240235
for (let tries = 0; tries < maxTries; tries++) {
241236
if (previousOperationError) {
242237
if (hasWriteAspect && previousOperationError.code === MMAPv1_RETRY_WRITES_ERROR_CODE) {
@@ -290,10 +285,6 @@ async function tryOperation<T extends AbstractOperation, TResult = ResultTypeFro
290285
operation.resetBatch();
291286
}
292287

293-
if (!isModernOperation) {
294-
return await operation.execute(server, session, timeoutContext);
295-
}
296-
297288
try {
298289
const result = await server.modernCommand(operation, timeoutContext);
299290
return operation.handleOk(result);

src/operations/get_more.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { MongoRuntimeError } from '../error';
55
import type { Server, ServerCommandOptions } from '../sdam/server';
66
import { type TimeoutContext } from '../timeout';
77
import { maxWireVersion, type MongoDBNamespace } from '../utils';
8-
import { Aspect, defineAspects, ModernizedOperation, type OperationOptions } from './operation';
8+
import { AbstractOperation, Aspect, defineAspects, type OperationOptions } from './operation';
99

1010
/** @internal */
1111
export interface GetMoreOptions extends OperationOptions {
@@ -37,7 +37,7 @@ export interface GetMoreCommand {
3737
}
3838

3939
/** @internal */
40-
export class GetMoreOperation extends ModernizedOperation<CursorResponse> {
40+
export class GetMoreOperation extends AbstractOperation<CursorResponse> {
4141
override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse;
4242
cursorId: Long;
4343
override options: GetMoreOptions;

src/operations/kill_cursors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { Server, ServerCommandOptions } from '../sdam/server';
66
import type { ClientSession } from '../sessions';
77
import { type TimeoutContext } from '../timeout';
88
import { type MongoDBNamespace } from '../utils';
9-
import { Aspect, defineAspects, ModernizedOperation, type OperationOptions } from './operation';
9+
import { AbstractOperation, Aspect, defineAspects, type OperationOptions } from './operation';
1010

1111
/**
1212
* https://www.mongodb.com/docs/manual/reference/command/killCursors/
@@ -18,7 +18,7 @@ interface KillCursorsCommand {
1818
comment?: unknown;
1919
}
2020

21-
export class KillCursorsOperation extends ModernizedOperation<void> {
21+
export class KillCursorsOperation extends AbstractOperation<void> {
2222
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
2323
cursorId: Long;
2424

src/operations/operation.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,6 @@ export abstract class AbstractOperation<TResult = any> {
8787
Command name should be stateless (should not use 'this' keyword) */
8888
abstract get commandName(): string;
8989

90-
abstract execute(
91-
server: Server,
92-
session: ClientSession | undefined,
93-
timeoutContext: TimeoutContext
94-
): Promise<TResult>;
95-
9690
hasAspect(aspect: symbol): boolean {
9791
const ctor = this.constructor as { aspects?: Set<symbol> };
9892
if (ctor.aspects == null) {
@@ -126,21 +120,8 @@ export abstract class AbstractOperation<TResult = any> {
126120
get canRetryWrite(): boolean {
127121
return this.hasAspect(Aspect.RETRYABLE) && this.hasAspect(Aspect.WRITE_OPERATION);
128122
}
129-
}
130-
131-
/** @internal */
132-
export abstract class ModernizedOperation<TResult> extends AbstractOperation<TResult> {
133123
abstract SERVER_COMMAND_RESPONSE_TYPE: typeof MongoDBResponse;
134124

135-
/** this will never be used - but we must implement it to satisfy AbstractOperation's interface */
136-
override execute(
137-
_server: Server,
138-
_session: ClientSession | undefined,
139-
_timeoutContext: TimeoutContext
140-
): Promise<TResult> {
141-
throw new Error('cannot execute!!');
142-
}
143-
144125
/**
145126
* Build a raw command document.
146127
*/

src/operations/run_command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { type Abortable } from '..';
22
import type { BSONSerializeOptions, Document } from '../bson';
33
import { type Connection } from '../cmap/connection';
44
import { CursorResponse, MongoDBResponse } from '../cmap/wire_protocol/responses';
5-
import { ModernizedOperation } from '../operations/operation';
5+
import { AbstractOperation } from '../operations/operation';
66
import type { ReadPreferenceLike } from '../read_preference';
77
import type { ServerCommandOptions } from '../sdam/server';
88
import type { ClientSession } from '../sessions';
@@ -32,7 +32,7 @@ export type RunCommandOptions = {
3232
Abortable;
3333

3434
/** @internal */
35-
export class RunCommandOperation<T = Document> extends ModernizedOperation<T> {
35+
export class RunCommandOperation<T = Document> extends AbstractOperation<T> {
3636
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
3737
command: Document;
3838
override options: RunCommandOptions;

src/operations/search_indexes/create.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { Collection } from '../../collection';
55
import type { ServerCommandOptions } from '../../sdam/server';
66
import type { ClientSession } from '../../sessions';
77
import { type TimeoutContext } from '../../timeout';
8-
import { ModernizedOperation } from '../operation';
8+
import { AbstractOperation } from '../operation';
99

1010
/**
1111
* @public
@@ -22,7 +22,7 @@ export interface SearchIndexDescription extends Document {
2222
}
2323

2424
/** @internal */
25-
export class CreateSearchIndexesOperation extends ModernizedOperation<Document> {
25+
export class CreateSearchIndexesOperation extends AbstractOperation<Document> {
2626
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
2727
private readonly collection: Collection;
2828
private readonly descriptions: ReadonlyArray<SearchIndexDescription>;

src/operations/search_indexes/drop.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { MONGODB_ERROR_CODES, MongoServerError } from '../../error';
66
import type { ServerCommandOptions } from '../../sdam/server';
77
import type { ClientSession } from '../../sessions';
88
import { type TimeoutContext } from '../../timeout';
9-
import { ModernizedOperation } from '../operation';
9+
import { AbstractOperation } from '../operation';
1010

1111
/** @internal */
12-
export class DropSearchIndexOperation extends ModernizedOperation<void> {
12+
export class DropSearchIndexOperation extends AbstractOperation<void> {
1313
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
1414

1515
private readonly collection: Collection;

0 commit comments

Comments
 (0)