Skip to content

Commit a95347a

Browse files
committed
refactor: use named exports for all SDAM types
1 parent 38d5ed8 commit a95347a

File tree

12 files changed

+40
-30
lines changed

12 files changed

+40
-30
lines changed

lib/core/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = {
3333
Sessions: require('./sessions'),
3434
BSON: BSON,
3535
EJSON: EJSON,
36-
Topology: require('./sdam/topology'),
36+
Topology: require('./sdam/topology').Topology,
3737
// Raw operations
3838
Query: require('./connection/commands').Query,
3939
// Auth mechanisms

lib/core/sdam/monitoring.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const ServerDescription = require('./server_description');
3+
const ServerDescription = require('./server_description').ServerDescription;
44
const calculateDurationInMs = require('../utils').calculateDurationInMs;
55

66
// pulled from `Server` implementation

lib/core/sdam/server.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const wireProtocol = require('../wireprotocol');
77
const BSON = require('../connection/utils').retrieveBSON();
88
const createClientInfo = require('../topologies/shared').createClientInfo;
99
const Logger = require('../connection/logger');
10-
const ServerDescription = require('./server_description');
10+
const ServerDescription = require('./server_description').ServerDescription;
1111
const ReadPreference = require('../topologies/read_preference');
1212
const monitorServer = require('./monitoring').monitorServer;
1313
const MongoParseError = require('../error').MongoParseError;
@@ -545,4 +545,6 @@ function parseErrorEventHandler(server) {
545545
};
546546
}
547547

548-
module.exports = Server;
548+
module.exports = {
549+
Server
550+
};

lib/core/sdam/server_description.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,6 @@ function parseServerType(ismaster) {
174174
return ServerType.Standalone;
175175
}
176176

177-
module.exports = ServerDescription;
177+
module.exports = {
178+
ServerDescription
179+
};

lib/core/sdam/topology.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22
const EventEmitter = require('events');
3-
const ServerDescription = require('./server_description');
3+
const ServerDescription = require('./server_description').ServerDescription;
44
const ServerType = require('./common').ServerType;
5-
const TopologyDescription = require('./topology_description');
5+
const TopologyDescription = require('./topology_description').TopologyDescription;
66
const TopologyType = require('./common').TopologyType;
77
const monitoring = require('./monitoring');
8-
const Server = require('./server');
8+
const Server = require('./server').Server;
99
const relayEvents = require('../utils').relayEvents;
1010
const ReadPreference = require('../topologies/read_preference');
1111
const isRetryableWritesSupported = require('../topologies/shared').isRetryableWritesSupported;
@@ -1141,4 +1141,6 @@ function srvPollingHandler(topology) {
11411141
* @type {object}
11421142
*/
11431143

1144-
module.exports = Topology;
1144+
module.exports = {
1145+
Topology
1146+
};

lib/core/sdam/topology_description.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const ServerType = require('./common').ServerType;
3-
const ServerDescription = require('./server_description');
3+
const ServerDescription = require('./server_description').ServerDescription;
44
const WIRE_CONSTANTS = require('../wireprotocol/constants');
55
const TopologyType = require('./common').TopologyType;
66

@@ -396,4 +396,6 @@ function checkHasPrimary(serverDescriptions) {
396396
return TopologyType.ReplicaSetNoPrimary;
397397
}
398398

399-
module.exports = TopologyDescription;
399+
module.exports = {
400+
TopologyDescription
401+
};

lib/core/wireprotocol/shared.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const ReadPreference = require('../topologies/read_preference');
44
const MongoError = require('../error').MongoError;
55
const ServerType = require('../sdam/common').ServerType;
6-
const TopologyDescription = require('../sdam/topology_description');
6+
const TopologyDescription = require('../sdam/topology_description').TopologyDescription;
77

88
const MESSAGE_HEADER_SIZE = 16;
99
const COMPRESSION_DETAILS_SIZE = 9; // originalOpcode + uncompressedSize, compressorID

test/core/functional/replset_server_selection_tests.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

33
var expect = require('chai').expect,
4-
f = require('util').format,
54
fs = require('fs'),
5+
p = require('path'),
66
ReplSetState = require('../../../lib/core/topologies/replset_state'),
77
MongoError = require('../../../lib/core/error').MongoError,
88
ReadPreference = require('../../../lib/core/topologies/read_preference');
@@ -18,17 +18,17 @@ describe('A replicaset with no primary', function() {
1818

1919
test: function(done) {
2020
const config = this.configuration;
21-
var path = f(
22-
'%s/../spec/server-selection/server_selection/ReplicaSetNoPrimary/read',
23-
__dirname
21+
var path = p.resolve(
22+
__dirname,
23+
'../../spec/server-selection/server_selection/ReplicaSetNoPrimary/read'
2424
);
2525
var entries = fs.readdirSync(path).filter(function(x) {
2626
return x.indexOf('.json') !== -1;
2727
});
2828

2929
// Execute each of the entries
3030
entries.forEach(function(x) {
31-
executeEntry(config, x, f('%s/%s', path, x));
31+
executeEntry(config, x, `${path}/${x}`);
3232
});
3333

3434
done();
@@ -47,17 +47,18 @@ describe('A replicaset with a primary', function() {
4747

4848
test: function(done) {
4949
const config = this.configuration;
50-
var path = f(
51-
'%s/../spec/server-selection/server_selection/ReplicaSetWithPrimary/read',
52-
__dirname
50+
var path = p.resolve(
51+
__dirname,
52+
'../../spec/server-selection/server_selection/ReplicaSetWithPrimary/read'
5353
);
54+
5455
var entries = fs.readdirSync(path).filter(function(x) {
5556
return x.indexOf('.json') !== -1;
5657
});
5758

5859
// Execute each of the entries
5960
entries.forEach(function(x) {
60-
executeEntry(config, x, f('%s/%s', path, x));
61+
executeEntry(config, x, `${path}/${x}`);
6162
});
6263

6364
done();

test/core/functional/srv_polling_tests.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22

3-
const Topology = require('../../../lib/core/sdam/topology');
4-
const TopologyDescription = require('../../../lib/core/sdam/topology_description');
3+
const Topology = require('../../../lib/core/sdam/topology').Topology;
4+
const TopologyDescription = require('../../../lib/core/sdam/topology_description')
5+
.TopologyDescription;
56
const TopologyType = require('../../../lib/core/sdam/common').TopologyType;
67
const monitoring = require('../../../lib/core/sdam/monitoring');
78
const SrvPoller = require('../../../lib/core/sdam/srv_polling').SrvPoller;

test/core/unit/sdam_spec_tests.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ const fs = require('fs');
33
const path = require('path');
44
const chai = require('chai');
55
const expect = chai.expect;
6-
const Topology = require('../../../lib/core/sdam/topology');
7-
const Server = require('../../../lib/core/sdam/server');
8-
const ServerDescription = require('../../../lib/core/sdam/server_description');
6+
const Topology = require('../../../lib/core/sdam/topology').Topology;
7+
const Server = require('../../../lib/core/sdam/server').Server;
8+
const ServerDescription = require('../../../lib/core/sdam/server_description').ServerDescription;
99
const monitoring = require('../../../lib/core/sdam/monitoring');
1010
const parse = require('../../../lib/core/uri_parser');
1111
chai.use(require('chai-subset'));

0 commit comments

Comments
 (0)