set_profiling_level.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.SetProfilingLevelOperation = exports.ProfilingLevel = void 0;
  4. const error_1 = require("../error");
  5. const utils_1 = require("../utils");
  6. const command_1 = require("./command");
  7. const levelValues = new Set(['off', 'slow_only', 'all']);
  8. /** @public */
  9. exports.ProfilingLevel = Object.freeze({
  10. off: 'off',
  11. slowOnly: 'slow_only',
  12. all: 'all'
  13. });
  14. /** @internal */
  15. class SetProfilingLevelOperation extends command_1.CommandOperation {
  16. constructor(db, level, options) {
  17. super(db, options);
  18. this.options = options;
  19. switch (level) {
  20. case exports.ProfilingLevel.off:
  21. this.profile = 0;
  22. break;
  23. case exports.ProfilingLevel.slowOnly:
  24. this.profile = 1;
  25. break;
  26. case exports.ProfilingLevel.all:
  27. this.profile = 2;
  28. break;
  29. default:
  30. this.profile = 0;
  31. break;
  32. }
  33. this.level = level;
  34. }
  35. execute(server, session, callback) {
  36. const level = this.level;
  37. if (!levelValues.has(level)) {
  38. return callback(new error_1.MongoInvalidArgumentError(`Profiling level must be one of "${(0, utils_1.enumToString)(exports.ProfilingLevel)}"`));
  39. }
  40. // TODO(NODE-3483): Determine error to put here
  41. super.executeCommand(server, session, { profile: this.profile }, (err, doc) => {
  42. if (err == null && doc.ok === 1)
  43. return callback(undefined, level);
  44. return err != null
  45. ? callback(err)
  46. : callback(new error_1.MongoRuntimeError('Error with profile command'));
  47. });
  48. }
  49. }
  50. exports.SetProfilingLevelOperation = SetProfilingLevelOperation;
  51. //# sourceMappingURL=set_profiling_level.js.map