-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathprofiling_level.ts
More file actions
46 lines (39 loc) · 1.48 KB
/
profiling_level.ts
File metadata and controls
46 lines (39 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { BSONType, type Document } from '../bson';
import { type Connection } from '../cmap/connection';
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
import type { Db } from '../db';
import { MongoUnexpectedServerResponseError } from '../error';
import { type CommandOperationOptions, ModernizedCommandOperation } from './command';
/** @public */
export type ProfilingLevelOptions = CommandOperationOptions;
class ProfilingLevelResponse extends MongoDBResponse {
get was() {
return this.get('was', BSONType.int, true);
}
}
/** @internal */
export class ProfilingLevelOperation extends ModernizedCommandOperation<string> {
override SERVER_COMMAND_RESPONSE_TYPE = ProfilingLevelResponse;
override options: ProfilingLevelOptions;
constructor(db: Db, options: ProfilingLevelOptions) {
super(db, options);
this.options = options;
}
override get commandName() {
return 'profile' as const;
}
override buildCommandDocument(_connection: Connection): Document {
return { profile: -1 };
}
override handleOk(response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): string {
if (response.ok === 1) {
const was = response.was;
if (was === 0) return 'off';
if (was === 1) return 'slow_only';
if (was === 2) return 'all';
throw new MongoUnexpectedServerResponseError(`Illegal profiling level value ${was}`);
} else {
throw new MongoUnexpectedServerResponseError('Error with profile command');
}
}
}