From 8c62e1dc6a4693c66924c528ed54f3383ba3db86 Mon Sep 17 00:00:00 2001 From: Ruy Adorno Date: Tue, 30 May 2023 16:28:49 -0400 Subject: [PATCH] fix: skip config validation when using connector 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: https://github.com/tediousjs/tedious/pull/1540 Fixes: https://github.com/tediousjs/tedious/issues/1541 Signed-off-by: Ruy Adorno --- src/connection.ts | 5 ++++- test/unit/custom-connector.js | 2 -- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/connection.ts b/src/connection.ts index 4241efc85..d79186b1f 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -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.'); } @@ -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, diff --git a/test/unit/custom-connector.js b/test/unit/custom-connector.js index 36e49d19d..fb23984bc 100644 --- a/test/unit/custom-connector.js +++ b/test/unit/custom-connector.js @@ -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; @@ -37,7 +36,6 @@ describe('custom connector', function() { port, }); }, - port }, });