profiling_level.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ProfilingLevelOperation = void 0;
  4. const bson_1 = require("../bson");
  5. const responses_1 = require("../cmap/wire_protocol/responses");
  6. const error_1 = require("../error");
  7. const command_1 = require("./command");
  8. class ProfilingLevelResponse extends responses_1.MongoDBResponse {
  9. get was() {
  10. return this.get('was', bson_1.BSONType.int, true);
  11. }
  12. }
  13. /** @internal */
  14. class ProfilingLevelOperation extends command_1.CommandOperation {
  15. constructor(db, options) {
  16. super(db, options);
  17. this.SERVER_COMMAND_RESPONSE_TYPE = ProfilingLevelResponse;
  18. this.options = options;
  19. }
  20. get commandName() {
  21. return 'profile';
  22. }
  23. buildCommandDocument(_connection) {
  24. return { profile: -1 };
  25. }
  26. handleOk(response) {
  27. if (response.ok === 1) {
  28. const was = response.was;
  29. if (was === 0)
  30. return 'off';
  31. if (was === 1)
  32. return 'slow_only';
  33. if (was === 2)
  34. return 'all';
  35. throw new error_1.MongoUnexpectedServerResponseError(`Illegal profiling level value ${was}`);
  36. }
  37. else {
  38. throw new error_1.MongoUnexpectedServerResponseError('Error with profile command');
  39. }
  40. }
  41. }
  42. exports.ProfilingLevelOperation = ProfilingLevelOperation;
  43. //# sourceMappingURL=profiling_level.js.map