From eb5ef04b6a3989e5877ed88378a18b8748d8f440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 21 Jul 2014 16:56:46 +0200 Subject: [PATCH] Remove `loopback.compat.usePluralNamesForRemoting` The `usePluralNamesForRemoting` was added in January 2014 for users upgrading from LoopBack 1.5 or older. --- lib/application.js | 1 - lib/compat.js | 56 ---------------------------------------- lib/connectors/remote.js | 1 - lib/loopback.js | 5 ---- lib/models/model.js | 7 +++-- test/app.test.js | 22 ---------------- test/model.test.js | 31 ---------------------- 7 files changed, 3 insertions(+), 120 deletions(-) delete mode 100644 lib/compat.js diff --git a/lib/application.js b/lib/application.js index 7ccfcbb0..97bb1989 100644 --- a/lib/application.js +++ b/lib/application.js @@ -4,7 +4,6 @@ var DataSource = require('loopback-datasource-juggler').DataSource , registry = require('./registry') - , compat = require('./compat') , assert = require('assert') , fs = require('fs') , extend = require('util')._extend diff --git a/lib/compat.js b/lib/compat.js deleted file mode 100644 index 9fe324f7..00000000 --- a/lib/compat.js +++ /dev/null @@ -1,56 +0,0 @@ -var assert = require('assert'); - -/** - * Compatibility layer allowing applications based on an older LoopBack version - * to work with newer versions with minimum changes involved. - * - * You should not use it unless migrating from an older version of LoopBack. - */ - -var compat = exports; - -/** - * LoopBack versions pre-1.6 use plural model names when registering shared - * classes with strong-remoting. As the result, strong-remoting use method names - * like `Users.create` for the javascript methods like `User.create`. - * This has been fixed in v1.6, LoopBack consistently uses the singular - * form now. - * - * Turn this option on to enable the old behaviour. - * - * - `app.remotes()` and `app.remoteObjects()` will be indexed using - * plural names (Users instead of User). - * - * - Remote hooks must use plural names for the class name, i.e - * `Users.create` instead of `User.create`. This is transparently - * handled by `Model.beforeRemote()` and `Model.afterRemote()`. - * - * @type {boolean} - * @deprecated Your application should not depend on the way how loopback models - * and strong-remoting are wired together. It if does, you should update - * it to use singular model names. - */ - -compat.usePluralNamesForRemoting = false; - -/** - * Get the class name to use with strong-remoting. - * @param {function} Ctor Model class (constructor), e.g. `User` - * @return {string} Singular or plural name, depending on the value - * of `compat.usePluralNamesForRemoting` - * @internal - */ - -compat.getClassNameForRemoting = function(Ctor) { - assert( - typeof(Ctor) === 'function', - 'compat.getClassNameForRemoting expects a constructor as the argument'); - - if (compat.usePluralNamesForRemoting) { - assert(Ctor.pluralModelName, - 'Model must have a "pluralModelName" property in compat mode'); - return Ctor.pluralModelName; - } - - return Ctor.modelName; -}; diff --git a/lib/connectors/remote.js b/lib/connectors/remote.js index 31b93273..26beb4a5 100644 --- a/lib/connectors/remote.js +++ b/lib/connectors/remote.js @@ -4,7 +4,6 @@ var assert = require('assert'); var remoting = require('strong-remoting'); -var compat = require('../compat'); var DataAccessObject = require('loopback-datasource-juggler/lib/dao'); /** diff --git a/lib/loopback.js b/lib/loopback.js index 40eca19c..1b8168f7 100644 --- a/lib/loopback.js +++ b/lib/loopback.js @@ -38,11 +38,6 @@ loopback.version = require('../package.json').version; loopback.mime = express.mime; -/*! - * Compatibility layer, intentionally left undocumented. - */ -loopback.compat = require('./compat'); - /*! * Create an loopback application. * diff --git a/lib/models/model.js b/lib/models/model.js index 6fa5c312..6893e325 100644 --- a/lib/models/model.js +++ b/lib/models/model.js @@ -2,7 +2,6 @@ * Module Dependencies. */ var registry = require('../registry'); -var compat = require('../compat'); var assert = require('assert'); var SharedClass = require('strong-remoting').SharedClass; @@ -87,7 +86,7 @@ Model.setup = function () { // create a sharedClass var sharedClass = ModelCtor.sharedClass = new SharedClass( - compat.getClassNameForRemoting(ModelCtor), + ModelCtor.modelName, ModelCtor, options.remoting ); @@ -152,7 +151,7 @@ Model.setup = function () { var self = this; if(this.app) { var remotes = this.app.remotes(); - var className = compat.getClassNameForRemoting(self); + var className = self.modelName; remotes.before(className + '.' + name, function (ctx, next) { fn(ctx, ctx.result, next); }); @@ -169,7 +168,7 @@ Model.setup = function () { var self = this; if(this.app) { var remotes = this.app.remotes(); - var className = compat.getClassNameForRemoting(self); + var className = self.modelName; remotes.after(className + '.' + name, function (ctx, next) { fn(ctx, ctx.result, next); }); diff --git a/test/app.test.js b/test/app.test.js index 5c7b62cd..8bed1cb2 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -57,28 +57,6 @@ describe('app', function() { request(app).get('/colors').expect(200, done); }); }); - - describe('in compat mode', function() { - before(function() { - loopback.compat.usePluralNamesForRemoting = true; - }); - after(function() { - loopback.compat.usePluralNamesForRemoting = false; - }); - - it('uses plural name as shared class name', function() { - var Color = db.createModel('color', {name: String}); - app.model(Color); - var classes = app.remotes().classes().map(function(c) {return c.name}); - expect(classes).to.contain('colors'); - }); - - it('uses plural name as app.remoteObjects() key', function() { - var Color = db.createModel('color', {name: String}); - app.model(Color); - expect(app.remoteObjects()).to.eql({ colors: Color }); - }); - }); }); describe('app.model(name, config)', function () { diff --git a/test/model.test.js b/test/model.test.js index 145f0185..3c544875 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -270,37 +270,6 @@ describe.onServer('Remote Methods', function(){ }); }) - describe('in compat mode', function() { - before(function() { - loopback.compat.usePluralNamesForRemoting = true; - }); - after(function() { - loopback.compat.usePluralNamesForRemoting = false; - }); - - it('correctly install before/after hooks', function(done) { - var hooksCalled = []; - - User.beforeRemote('**', function(ctx, user, next) { - hooksCalled.push('beforeRemote'); - next(); - }); - - User.afterRemote('**', function(ctx, user, next) { - hooksCalled.push('afterRemote'); - next(); - }); - - request(app).get('/users') - .expect(200, function(err, res) { - if (err) return done(err); - expect(hooksCalled, 'hooks called') - .to.eql(['beforeRemote', 'afterRemote']); - done(); - }); - }); - }); - describe('Model.hasMany(Model)', function() { it("Define a one to many relationship", function(done) { var Book = dataSource.createModel('book', {title: String, author: String});