All files / src/operations profiling_level.ts

88.23% Statements 15/17
75% Branches 6/8
100% Functions 3/3
85.71% Lines 12/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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  396x       396x           396x       923x 923x       1152x               694x 694x 694x 694x 347x 59x              
import type { Db } from '../db';
import { MongoUnexpectedServerResponseError } from '../error';
import type { Server } from '../sdam/server';
import type { ClientSession } from '../sessions';
import { type TimeoutContext } from '../timeout';
import { CommandOperation, type CommandOperationOptions } from './command';
 
/** @public */
export type ProfilingLevelOptions = CommandOperationOptions;
 
/** @internal */
export class ProfilingLevelOperation extends CommandOperation<string> {
  override options: ProfilingLevelOptions;
 
  constructor(db: Db, options: ProfilingLevelOptions) {
    super(db, options);
    this.options = options;
  }
 
  override get commandName() {
    return 'profile' as const;
  }
 
  override async execute(
    server: Server,
    session: ClientSession | undefined,
    timeoutContext: TimeoutContext
  ): Promise<string> {
    const doc = await super.executeCommand(server, session, { profile: -1 }, timeoutContext);
    Eif (doc.ok === 1) {
      const was = doc.was;
      if (was === 0) return 'off';
      if (was === 1) return 'slow_only';
      Eif (was === 2) return 'all';
      throw new MongoUnexpectedServerResponseError(`Illegal profiling level value ${was}`);
    } else {
      throw new MongoUnexpectedServerResponseError('Error with profile command');
    }
  }
}