set_profiling_level.js 1.8 KB

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