1+ import { type Connection } from '..' ;
12import type { Document } from '../bson' ;
3+ import { MongoDBResponse } from '../cmap/wire_protocol/responses' ;
24import { Collection } from '../collection' ;
3- import type { Server } from '../sdam/server' ;
45import type { ClientSession } from '../sessions' ;
5- import { type TimeoutContext } from '../timeout' ;
66import { MongoDBNamespace } from '../utils' ;
7- import { CommandOperation , type CommandOperationOptions } from './command' ;
7+ import { type CommandOperationOptions , ModernizedCommandOperation } from './command' ;
88import { Aspect , defineAspects } from './operation' ;
99
1010/** @public */
@@ -16,7 +16,8 @@ export interface RenameOptions extends CommandOperationOptions {
1616}
1717
1818/** @internal */
19- export class RenameOperation extends CommandOperation < Document > {
19+ export class RenameOperation extends ModernizedCommandOperation < Document > {
20+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
2021 collection : Collection ;
2122 newName : string ;
2223 override options : RenameOptions ;
@@ -33,24 +34,20 @@ export class RenameOperation extends CommandOperation<Document> {
3334 return 'renameCollection' as const ;
3435 }
3536
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 {
4238 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 ( ) ;
4440 const dropTarget =
4541 typeof this . options . dropTarget === 'boolean' ? this . options . dropTarget : false ;
4642
47- const command = {
48- renameCollection : renameCollection ,
49- to : toCollection ,
50- dropTarget : dropTarget
43+ return {
44+ renameCollection,
45+ to,
46+ dropTarget
5147 } ;
48+ }
5249
53- await super . executeCommand ( server , session , command , timeoutContext ) ;
50+ override handleOk ( _response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE > ) : Document {
5451 return new Collection ( this . collection . s . db , this . newName , this . collection . s . options ) ;
5552 }
5653}
0 commit comments