From 5231b0cb27be58a6ec394579f776ab2c8a8c3790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 12 Jun 2018 16:30:15 +0200 Subject: [PATCH 1/7] Drop support for Node 4.x Node 4.x is no longer maintained by Node.js project. --- .travis.yml | 1 - package.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1d0ad98..c35f26e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ sudo: false language: node_js node_js: - - "4" - "6" diff --git a/package.json b/package.json index 526ce04..9f8d475 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "4.4.0", "description": "Building blocks for LoopBack connectors", "engines": { - "node": ">=4" + "node": ">=6" }, "keywords": [ "StrongLoop", From ffc06e3ce100474cc0154ad9d04d3453a9972561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 12 Jun 2018 16:31:02 +0200 Subject: [PATCH 2/7] Travis: add Node.js 8.x + 10.x to the build matrix --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index c35f26e..c60f507 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,3 +2,5 @@ sudo: false language: node_js node_js: - "6" + - "8" + - "10" From 9f18837ec61a8b4e2ff8c7e46418dad7a9c1f738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 12 Jun 2018 16:31:40 +0200 Subject: [PATCH 3/7] Disable package-lock feature of npm --- .npmrc | 1 + 1 file changed, 1 insertion(+) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false From a695cb22e1c9101dce0cb1742f456edaa462f55c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 12 Jun 2018 16:33:52 +0200 Subject: [PATCH 4/7] Update eslint + config to latest --- lib/sql.js | 40 +++++++++++------------ package.json | 4 +-- test/transaction.test.js | 70 ++++++++++++++++++++-------------------- 3 files changed, 57 insertions(+), 57 deletions(-) diff --git a/lib/sql.js b/lib/sql.js index 20790ed..46e71c3 100644 --- a/lib/sql.js +++ b/lib/sql.js @@ -167,7 +167,7 @@ SQLConnector.prototype.addPropertyToActual = function(model, propName) { var sqlCommand = self.columnEscaped(model, propName) + ' ' + self.columnDataType(model, propName) + (self.isNullable(self.getPropertyDefinition(model, propName)) ? - '' : ' NOT NULL'); + '' : ' NOT NULL'); return sqlCommand; }; @@ -631,17 +631,17 @@ SQLConnector.prototype.execute = function(sql, params, options, callback) { }; this.notifyObserversAround('execute', context, function(context, done) { self.executeSQL(context.req.sql, context.req.params, context.options, - function(err, info) { - if (err) { - debug('Error: %j %j %j', err, context.req.sql, context.req.params); - } + function(err, info) { + if (err) { + debug('Error: %j %j %j', err, context.req.sql, context.req.params); + } - if (!err && info != null) { - context.res = info; - } - // Don't pass more than one args as it will confuse async.waterfall - done(err, info); - }); + if (!err && info != null) { + context.res = info; + } + // Don't pass more than one args as it will confuse async.waterfall + done(err, info); + }); }, callback); }; @@ -816,7 +816,7 @@ SQLConnector.prototype.updateAttributes = function(model, id, data, options, cb) function errorIdNotFoundForUpdate(idValue) { var msg = g.f( - 'Could not update attributes. {{Object}} with {{id}} %s does not exist!', idValue); + 'Could not update attributes. {{Object}} with {{id}} %s does not exist!', idValue); var error = new Error(msg); error.statusCode = error.status = 404; return error; @@ -1784,8 +1784,8 @@ SQLConnector.prototype.discoverDatabaseSchemas = function(options, cb) { * @param options {all: for all owners, owner: for a given owner} * @returns {string} The sql statement */ - // Due to the different implementation structure of information_schema across - // connectors, each connector will have to generate its own query +// Due to the different implementation structure of information_schema across +// connectors, each connector will have to generate its own query SQLConnector.prototype.buildQueryTables = function(options) { throw new Error(g.f('{{buildQueryTables}} must be implemented by the connector')); }; @@ -1795,8 +1795,8 @@ SQLConnector.prototype.buildQueryTables = function(options) { * @param options {all: for all owners, owner: for a given owner} * @returns {string} The sql statement */ - // Due to the different implementation structure of information_schema across - // connectors, each connector will have to generate its own query +// Due to the different implementation structure of information_schema across +// connectors, each connector will have to generate its own query SQLConnector.prototype.buildQueryViews = function(options) { throw new Error(g.f('{{buildQueryViews}} must be implemented by the connector')); }; @@ -1946,8 +1946,8 @@ SQLConnector.prototype.discoverPrimaryKeys = function(table, options, cb) { * @param table * @returns {string} */ - // Due to the different implementation structure of information_schema across - // connectors, each connector will have to generate its own query +// Due to the different implementation structure of information_schema across +// connectors, each connector will have to generate its own query SQLConnector.prototype.buildQueryForeignKeys = function(schema, table) { throw new Error(g.f('{{buildQueryForeignKeys}} must be implemented by the connector')); }; @@ -1982,8 +1982,8 @@ SQLConnector.prototype.discoverForeignKeys = function(table, options, cb) { * @param table * @returns {string} */ - // Due to the different implementation structure of information_schema across - // connectors, each connector will have to generate its own query +// Due to the different implementation structure of information_schema across +// connectors, each connector will have to generate its own query SQLConnector.prototype.buildQueryExportedForeignKeys = function(schema, table) { throw new Error(g.f('{{buildQueryExportedForeignKeys}} must be implemented by' + 'the connector')); diff --git a/package.json b/package.json index 9f8d475..18d4e98 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,8 @@ }, "devDependencies": { "chai": "~3.5.0", - "eslint": "^3.17.1", - "eslint-config-loopback": "^8.0.0", + "eslint": "^4.19.1", + "eslint-config-loopback": "^10.0.0", "loopback-datasource-juggler": "^3.12.0", "mocha": "^3.2.0" } diff --git a/test/transaction.test.js b/test/transaction.test.js index 3e254dc..4fdc069 100644 --- a/test/transaction.test.js +++ b/test/transaction.test.js @@ -41,42 +41,42 @@ describe('transactions', function() { isolationLevel: Transaction.READ_COMMITTED, timeout: timeout, }, - function(err, tx) { - if (err) return done(err); - expect(typeof tx.id).to.eql('string'); - hooks = []; - tx.observe('before commit', function(context, next) { - hooks.push('before commit'); - next(); - }); - tx.observe('after commit', function(context, next) { - hooks.push('after commit'); - next(); - }); - tx.observe('before rollback', function(context, next) { - hooks.push('before rollback'); - next(); - }); - tx.observe('after rollback', function(context, next) { - hooks.push('after rollback'); - next(); - }); - currentTx = tx; - Post.create(post, {transaction: tx, model: 'Post'}, - function(err, p) { - if (err) { - done(err); - } else { - p.reviews.create({ - author: 'John', - content: 'Review for ' + p.title, - }, {transaction: tx, model: 'Review'}, - function(err, c) { - done(err); - }); - } - }); + function(err, tx) { + if (err) return done(err); + expect(typeof tx.id).to.eql('string'); + hooks = []; + tx.observe('before commit', function(context, next) { + hooks.push('before commit'); + next(); }); + tx.observe('after commit', function(context, next) { + hooks.push('after commit'); + next(); + }); + tx.observe('before rollback', function(context, next) { + hooks.push('before rollback'); + next(); + }); + tx.observe('after rollback', function(context, next) { + hooks.push('after rollback'); + next(); + }); + currentTx = tx; + Post.create(post, {transaction: tx, model: 'Post'}, + function(err, p) { + if (err) { + done(err); + } else { + p.reviews.create({ + author: 'John', + content: 'Review for ' + p.title, + }, {transaction: tx, model: 'Review'}, + function(err, c) { + done(err); + }); + } + }); + }); }; } From 284e0111b75bb5eaa101ed86e3f2a600cb3ee942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 12 Jun 2018 16:44:24 +0200 Subject: [PATCH 5/7] Update Mocha and Chai to latest --- package.json | 4 ++-- test/transaction.test.js | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 18d4e98..99f05a3 100644 --- a/package.json +++ b/package.json @@ -30,10 +30,10 @@ "uuid": "^3.0.1" }, "devDependencies": { - "chai": "~3.5.0", + "chai": "^4.1.2", "eslint": "^4.19.1", "eslint-config-loopback": "^10.0.0", "loopback-datasource-juggler": "^3.12.0", - "mocha": "^3.2.0" + "mocha": "^5.2.0" } } diff --git a/test/transaction.test.js b/test/transaction.test.js index 4fdc069..9ce4d88 100644 --- a/test/transaction.test.js +++ b/test/transaction.test.js @@ -173,24 +173,26 @@ describe('transactions', function() { }); describe('timeout', function() { + const TIMEOUT = 50; before(function() { // Reset the collection db.connector.data = {}; }); var post = {title: 't3', content: 'c3'}; - before(createPostInTx(post, 50)); + beforeEach(createPostInTx(post, TIMEOUT)); it('should report timeout', function(done) { - setTimeout(function() { + // wait until the "create post" transaction times out + setTimeout(runTheTest, TIMEOUT * 3); + + function runTheTest() { Post.find({where: {title: 't3'}}, {transaction: currentTx}, function(err, posts) { - if (err) return done(err); - expect(posts.length).to.be.eql(1); + expect(err).to.match(/transaction.*not active/); done(); }); - }, 300); - done(); + } }); it('should invoke the timeout hook', function(done) { @@ -198,6 +200,10 @@ describe('transactions', function() { next(); done(); }); + + // If the event is not fired quickly enough, then the test can + // quickly fail - no need to wait full two seconds (Mocha's default) + this.timeout(TIMEOUT * 3); }); }); From 9c44ec59c396345f62b93d8296b50878d373c050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 12 Jun 2018 16:44:59 +0200 Subject: [PATCH 6/7] Update strong-globalize to 4.x --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 99f05a3..1e3cc2f 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "bluebird": "^3.4.6", "debug": "^3.1.0", "msgpack5": "^3.4.1", - "strong-globalize": "^3.1.0", + "strong-globalize": "^4.1.1", "uuid": "^3.0.1" }, "devDependencies": { From 9435ba50713d9f0029cb5b99e38e31a7a5a39a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 12 Jun 2018 16:49:36 +0200 Subject: [PATCH 7/7] Update msgpack5 to 4.x This adds support for Timestamp extension type: https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1e3cc2f..89fa25c 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "async": "^2.1.5", "bluebird": "^3.4.6", "debug": "^3.1.0", - "msgpack5": "^3.4.1", + "msgpack5": "^4.2.0", "strong-globalize": "^4.1.1", "uuid": "^3.0.1" },