stream_description.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.StreamDescription = void 0;
  4. const common_1 = require("../sdam/common");
  5. const server_description_1 = require("../sdam/server_description");
  6. const RESPONSE_FIELDS = [
  7. 'minWireVersion',
  8. 'maxWireVersion',
  9. 'maxBsonObjectSize',
  10. 'maxMessageSizeBytes',
  11. 'maxWriteBatchSize',
  12. 'logicalSessionTimeoutMinutes'
  13. ];
  14. /** @public */
  15. class StreamDescription {
  16. constructor(address, options) {
  17. this.address = address;
  18. this.type = common_1.ServerType.Unknown;
  19. this.minWireVersion = undefined;
  20. this.maxWireVersion = undefined;
  21. this.maxBsonObjectSize = 16777216;
  22. this.maxMessageSizeBytes = 48000000;
  23. this.maxWriteBatchSize = 100000;
  24. this.logicalSessionTimeoutMinutes = options === null || options === void 0 ? void 0 : options.logicalSessionTimeoutMinutes;
  25. this.loadBalanced = !!(options === null || options === void 0 ? void 0 : options.loadBalanced);
  26. this.compressors =
  27. options && options.compressors && Array.isArray(options.compressors)
  28. ? options.compressors
  29. : [];
  30. }
  31. receiveResponse(response) {
  32. if (response == null) {
  33. return;
  34. }
  35. this.type = (0, server_description_1.parseServerType)(response);
  36. for (const field of RESPONSE_FIELDS) {
  37. if (response[field] != null) {
  38. this[field] = response[field];
  39. }
  40. // testing case
  41. if ('__nodejs_mock_server__' in response) {
  42. this.__nodejs_mock_server__ = response['__nodejs_mock_server__'];
  43. }
  44. }
  45. if (response.compression) {
  46. this.compressor = this.compressors.filter(c => { var _a; return (_a = response.compression) === null || _a === void 0 ? void 0 : _a.includes(c); })[0];
  47. }
  48. }
  49. }
  50. exports.StreamDescription = StreamDescription;
  51. //# sourceMappingURL=stream_description.js.map