From 2300445646db264fe03a6194e2e7a77887204027 Mon Sep 17 00:00:00 2001 From: "Brian M. Carlson" Date: Sun, 18 Jun 2017 14:30:39 -0500 Subject: [PATCH] Cleanup a bit of dead code --- lib/client.js | 10 +++------- lib/index.js | 17 ++++++++++++++++- lib/native/index.js | 2 +- lib/pool-factory.js | 17 ----------------- lib/promise.js | 12 ------------ lib/utils.js | 10 +++++++++- test/unit/client/md5-password-tests.js | 9 +++++---- 7 files changed, 34 insertions(+), 43 deletions(-) delete mode 100644 lib/pool-factory.js delete mode 100644 lib/promise.js diff --git a/lib/client.js b/lib/client.js index 22026c1f..b11a0f39 100644 --- a/lib/client.js +++ b/lib/client.js @@ -6,9 +6,9 @@ * README.md file in the root directory of this source tree. */ -var crypto = require('crypto'); var EventEmitter = require('events').EventEmitter; var util = require('util'); +var utils = require('./utils') var pgPass = require('pgpass'); var TypeOverrides = require('./type-overrides'); @@ -97,8 +97,8 @@ Client.prototype.connect = function(callback) { //password request handling con.on('authenticationMD5Password', checkPgPass(function(msg) { - var inner = Client.md5(self.password + self.user); - var outer = Client.md5(Buffer.concat([Buffer.from(inner), msg.salt])); + var inner = utils.md5(self.password + self.user); + var outer = utils.md5(Buffer.concat([Buffer.from(inner), msg.salt])); var md5password = "md5" + outer; con.password(md5password); })); @@ -406,10 +406,6 @@ Client.prototype.end = function (cb) { } }; -Client.md5 = function (string) { - return crypto.createHash('md5').update(string, 'utf-8').digest('hex'); -}; - // expose a Query constructor Client.Query = Query; diff --git a/lib/index.js b/lib/index.js index ac3fb059..d12ea45a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -12,7 +12,22 @@ var Client = require('./client'); var defaults = require('./defaults'); var Connection = require('./connection'); var ConnectionParameters = require('./connection-parameters'); -var poolFactory = require('./pool-factory'); +var Pool = require('pg-pool'); + +const poolFactory = (Client) => { + var BoundPool = function(options) { + var config = { Client: Client }; + for (var key in options) { + config[key] = options[key]; + } + Pool.call(this, config); + }; + + util.inherits(BoundPool, Pool); + + return BoundPool; +}; + var PG = function(clientConstructor) { this.defaults = defaults; diff --git a/lib/native/index.js b/lib/native/index.js index ccf987e3..a35a2733 100644 --- a/lib/native/index.js +++ b/lib/native/index.js @@ -1 +1 @@ -module.exports = require('./client'); +module.exports = require('./client') diff --git a/lib/pool-factory.js b/lib/pool-factory.js deleted file mode 100644 index 85f0e6a5..00000000 --- a/lib/pool-factory.js +++ /dev/null @@ -1,17 +0,0 @@ -var Client = require('./client'); -var util = require('util'); -var Pool = require('pg-pool'); - -module.exports = function(Client) { - var BoundPool = function(options) { - var config = { Client: Client }; - for (var key in options) { - config[key] = options[key]; - } - Pool.call(this, config); - }; - - util.inherits(BoundPool, Pool); - - return BoundPool; -}; diff --git a/lib/promise.js b/lib/promise.js deleted file mode 100644 index 4d308cb9..00000000 --- a/lib/promise.js +++ /dev/null @@ -1,12 +0,0 @@ -const util = require('util') -const deprecationMessage = 'Using the promise result as an event emitter is deprecated and will be removed in pg@8.0' -module.exports = function(emitter, callback) { - const promise = new global.Promise(callback) - promise.on = util.deprecate(function () { - emitter.on.apply(emitter, arguments) - }, deprecationMessage); - - promise.once = util.deprecate(function () { - emitter.once.apply(emitter, arguments) - }, deprecationMessage) -} diff --git a/lib/utils.js b/lib/utils.js index e658bbd4..7ecf4b29 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -7,7 +7,9 @@ */ const util = require('util') -var defaults = require('./defaults'); +const crypto = require('crypto'); + +const defaults = require('./defaults'); function escapeElement(elementRepresentation) { var escaped = elementRepresentation @@ -138,6 +140,11 @@ function normalizeQueryConfig (config, values, callback) { return config; } + +const md5 = function (string) { + return crypto.createHash('md5').update(string, 'utf-8').digest('hex'); +}; + module.exports = { prepareValue: function prepareValueWrapper (value) { //this ensures that extra arguments do not get passed into prepareValue @@ -145,4 +152,5 @@ module.exports = { return prepareValue(value); }, normalizeQueryConfig: normalizeQueryConfig, + md5: md5, }; diff --git a/test/unit/client/md5-password-tests.js b/test/unit/client/md5-password-tests.js index 315ef197..78c82602 100644 --- a/test/unit/client/md5-password-tests.js +++ b/test/unit/client/md5-password-tests.js @@ -1,4 +1,5 @@ -require(__dirname + '/test-helper'); +require('./test-helper'); +var utils = require('../../../lib/utils') test('md5 authentication', function() { var client = createClient(); @@ -9,8 +10,8 @@ test('md5 authentication', function() { test('responds', function() { assert.lengthIs(client.connection.stream.packets, 1); test('should have correct encrypted data', function() { - var encrypted = Client.md5(client.password + client.user); - encrypted = Client.md5(encrypted + salt.toString('binary')); + var encrypted = utils.md5(client.password + client.user); + encrypted = utils.md5(encrypted + salt.toString('binary')); var password = "md5" + encrypted //how do we want to test this? assert.equalBuffers(client.connection.stream.packets[0], new BufferList() @@ -20,5 +21,5 @@ test('md5 authentication', function() { }); test('md5 of utf-8 strings', function() { - assert.equal(Client.md5('😊'), '5deda34cd95f304948d2bc1b4a62c11e'); + assert.equal(utils.md5('😊'), '5deda34cd95f304948d2bc1b4a62c11e'); });