1
+ import { type Connection } from '..' ;
1
2
import type { Document } from '../bson' ;
3
+ import { MongoDBResponse } from '../cmap/wire_protocol/responses' ;
2
4
import { Collection } from '../collection' ;
3
- import type { Server } from '../sdam/server' ;
4
5
import type { ClientSession } from '../sessions' ;
5
- import { type TimeoutContext } from '../timeout' ;
6
6
import { MongoDBNamespace } from '../utils' ;
7
- import { CommandOperation , type CommandOperationOptions } from './command' ;
7
+ import { type CommandOperationOptions , ModernizedCommandOperation } from './command' ;
8
8
import { Aspect , defineAspects } from './operation' ;
9
9
10
10
/** @public */
@@ -16,7 +16,8 @@ export interface RenameOptions extends CommandOperationOptions {
16
16
}
17
17
18
18
/** @internal */
19
- export class RenameOperation extends CommandOperation < Document > {
19
+ export class RenameOperation extends ModernizedCommandOperation < Document > {
20
+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
20
21
collection : Collection ;
21
22
newName : string ;
22
23
override options : RenameOptions ;
@@ -33,24 +34,20 @@ export class RenameOperation extends CommandOperation<Document> {
33
34
return 'renameCollection' as const ;
34
35
}
35
36
36
- override async execute (
37
- server : Server ,
38
- session : ClientSession | undefined ,
39
- timeoutContext : TimeoutContext
40
- ) : Promise < Collection > {
41
- // Build the command
37
+ override buildCommandDocument ( _connection : Connection , _session ?: ClientSession ) : Document {
42
38
const renameCollection = this . collection . namespace ;
43
- const toCollection = this . collection . s . namespace . withCollection ( this . newName ) . toString ( ) ;
39
+ const to = this . collection . s . namespace . withCollection ( this . newName ) . toString ( ) ;
44
40
const dropTarget =
45
41
typeof this . options . dropTarget === 'boolean' ? this . options . dropTarget : false ;
46
42
47
- const command = {
48
- renameCollection : renameCollection ,
49
- to : toCollection ,
50
- dropTarget : dropTarget
43
+ return {
44
+ renameCollection,
45
+ to,
46
+ dropTarget
51
47
} ;
48
+ }
52
49
53
- await super . executeCommand ( server , session , command , timeoutContext ) ;
50
+ override handleOk ( _response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE > ) : Document {
54
51
return new Collection ( this . collection . s . db , this . newName , this . collection . s . options ) ;
55
52
}
56
53
}
0 commit comments