1+ import { type Document } from '../bson' ;
2+ import { type Connection } from '../cmap/connection' ;
3+ import { MongoDBResponse } from '../cmap/wire_protocol/responses' ;
14import type { Db } from '../db' ;
25import { MongoInvalidArgumentError } from '../error' ;
3- import type { Server } from '../sdam/server' ;
4- import type { ClientSession } from '../sessions' ;
5- import { type TimeoutContext } from '../timeout' ;
66import { enumToString } from '../utils' ;
7- import { CommandOperation , type CommandOperationOptions } from './command' ;
7+ import { type CommandOperationOptions , ModernizedCommandOperation } from './command' ;
88
99const levelValues = new Set ( [ 'off' , 'slow_only' , 'all' ] ) ;
1010
@@ -22,7 +22,8 @@ export type ProfilingLevel = (typeof ProfilingLevel)[keyof typeof ProfilingLevel
2222export type SetProfilingLevelOptions = CommandOperationOptions ;
2323
2424/** @internal */
25- export class SetProfilingLevelOperation extends CommandOperation < ProfilingLevel > {
25+ export class SetProfilingLevelOperation extends ModernizedCommandOperation < ProfilingLevel > {
26+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
2627 override options : SetProfilingLevelOptions ;
2728 level : ProfilingLevel ;
2829 profile : 0 | 1 | 2 ;
@@ -52,21 +53,22 @@ export class SetProfilingLevelOperation extends CommandOperation<ProfilingLevel>
5253 return 'profile' as const ;
5354 }
5455
55- override async execute (
56- server : Server ,
57- session : ClientSession | undefined ,
58- timeoutContext : TimeoutContext
59- ) : Promise < ProfilingLevel > {
56+ override buildCommandDocument ( _connection : Connection ) : Document {
6057 const level = this . level ;
6158
6259 if ( ! levelValues . has ( level ) ) {
60+ // TODO(NODE-3483): Determine error to put here
6361 throw new MongoInvalidArgumentError (
6462 `Profiling level must be one of "${ enumToString ( ProfilingLevel ) } "`
6563 ) ;
6664 }
6765
68- // TODO(NODE-3483): Determine error to put here
69- await super . executeCommand ( server , session , { profile : this . profile } , timeoutContext ) ;
70- return level ;
66+ return { profile : this . profile } ;
67+ }
68+
69+ override handleOk (
70+ _response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE >
71+ ) : ProfilingLevel {
72+ return this . level ;
7173 }
7274}
0 commit comments