1
1
import 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' ;
4
6
import type { ClientSession } from '../sessions' ;
5
7
import { 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' ;
8
10
9
11
/**
10
12
* https://www.mongodb.com/docs/manual/reference/command/killCursors/
@@ -16,7 +18,8 @@ interface KillCursorsCommand {
16
18
comment ?: unknown ;
17
19
}
18
20
19
- export class KillCursorsOperation extends AbstractOperation {
21
+ export class KillCursorsOperation extends ModernizedOperation < void > {
22
+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
20
23
cursorId : Long ;
21
24
22
25
constructor ( cursorId : Long , ns : MongoDBNamespace , server : Server , options : OperationOptions ) {
@@ -30,15 +33,7 @@ export class KillCursorsOperation extends AbstractOperation {
30
33
return 'killCursors' as const ;
31
34
}
32
35
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 {
42
37
const killCursors = this . ns . collection ;
43
38
if ( killCursors == null ) {
44
39
// Cursors should have adopted the namespace returned by MongoDB
@@ -50,15 +45,19 @@ export class KillCursorsOperation extends AbstractOperation {
50
45
killCursors,
51
46
cursors : [ this . cursorId ]
52
47
} ;
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
62
61
}
63
62
}
64
63
0 commit comments