Skip to content

Commit

Permalink
fix: skip config validation when using connector
Browse files Browse the repository at this point in the history
This changeset fixes a problem in the original custom `connector`
factory method implementation that required the `server` config property
to be defined even though its value is ignored.

Removing the validation when `config.options.connector` is defined fixes
the problem.

Ref: #1540
Fixes: #1541
Signed-off-by: Ruy Adorno <[email protected]>
  • Loading branch information
ruyadorno committed May 30, 2023
1 parent e4eadf8 commit 8c62e1d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ class Connection extends EventEmitter {
throw new TypeError('The "config" argument is required and must be of type Object.');
}

if (typeof config.server !== 'string') {
if (typeof config.server !== 'string' && !config.options!.connector) {
throw new TypeError('The "config.server" property is required and must be of type string.');
}

Expand Down Expand Up @@ -1902,6 +1902,9 @@ class Connection extends EventEmitter {

if (this.config.options.port) {
return this.connectOnPort(this.config.options.port, this.config.options.multiSubnetFailover, signal, this.config.options.connector);
} else if (this.config.options.connector) {
// port and multiSubnetFailover are not used when using a custom connector
return this.connectOnPort(0, false, signal, this.config.options.connector);
} else {
return instanceLookup({
server: this.config.server,
Expand Down
2 changes: 0 additions & 2 deletions test/unit/custom-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ describe('custom connector', function() {
const host = server.address().address;
const port = server.address().port;
const connection = new Connection({
server: host,
options: {
connector: async () => {
customConnectorCalled = true;
Expand All @@ -37,7 +36,6 @@ describe('custom connector', function() {
port,
});
},
port
},
});

Expand Down

0 comments on commit 8c62e1d

Please sign in to comment.