1
+ import { type Document } from '../bson' ;
2
+ import { type Connection } from '../cmap/connection' ;
3
+ import { MongoDBResponse } from '../cmap/wire_protocol/responses' ;
1
4
import type { Db } from '../db' ;
2
5
import { MongoInvalidArgumentError } from '../error' ;
3
- import type { Server } from '../sdam/server' ;
4
- import type { ClientSession } from '../sessions' ;
5
- import { type TimeoutContext } from '../timeout' ;
6
6
import { enumToString } from '../utils' ;
7
- import { CommandOperation , type CommandOperationOptions } from './command' ;
7
+ import { type CommandOperationOptions , ModernizedCommandOperation } from './command' ;
8
8
9
9
const levelValues = new Set ( [ 'off' , 'slow_only' , 'all' ] ) ;
10
10
@@ -22,7 +22,8 @@ export type ProfilingLevel = (typeof ProfilingLevel)[keyof typeof ProfilingLevel
22
22
export type SetProfilingLevelOptions = CommandOperationOptions ;
23
23
24
24
/** @internal */
25
- export class SetProfilingLevelOperation extends CommandOperation < ProfilingLevel > {
25
+ export class SetProfilingLevelOperation extends ModernizedCommandOperation < ProfilingLevel > {
26
+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
26
27
override options : SetProfilingLevelOptions ;
27
28
level : ProfilingLevel ;
28
29
profile : 0 | 1 | 2 ;
@@ -52,21 +53,22 @@ export class SetProfilingLevelOperation extends CommandOperation<ProfilingLevel>
52
53
return 'profile' as const ;
53
54
}
54
55
55
- override async execute (
56
- server : Server ,
57
- session : ClientSession | undefined ,
58
- timeoutContext : TimeoutContext
59
- ) : Promise < ProfilingLevel > {
56
+ override buildCommandDocument ( _connection : Connection ) : Document {
60
57
const level = this . level ;
61
58
62
59
if ( ! levelValues . has ( level ) ) {
60
+ // TODO(NODE-3483): Determine error to put here
63
61
throw new MongoInvalidArgumentError (
64
62
`Profiling level must be one of "${ enumToString ( ProfilingLevel ) } "`
65
63
) ;
66
64
}
67
65
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 ;
71
73
}
72
74
}
0 commit comments