11import type { Long } from '../bson' ;
2- import { MongoRuntimeError } from '../error' ;
3- import type { Server } from '../sdam/server' ;
2+ import { type Connection } from '../cmap/connection' ;
3+ import { MongoDBResponse } from '../cmap/wire_protocol/responses' ;
4+ import { type MongoError , MongoRuntimeError } from '../error' ;
5+ import type { Server , ServerCommandOptions } from '../sdam/server' ;
46import type { ClientSession } from '../sessions' ;
57import { type TimeoutContext } from '../timeout' ;
6- import { type MongoDBNamespace , squashError } from '../utils' ;
7- import { AbstractOperation , Aspect , defineAspects , type OperationOptions } from './operation' ;
8+ import { type MongoDBNamespace } from '../utils' ;
9+ import { Aspect , defineAspects , ModernizedOperation , type OperationOptions } from './operation' ;
810
911/**
1012 * https://www.mongodb.com/docs/manual/reference/command/killCursors/
@@ -16,7 +18,8 @@ interface KillCursorsCommand {
1618 comment ?: unknown ;
1719}
1820
19- export class KillCursorsOperation extends AbstractOperation {
21+ export class KillCursorsOperation extends ModernizedOperation < void > {
22+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
2023 cursorId : Long ;
2124
2225 constructor ( cursorId : Long , ns : MongoDBNamespace , server : Server , options : OperationOptions ) {
@@ -30,15 +33,7 @@ export class KillCursorsOperation extends AbstractOperation {
3033 return 'killCursors' as const ;
3134 }
3235
33- override async execute (
34- server : Server ,
35- session : ClientSession | undefined ,
36- timeoutContext : TimeoutContext
37- ) : Promise < void > {
38- if ( server !== this . server ) {
39- throw new MongoRuntimeError ( 'Killcursor must run on the same server operation began on' ) ;
40- }
41-
36+ override buildCommand ( _connection : Connection , _session ?: ClientSession ) : KillCursorsCommand {
4237 const killCursors = this . ns . collection ;
4338 if ( killCursors == null ) {
4439 // Cursors should have adopted the namespace returned by MongoDB
@@ -50,15 +45,19 @@ export class KillCursorsOperation extends AbstractOperation {
5045 killCursors,
5146 cursors : [ this . cursorId ]
5247 } ;
53- try {
54- await server . command ( this . ns , killCursorsCommand , {
55- session,
56- timeoutContext
57- } ) ;
58- } catch ( error ) {
59- // The driver should never emit errors from killCursors, this is spec-ed behavior
60- squashError ( error ) ;
61- }
48+
49+ return killCursorsCommand ;
50+ }
51+
52+ override buildOptions ( timeoutContext : TimeoutContext ) : ServerCommandOptions {
53+ return {
54+ session : this . session ,
55+ timeoutContext
56+ } ;
57+ }
58+
59+ override handleError ( _error : MongoError ) : void {
60+ // The driver should never emit errors from killCursors, this is spec-ed behavior
6261 }
6362}
6463
0 commit comments