Skip to content

Commit c16f98c

Browse files
committed
chore: split out run command cursor op
1 parent 0f781a8 commit c16f98c

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/cursor/run_command_cursor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Db } from '../db';
44
import { MongoAPIError, MongoRuntimeError } from '../error';
55
import { executeOperation } from '../operations/execute_operation';
66
import { GetMoreOperation } from '../operations/get_more';
7-
import { RunCommandOperation } from '../operations/run_command';
7+
import { RunCommandOperation, RunCursorCommandOperation } from '../operations/run_command';
88
import type { ReadConcernLike } from '../read_concern';
99
import type { ReadPreferenceLike } from '../read_preference';
1010
import type { ClientSession } from '../sessions';
@@ -143,7 +143,7 @@ export class RunCommandCursor extends AbstractCursor {
143143

144144
/** @internal */
145145
protected async _initialize(session: ClientSession): Promise<InitialCursorResponse> {
146-
const operation = new RunCommandOperation<CursorResponse>(this.db, this.command, {
146+
const operation = new RunCursorCommandOperation(this.db, this.command, {
147147
...this.cursorOptions,
148148
session: session,
149149
readPreference: this.cursorOptions.readPreference,

src/operations/run_command.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { BSONSerializeOptions, Document } from '../bson';
22
import { type Connection } from '../cmap/connection';
3-
import { MongoDBResponse, type MongoDBResponseConstructor } from '../cmap/wire_protocol/responses';
3+
import { CursorResponse, MongoDBResponse, type MongoDBResponseConstructor } from '../cmap/wire_protocol/responses';
44
import { type Db } from '../db';
55
import type { ReadPreferenceLike } from '../read_preference';
66
import type { ServerCommandOptions } from '../sdam/server';
@@ -54,6 +54,41 @@ export class RunCommandOperation<T = Document> extends ModernizedOperation<T> {
5454
}
5555
}
5656

57+
/** @internal */
58+
export class RunCursorCommandOperation extends ModernizedOperation<CursorResponse> {
59+
override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse;
60+
command: Document;
61+
override options: RunCommandOptions & { responseType?: MongoDBResponseConstructor };
62+
63+
constructor(
64+
parent: Db,
65+
command: Document,
66+
options: RunCommandOptions & { responseType?: MongoDBResponseConstructor }
67+
) {
68+
super(options);
69+
this.command = command;
70+
this.options = options;
71+
this.ns = parent.s.namespace.withCollection('$cmd');
72+
}
73+
74+
override get commandName() {
75+
return 'runCommand' as const;
76+
}
77+
78+
override buildCommand(_connection: Connection, _session?: ClientSession): Document {
79+
return this.command;
80+
}
81+
82+
override buildOptions(timeoutContext: TimeoutContext): ServerCommandOptions {
83+
return { session: this.session, timeoutContext };
84+
}
85+
override handleOk(
86+
response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
87+
): CursorResponse {
88+
return response;
89+
}
90+
}
91+
5792
export class RunAdminCommandOperation<T = Document> extends ModernizedOperation<T> {
5893
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
5994
command: Document;

0 commit comments

Comments
 (0)