profiling_level.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import type { Db } from '../db';
  2. import { MongoRuntimeError } from '../error';
  3. import type { Server } from '../sdam/server';
  4. import type { ClientSession } from '../sessions';
  5. import type { Callback } from '../utils';
  6. import { CommandCallbackOperation, type CommandOperationOptions } from './command';
  7. /** @public */
  8. export type ProfilingLevelOptions = CommandOperationOptions;
  9. /** @internal */
  10. export class ProfilingLevelOperation extends CommandCallbackOperation<string> {
  11. override options: ProfilingLevelOptions;
  12. constructor(db: Db, options: ProfilingLevelOptions) {
  13. super(db, options);
  14. this.options = options;
  15. }
  16. override executeCallback(
  17. server: Server,
  18. session: ClientSession | undefined,
  19. callback: Callback<string>
  20. ): void {
  21. super.executeCommandCallback(server, session, { profile: -1 }, (err, doc) => {
  22. if (err == null && doc.ok === 1) {
  23. const was = doc.was;
  24. if (was === 0) return callback(undefined, 'off');
  25. if (was === 1) return callback(undefined, 'slow_only');
  26. if (was === 2) return callback(undefined, 'all');
  27. // TODO(NODE-3483)
  28. return callback(new MongoRuntimeError(`Illegal profiling level value ${was}`));
  29. } else {
  30. // TODO(NODE-3483): Consider MongoUnexpectedServerResponseError
  31. err != null ? callback(err) : callback(new MongoRuntimeError('Error with profile command'));
  32. }
  33. });
  34. }
  35. }