diff --git a/.travis.yml b/.travis.yml index 74f1e4c0c..885cfa0ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,14 +12,6 @@ addons: matrix: include: - - node_js: "0.10" - addons: - postgresql: "9.6" - env: [] - - node_js: "0.12" - addons: - postgresql: "9.6" - env: [] - node_js: "4" addons: postgresql: "9.6" diff --git a/lib/client.js b/lib/client.js index a0d7f21c7..a565ccbcb 100644 --- a/lib/client.js +++ b/lib/client.js @@ -94,7 +94,7 @@ 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([new Buffer(inner), msg.salt])); + var outer = Client.md5(Buffer.concat([Buffer.from(inner), msg.salt])); var md5password = "md5" + outer; con.password(md5password); })); diff --git a/lib/connection.js b/lib/connection.js index 87d4f274b..676b5f0cb 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -13,21 +13,6 @@ var util = require('util'); var Writer = require('buffer-writer'); var Reader = require('packet-reader'); -var indexOf = - 'indexOf' in Buffer.prototype ? - function indexOf(buffer, value, start) { - return buffer.indexOf(value, start); - } : - function indexOf(buffer, value, start) { - for (var i = start, len = buffer.length; i < len; i++) { - if (buffer[i] === value) { - return i; - } - } - - return -1; - }; - var TEXT_MODE = 0; var BINARY_MODE = 1; var Connection = function(config) { @@ -311,7 +296,7 @@ Connection.prototype.execute = function(config, more) { this._send(0x45, more); }; -var emptyBuffer = Buffer(0); +var emptyBuffer = Buffer.alloc(0); Connection.prototype.flush = function() { //0x48 = 'H' @@ -450,7 +435,7 @@ Connection.prototype.parseR = function(buffer, length) { code = this.parseInt32(buffer); if(code === 5) { //md5 required msg.name = 'authenticationMD5Password'; - msg.salt = new Buffer(4); + msg.salt = Buffer.alloc(4); buffer.copy(msg.salt, 0, this.offset, this.offset + 4); this.offset += 4; return msg; @@ -665,7 +650,7 @@ Connection.prototype.readBytes = function(buffer, length) { Connection.prototype.parseCString = function(buffer) { var start = this.offset; - var end = indexOf(buffer, 0, start); + var end = buffer.indexOf(0, start); this.offset = end + 1; return buffer.toString(this.encoding, start, end); }; diff --git a/package.json b/package.json index 590a91557..d52ba05ca 100644 --- a/package.json +++ b/package.json @@ -30,9 +30,7 @@ "async": "0.9.0", "co": "4.6.0", "jshint": "2.5.2", - "lodash": "4.13.1", - "pg-copy-streams": "0.3.0", - "promise-polyfill": "5.2.1" + "pg-copy-streams": "0.3.0" }, "minNativeVersion": "1.7.0", "scripts": { diff --git a/test/buffer-list.js b/test/buffer-list.js index 3aa245521..2b1ac73e1 100644 --- a/test/buffer-list.js +++ b/test/buffer-list.js @@ -9,7 +9,7 @@ p.add = function(buffer, front) { }; p.addInt16 = function(val, front) { - return this.add(Buffer([(val >>> 8),(val >>> 0)]),front); + return this.add(Buffer.from([(val >>> 8),(val >>> 0)]),front); }; p.getByteLength = function(initial) { @@ -19,7 +19,7 @@ p.getByteLength = function(initial) { }; p.addInt32 = function(val, first) { - return this.add(Buffer([ + return this.add(Buffer.from([ (val >>> 24 & 0xFF), (val >>> 16 & 0xFF), (val >>> 8 & 0xFF), @@ -29,14 +29,14 @@ p.addInt32 = function(val, first) { p.addCString = function(val, front) { var len = Buffer.byteLength(val); - var buffer = new Buffer(len+1); + var buffer = Buffer.alloc(len+1); buffer.write(val); buffer[len] = 0; return this.add(buffer, front); }; p.addChar = function(char, first) { - return this.add(Buffer(char,'utf8'), first); + return this.add(Buffer.from(char,'utf8'), first); }; p.join = function(appendLength, char) { @@ -49,7 +49,7 @@ p.join = function(appendLength, char) { this.addChar(char, true); length++; } - var result = Buffer(length); + var result = Buffer.alloc(length); var index = 0; this.buffers.forEach(function(buffer) { buffer.copy(result, index, 0); diff --git a/test/integration/client/query-as-promise-tests.js b/test/integration/client/query-as-promise-tests.js index 8dcdeb517..ac958729b 100644 --- a/test/integration/client/query-as-promise-tests.js +++ b/test/integration/client/query-as-promise-tests.js @@ -1,10 +1,5 @@ var helper = require(__dirname + '/../test-helper'); var pg = helper.pg; -var semver = require('semver') - -if (semver.lt(process.version, '0.12.0')) { - return console.log('promises are not supported in node < v0.10') -} process.on('unhandledRejection', function(e) { console.error(e, e.stack) diff --git a/test/integration/connection-pool/idle-timeout-tests.js b/test/integration/connection-pool/idle-timeout-tests.js index 0a60ce504..5a5db0ba9 100644 --- a/test/integration/connection-pool/idle-timeout-tests.js +++ b/test/integration/connection-pool/idle-timeout-tests.js @@ -1,7 +1,6 @@ var helper = require(__dirname + '/test-helper'); -var _ = require('lodash') -const config = _.extend({ }, helper.config, { idleTimeoutMillis: 50 }) +const config = Object.assign({ }, helper.config, { idleTimeoutMillis: 50 }) test('idle timeout', function() { helper.pg.connect(config, assert.calls(function(err, client, done) { diff --git a/test/integration/connection-pool/yield-support-body.js b/test/integration/connection-pool/yield-support-body.js deleted file mode 100644 index 943ab3a2e..000000000 --- a/test/integration/connection-pool/yield-support-body.js +++ /dev/null @@ -1,28 +0,0 @@ -var helper = require('./test-helper') -var co = require('co') - -var tid = setTimeout(function() { - throw new Error('Tests did not complete in time') -}, 1000) - -co(function * () { - var client = yield helper.pg.connect() - var res = yield client.query('SELECT $1::text as name', ['foo']) - assert.equal(res.rows[0].name, 'foo') - - var threw = false - try { - yield client.query('SELECT LKDSJDSLKFJ') - } catch(e) { - threw = true - } - assert(threw) - client.release() - helper.pg.end() - clearTimeout(tid) -}) -.catch(function(e) { - setImmediate(function() { - throw e - }) -}) diff --git a/test/integration/connection-pool/yield-support-tests.js b/test/integration/connection-pool/yield-support-tests.js index fb79ddc4c..943ab3a2e 100644 --- a/test/integration/connection-pool/yield-support-tests.js +++ b/test/integration/connection-pool/yield-support-tests.js @@ -1,5 +1,28 @@ -var semver = require('semver') -if (semver.lt(process.version, '1.0.0')) { - return console.log('yield is not supported in node <= v0.12') -} -require('./yield-support-body') +var helper = require('./test-helper') +var co = require('co') + +var tid = setTimeout(function() { + throw new Error('Tests did not complete in time') +}, 1000) + +co(function * () { + var client = yield helper.pg.connect() + var res = yield client.query('SELECT $1::text as name', ['foo']) + assert.equal(res.rows[0].name, 'foo') + + var threw = false + try { + yield client.query('SELECT LKDSJDSLKFJ') + } catch(e) { + threw = true + } + assert(threw) + client.release() + helper.pg.end() + clearTimeout(tid) +}) +.catch(function(e) { + setImmediate(function() { + throw e + }) +}) diff --git a/test/integration/gh-issues/675-tests.js b/test/integration/gh-issues/675-tests.js index f7d95427d..c27d3632b 100644 --- a/test/integration/gh-issues/675-tests.js +++ b/test/integration/gh-issues/675-tests.js @@ -11,11 +11,11 @@ helper.pg.connect(helper.config, function(err, client, done) { c = 'INSERT INTO posts (body) VALUES ($1) RETURNING *'; - var body = new Buffer('foo'); + var body = Buffer.from('foo'); client.query(c, [body], function(err) { if (err) throw err; - body = new Buffer([]); + body = Buffer.from([]); client.query(c, [body], function(err, res) { done(); diff --git a/test/test-buffers.js b/test/test-buffers.js index ddb6ba637..b16a7ab62 100644 --- a/test/test-buffers.js +++ b/test/test-buffers.js @@ -4,7 +4,7 @@ require(__dirname+'/test-helper'); var buffers = {}; buffers.readyForQuery = function() { return new BufferList() - .add(Buffer('I')) + .add(Buffer.from('I')) .join(true,'Z'); }; @@ -23,7 +23,7 @@ buffers.authenticationCleartextPassword = function() { buffers.authenticationMD5Password = function() { return new BufferList() .addInt32(5) - .add(Buffer([1,2,3,4])) + .add(Buffer.from([1,2,3,4])) .join(true, 'R'); }; @@ -71,7 +71,7 @@ buffers.dataRow = function(columns) { if(col == null) { buf.addInt32(-1); } else { - var strBuf = new Buffer(col, 'utf8'); + var strBuf = Buffer.from(col, 'utf8'); buf.addInt32(strBuf.length); buf.add(strBuf); } @@ -94,7 +94,7 @@ var errorOrNotice = function(fields) { buf.addChar(field.type); buf.addCString(field.value); }); - return buf.add(Buffer([0]));//terminator + return buf.add(Buffer.from([0]));//terminator } buffers.parseComplete = function() { diff --git a/test/test-helper.js b/test/test-helper.js index d8e068764..175cbbb9d 100644 --- a/test/test-helper.js +++ b/test/test-helper.js @@ -1,11 +1,6 @@ //make assert a global... assert = require('assert'); -//support for node@0.10.x -if (typeof Promise == 'undefined') { - global.Promise = require('promise-polyfill') -} - var EventEmitter = require('events').EventEmitter; var sys = require('util'); var BufferList = require(__dirname+'/buffer-list') diff --git a/test/unit/client/md5-password-tests.js b/test/unit/client/md5-password-tests.js index 3c5403685..315ef197b 100644 --- a/test/unit/client/md5-password-tests.js +++ b/test/unit/client/md5-password-tests.js @@ -3,7 +3,7 @@ require(__dirname + '/test-helper'); test('md5 authentication', function() { var client = createClient(); client.password = "!"; - var salt = Buffer([1, 2, 3, 4]); + var salt = Buffer.from([1, 2, 3, 4]); client.connection.emit('authenticationMD5Password', {salt: salt}); test('responds', function() { diff --git a/test/unit/connection/inbound-parser-tests.js b/test/unit/connection/inbound-parser-tests.js index a9910966b..2b822e440 100644 --- a/test/unit/connection/inbound-parser-tests.js +++ b/test/unit/connection/inbound-parser-tests.js @@ -158,7 +158,7 @@ test('Connection', function() { testForMessage(plainPasswordBuffer, expectedPlainPasswordMessage); var msg = testForMessage(md5PasswordBuffer, expectedMD5PasswordMessage); test('md5 has right salt', function() { - assert.equalBuffers(msg.salt, Buffer([1,2,3,4])); + assert.equalBuffers(msg.salt, Buffer.from([1,2,3,4])); }); testForMessage(paramStatusBuffer, expectedParameterStatusMessage); testForMessage(backendKeyDataBuffer, expectedBackendKeyDataMessage); @@ -173,7 +173,7 @@ test('Connection', function() { }); test("no data message", function() { - testForMessage(Buffer([0x6e, 0, 0, 0, 4]), { + testForMessage(Buffer.from([0x6e, 0, 0, 0, 4]), { name: 'noData' }); }); @@ -349,7 +349,7 @@ test('Connection', function() { }); test('parses replication start message', function() { - testForMessage(new Buffer([0x57, 0x00, 0x00, 0x00, 0x04]), { + testForMessage(Buffer.from([0x57, 0x00, 0x00, 0x00, 0x04]), { name: 'replicationStart', length: 4 }); @@ -383,8 +383,8 @@ test('split buffer, single message parsing', function() { }); var testMessageRecievedAfterSpiltAt = function(split) { - var firstBuffer = new Buffer(fullBuffer.length-split); - var secondBuffer = new Buffer(fullBuffer.length-firstBuffer.length); + var firstBuffer = Buffer.alloc(fullBuffer.length-split); + var secondBuffer = Buffer.alloc(fullBuffer.length-firstBuffer.length); fullBuffer.copy(firstBuffer, 0, 0); fullBuffer.copy(secondBuffer, 0, firstBuffer.length); stream.emit('data', firstBuffer); @@ -416,7 +416,7 @@ test('split buffer, single message parsing', function() { test('split buffer, multiple message parsing', function() { var dataRowBuffer = buffers.dataRow(['!']); var readyForQueryBuffer = buffers.readyForQuery(); - var fullBuffer = new Buffer(dataRowBuffer.length + readyForQueryBuffer.length); + var fullBuffer = Buffer.alloc(dataRowBuffer.length + readyForQueryBuffer.length); dataRowBuffer.copy(fullBuffer, 0, 0); readyForQueryBuffer.copy(fullBuffer, dataRowBuffer.length, 0); @@ -449,8 +449,8 @@ test('split buffer, multiple message parsing', function() { verifyMessages(); }); var splitAndVerifyTwoMessages = function(split) { - var firstBuffer = new Buffer(fullBuffer.length-split); - var secondBuffer = new Buffer(fullBuffer.length-firstBuffer.length); + var firstBuffer = Buffer.alloc(fullBuffer.length-split); + var secondBuffer = Buffer.alloc(fullBuffer.length-firstBuffer.length); fullBuffer.copy(firstBuffer, 0, 0); fullBuffer.copy(secondBuffer, 0, firstBuffer.length); stream.emit('data', firstBuffer); diff --git a/test/unit/connection/outbound-sending-tests.js b/test/unit/connection/outbound-sending-tests.js index 3dde8a3cb..353c073bf 100644 --- a/test/unit/connection/outbound-sending-tests.js +++ b/test/unit/connection/outbound-sending-tests.js @@ -104,12 +104,12 @@ test('bind messages', function() { .addInt16(0) .addInt16(4) .addInt32(1) - .add(Buffer("1")) + .add(Buffer.from("1")) .addInt32(2) - .add(Buffer("hi")) + .add(Buffer.from("hi")) .addInt32(-1) .addInt32(4) - .add(Buffer('zing')) + .add(Buffer.from('zing')) .addInt16(0) .join(true, 'B'); assert.received(stream, expectedBuffer); @@ -120,7 +120,7 @@ test('with named statement, portal, and buffer value', function() { con.bind({ portal: 'bang', statement: 'woo', - values: ['1', 'hi', null, new Buffer('zing', 'UTF-8')] + values: ['1', 'hi', null, Buffer.from('zing', 'utf8')] }); var expectedBuffer = new BufferList() .addCString('bang') //portal name @@ -132,12 +132,12 @@ test('with named statement, portal, and buffer value', function() { .addInt16(1)//binary .addInt16(4) .addInt32(1) - .add(Buffer("1")) + .add(Buffer.from("1")) .addInt32(2) - .add(Buffer("hi")) + .add(Buffer.from("hi")) .addInt32(-1) .addInt32(4) - .add(new Buffer('zing', 'UTF-8')) + .add(Buffer.from('zing', 'UTF-8')) .addInt16(0) .join(true, 'B'); assert.received(stream, expectedBuffer); @@ -181,7 +181,7 @@ test('sends sync command', function() { test('sends end command', function() { con.end(); - var expected = new Buffer([0x58, 0, 0, 0, 4]); + var expected = Buffer.from([0x58, 0, 0, 0, 4]); assert.received(stream, expected); }); diff --git a/test/unit/utils-tests.js b/test/unit/utils-tests.js index d640f9880..82b11715a 100644 --- a/test/unit/utils-tests.js +++ b/test/unit/utils-tests.js @@ -50,7 +50,7 @@ test('normalizing query configs', function() { }) test('prepareValues: buffer prepared properly', function() { - var buf = new Buffer("quack"); + var buf = Buffer.from("quack"); var out = utils.prepareValue(buf); assert.strictEqual(buf, out); }); @@ -142,7 +142,7 @@ test('prepareValue: objects with simple toPostgres prepared properly', function( }); test('prepareValue: objects with complex toPostgres prepared properly', function() { - var buf = new Buffer("zomgcustom!"); + var buf = Buffer.from("zomgcustom!"); var customType = { toPostgres: function() { return [1, 2]; @@ -165,7 +165,7 @@ test('prepareValue: objects with toPostgres receive prepareValue', function() { }); test('prepareValue: objects with circular toPostgres rejected', function() { - var buf = new Buffer("zomgcustom!"); + var buf = Buffer.from("zomgcustom!"); var customType = { toPostgres: function() { return { toPostgres: function () { return customType; } };