From 4ebf10ae0d513e2df499503b148e855510d63329 Mon Sep 17 00:00:00 2001 From: Rob Halff Date: Fri, 17 Oct 2014 00:54:40 +0200 Subject: [PATCH 1/6] add missing semicolons --- lib/access-context.js | 24 +++---- lib/application.js | 44 ++++++------- lib/connectors/base-connector.js | 12 ++-- lib/connectors/mail.js | 14 ++-- lib/connectors/memory.js | 4 +- lib/middleware/status.js | 4 +- lib/middleware/token.js | 14 ++-- lib/middleware/urlNotFound.js | 2 +- lib/model.js | 106 +++++++++++++++---------------- lib/persisted-model.js | 76 +++++++++++----------- 10 files changed, 150 insertions(+), 150 deletions(-) diff --git a/lib/access-context.js b/lib/access-context.js index acbe9495..e2d52ebb 100644 --- a/lib/access-context.js +++ b/lib/access-context.js @@ -39,15 +39,15 @@ function AccessContext(context) { this.sharedMethod = context.sharedMethod; this.sharedClass = this.sharedMethod && this.sharedMethod.sharedClass; if(this.sharedMethod) { - this.methodNames = this.sharedMethod.aliases.concat([this.sharedMethod.name]); + this.methodNames = this.sharedMethod.aliases.concat([this.sharedMethod.name]); } else { this.methodNames = []; } - + if(this.sharedMethod) { - this.accessType = this.model._getAccessTypeForMethod(this.sharedMethod); + this.accessType = this.model._getAccessTypeForMethod(this.sharedMethod); } - + this.accessType = context.accessType || AccessContext.ALL; assert(loopback.AccessToken, 'AccessToken model must be defined before AccessContext model'); @@ -157,9 +157,9 @@ AccessContext.prototype.debug = function() { if(debug.enabled) { debug('---AccessContext---'); if(this.principals && this.principals.length) { - debug('principals:') + debug('principals:'); this.principals.forEach(function(principal) { - debug('principal: %j', principal) + debug('principal: %j', principal); }); } else { debug('principals: %j', this.principals); @@ -170,14 +170,14 @@ AccessContext.prototype.debug = function() { debug('method %s', this.method); debug('accessType %s', this.accessType); if(this.accessToken) { - debug('accessToken:') + debug('accessToken:'); debug(' id %j', this.accessToken.id); debug(' ttl %j', this.accessToken.ttl); } debug('getUserId() %s', this.getUserId()); debug('isAuthenticated() %s', this.isAuthenticated()); } -} +}; /** * This class represents the abstract notion of a principal, which can be used @@ -273,17 +273,17 @@ AccessRequest.prototype.exactlyMatches = function(acl) { } return false; -} +}; /** * Is the request for access allowed? - * + * * @returns {Boolean} */ AccessRequest.prototype.isAllowed = function() { return this.permission !== loopback.ACL.DENY; -} +}; AccessRequest.prototype.debug = function() { if(debug.enabled) { @@ -295,7 +295,7 @@ AccessRequest.prototype.debug = function() { debug(' isWildcard() %s', this.isWildcard()); debug(' isAllowed() %s', this.isAllowed()); } -} +}; module.exports.AccessContext = AccessContext; module.exports.Principal = Principal; diff --git a/lib/application.js b/lib/application.js index 8c1fc2fd..91fc35ed 100644 --- a/lib/application.js +++ b/lib/application.js @@ -14,22 +14,22 @@ var DataSource = require('loopback-datasource-juggler').DataSource /** * The `App` object represents a Loopback application. - * + * * The App object extends [Express](http://expressjs.com/api.html#express) and * supports Express middleware. See * [Express documentation](http://expressjs.com/) for details. - * + * * ```js * var loopback = require('loopback'); * var app = loopback(); - * + * * app.get('/', function(req, res){ * res.send('hello world'); * }); - * + * * app.listen(3000); * ``` - * + * * @class LoopBackApplication * @header var app = loopback() */ @@ -59,10 +59,10 @@ app.remotes = function () { if(this.get) { options = this.get('remoting'); } - + return (this._remotes = RemoteObjects.create(options)); } -} +}; /*! * Remove a route by reference. @@ -76,7 +76,7 @@ app.disuse = function (route) { } } } -} +}; /** * Attach a model to the app. The `Model` will be available on the @@ -92,7 +92,7 @@ app.disuse = function (route) { * var User = loopback.User; * app.model(User, { dataSource: 'db' }); *``` - * + * * @param {Object|String} Model The model to attach. * @options {Object} config The model's configuration. * @property {String|DataSource} dataSource The `DataSource` to which to attach the model. @@ -207,7 +207,7 @@ app.model = function (Model, config) { app.models = function () { return this._models || (this._models = []); -} +}; /** * Define a DataSource. @@ -221,7 +221,7 @@ app.dataSource = function (name, config) { this.dataSources[classify(name)] = this.dataSources[camelize(name)] = ds; return ds; -} +}; /** * Register a connector. @@ -254,30 +254,30 @@ app.remoteObjects = function () { this.remotes().classes().forEach(function(sharedClass) { result[sharedClass.name] = sharedClass.ctor; }); - + return result; -} +}; /*! * Get a handler of the specified type from the handler cache. - * @triggers `mounted` events on shared class constructors (models) + * @triggers `mounted` events on shared class constructors (models) */ - + app.handler = function (type, options) { var handlers = this._handlers || (this._handlers = {}); if(handlers[type]) { return handlers[type]; } - + var remotes = this.remotes(); var handler = this._handlers[type] = remotes.handler(type, options); - + remotes.classes().forEach(function(sharedClass) { sharedClass.ctor.emit('mounted', app, sharedClass, remotes); }); - + return handler; -} +}; /** * An object to store dataSource instances. @@ -342,7 +342,7 @@ app.enableAuth = function() { app.boot = function(options) { throw new Error( '`app.boot` was removed, use the new module loopback-boot instead'); -} +}; function classify(str) { return stringUtils.classify(str); @@ -355,7 +355,7 @@ function camelize(str) { function dataSourcesFromConfig(config, connectorRegistry) { var connectorPath; - assert(typeof config === 'object', + assert(typeof config === 'object', 'cannont create data source without config object'); if(typeof config.connector === 'string') { @@ -469,4 +469,4 @@ app.listen = function(cb) { } return server; -} +}; diff --git a/lib/connectors/base-connector.js b/lib/connectors/base-connector.js index 75ee55a2..d5381a1f 100644 --- a/lib/connectors/base-connector.js +++ b/lib/connectors/base-connector.js @@ -7,13 +7,13 @@ module.exports = Connector; /** * Module dependencies. */ - + var EventEmitter = require('events').EventEmitter , debug = require('debug')('connector') , util = require('util') , inherits = util.inherits , assert = require('assert'); - + /** * Create a new `Connector` with the given `options`. * @@ -24,7 +24,7 @@ var EventEmitter = require('events').EventEmitter function Connector(options) { EventEmitter.apply(this, arguments); this.options = options; - + debug('created with options', options); } @@ -43,12 +43,12 @@ Connector._createJDBAdapter = function (jdbModule) { jdbModule.initialize(fauxSchema, function () { // connected }); -} +}; /*! * Add default crud operations from a JugglingDB adapter. */ Connector.prototype._addCrudOperationsFromJDBAdapter = function (connector) { - -} + +}; diff --git a/lib/connectors/mail.js b/lib/connectors/mail.js index 71706010..18157a8d 100644 --- a/lib/connectors/mail.js +++ b/lib/connectors/mail.js @@ -5,7 +5,7 @@ var mailer = require('nodemailer') , assert = require('assert') , debug = require('debug')('loopback:connector:mail') - , loopback = require('../loopback') + , loopback = require('../loopback'); /** * Export the MailConnector class. @@ -44,7 +44,7 @@ function MailConnector(settings) { MailConnector.initialize = function(dataSource, callback) { dataSource.connector = new MailConnector(dataSource.settings); callback(); -} +}; MailConnector.prototype.DataAccessObject = Mailer; @@ -86,7 +86,7 @@ MailConnector.prototype.setupTransport = function(setting) { connector.transportsIndex[setting.type] = transport; connector.transports.push(transport); -} +}; function Mailer() { @@ -101,7 +101,7 @@ function Mailer() { MailConnector.prototype.transportForName = function(name) { return this.transportsIndex[name]; -} +}; /** * Get the default transport. @@ -111,7 +111,7 @@ MailConnector.prototype.transportForName = function(name) { MailConnector.prototype.defaultTransport = function() { return this.transports[0] || this.stubTransport; -} +}; /** * Send an email with the given `options`. @@ -166,7 +166,7 @@ Mailer.send = function (options, fn) { fn(null, options); }); } -} +}; /** * Send an email instance using `modelInstance.send()`. @@ -174,7 +174,7 @@ Mailer.send = function (options, fn) { Mailer.prototype.send = function (fn) { this.constructor.send(this, fn); -} +}; /** * Access the node mailer object. diff --git a/lib/connectors/memory.js b/lib/connectors/memory.js index 08f2a2f6..ddd00fb7 100644 --- a/lib/connectors/memory.js +++ b/lib/connectors/memory.js @@ -7,14 +7,14 @@ module.exports = Memory; /** * Module dependencies. */ - + var Connector = require('./base-connector') , debug = require('debug')('memory') , util = require('util') , inherits = util.inherits , assert = require('assert') , JdbMemory = require('loopback-datasource-juggler/lib/connectors/memory'); - + /** * Create a new `Memory` connector with the given `options`. * diff --git a/lib/middleware/status.js b/lib/middleware/status.js index 085c5975..c90f5efc 100644 --- a/lib/middleware/status.js +++ b/lib/middleware/status.js @@ -14,7 +14,7 @@ module.exports = status; * "uptime": 9.394 * } * ``` - * + * * @header loopback.status() */ function status() { @@ -25,6 +25,6 @@ function status() { started: started, uptime: (Date.now() - Number(started)) / 1000 }); - } + }; } diff --git a/lib/middleware/token.js b/lib/middleware/token.js index 541300f1..659c9550 100644 --- a/lib/middleware/token.js +++ b/lib/middleware/token.js @@ -11,22 +11,22 @@ var assert = require('assert'); module.exports = token; -/** +/** * Check for an access token in cookies, headers, and query string parameters. * This function always checks for the following: - * + * * - `access_token` (params only) * - `X-Access-Token` (headers only) * - `authorization` (headers and cookies) * * It checks for these values in cookies, headers, and query string parameters _in addition_ to the items * specified in the options parameter. - * + * * **NOTE:** This function only checks for [signed cookies](http://expressjs.com/api.html#req.signedCookies). - * + * * The following example illustrates how to check for an `accessToken` in a custom cookie, query string parameter * and header called `foo-auth`. - * + * * ```js * app.use(loopback.token({ * cookies: ['foo-auth'], @@ -47,13 +47,13 @@ function token(options) { options = options || {}; var TokenModel = options.model || loopback.AccessToken; assert(TokenModel, 'loopback.token() middleware requires a AccessToken model'); - + return function (req, res, next) { if (req.accessToken !== undefined) return next(); TokenModel.findForRequest(req, options, function(err, token) { req.accessToken = token || null; next(err); }); - } + }; } diff --git a/lib/middleware/urlNotFound.js b/lib/middleware/urlNotFound.js index a73f6804..dd696d79 100644 --- a/lib/middleware/urlNotFound.js +++ b/lib/middleware/urlNotFound.js @@ -15,5 +15,5 @@ function urlNotFound() { var error = new Error('Cannot ' + req.method + ' ' + req.url); error.status = 404; next(error); - } + }; } diff --git a/lib/model.js b/lib/model.js index d2b459ff..2ff0009c 100644 --- a/lib/model.js +++ b/lib/model.js @@ -9,7 +9,7 @@ var extend = require('util')._extend; var stringUtils = require('underscore.string'); /** - * The base class for **all models**. + * The base class for **all models**. * * **Inheriting from `Model`** * @@ -18,7 +18,7 @@ var stringUtils = require('underscore.string'); * var options = {...}; * var MyModel = loopback.Model.extend('MyModel', properties, options); * ``` - * + * * **Options** * * - `trackChanges` - If true, changes to the model will be tracked. **Required @@ -27,7 +27,7 @@ var stringUtils = require('underscore.string'); * **Events** * * #### Event: `changed` - * + * * Emitted after a model has been successfully created, saved, or updated. * Argument: `inst`, model instance, object * @@ -37,10 +37,10 @@ var stringUtils = require('underscore.string'); * // => model with id 1 has been changed * }); * ``` - * + * * #### Event: `deleted` - * - * Emitted after an individual model has been deleted. + * + * Emitted after an individual model has been deleted. * Argument: `id`, model ID (number). * * ```js @@ -51,7 +51,7 @@ var stringUtils = require('underscore.string'); * ``` * * #### Event: `deletedAll` - * + * * Emitted after an individual model has been deleted. * Argument: `where` (optional), where filter, JSON object. * @@ -65,27 +65,27 @@ var stringUtils = require('underscore.string'); * } * }); * ``` - * + * * #### Event: `attached` - * + * * Emitted after a `Model` has been attached to an `app`. - * + * * #### Event: `dataSourceAttached` - * + * * Emitted after a `Model` has been attached to a `DataSource`. - * + * * #### Event: set - * + * * Emitted when model property is set. * Argument: `inst`, model instance, object - * + * * ```js * MyModel.on('set', function(inst) { * console.log('model with id %s has been changed', inst.id); * // => model with id 1 has been changed * }); * ``` - * + * * @param {Object} data * @property {String} modelName The name of the model. Static property. * @property {DataSource} dataSource Data source to which the model is connected, if any. Static property. @@ -128,7 +128,7 @@ Model.setup = function () { id = null; } else if (typeof id === 'function') { fn = id; - + if(typeof data !== 'object') { id = data; data = null; @@ -136,7 +136,7 @@ Model.setup = function () { id = null; } } - + if(id && data) { var model = new ModelCtor(data); model.id = id; @@ -152,14 +152,14 @@ Model.setup = function () { } else { err = new Error('could not find a model with id ' + id); err.statusCode = 404; - + fn(err); } }); } else { fn(new Error('must specify an id or data')); } - } + }; var idDesc = ModelCtor.modelName + ' id'; ModelCtor.sharedCtor.accepts = [ @@ -171,7 +171,7 @@ Model.setup = function () { ModelCtor.sharedCtor.http = [ {path: '/:id'} ]; - + ModelCtor.sharedCtor.returns = {root: true}; // before remote hook @@ -190,7 +190,7 @@ Model.setup = function () { }); } }; - + // after remote hook ModelCtor.afterRemote = function (name, fn) { var self = this; @@ -280,7 +280,7 @@ Model.checkAccess = function(token, modelId, sharedMethod, ctx, callback) { callback = ctx; ctx = {}; } - + aclModel.checkAccessForContext({ accessToken: token, model: this, @@ -308,7 +308,7 @@ Model._getAccessTypeForMethod = function(method) { method = {name: method}; } assert( - typeof method === 'object', + typeof method === 'object', 'method is a required argument and must be a RemoteMethod object' ); @@ -340,7 +340,7 @@ Model._getAccessTypeForMethod = function(method) { default: return ACL.EXECUTE; } -} +}; /** * Get the `Application` the Model is attached to. @@ -361,7 +361,7 @@ Model.getApp = function(callback) { callback(null, Model.app); }); } -} +}; /** * Enable remote invocation for the method with the given name. @@ -382,7 +382,7 @@ Model.remoteMethod = function(name, options) { options.isStatic = true; } this.sharedClass.defineMethod(name, options); -} +}; /** * Disable remote invocation for the method with the given name. @@ -395,7 +395,7 @@ Model.remoteMethod = function(name, options) { Model.disableRemoteMethod = function(name, isStatic) { this.sharedClass.disableMethod(name, isStatic || false); -} +}; Model.belongsToRemoting = function(relationName, relation, define) { var modelName = relation.modelTo && relation.modelTo.modelName; @@ -409,7 +409,7 @@ Model.belongsToRemoting = function(relationName, relation, define) { description: 'Fetches belongsTo relation ' + relationName, returns: {arg: relationName, type: modelName, root: true} }, fn); -} +}; Model.hasOneRemoting = function(relationName, relation, define) { var fn = this.prototype[relationName]; @@ -421,22 +421,22 @@ Model.hasOneRemoting = function(relationName, relation, define) { description: 'Fetches hasOne relation ' + relationName, returns: {arg: relationName, type: relation.modelTo.modelName, root: true} }, fn); -} +}; Model.hasManyRemoting = function (relationName, relation, define) { var pathName = (relation.options.http && relation.options.http.path) || relationName; var toModelName = relation.modelTo.modelName; - + function convertNullToNotFoundError(ctx, cb) { if (ctx.result !== null) return cb(); - + var fk = ctx.getArgByName('fk'); var msg = 'Unknown "' + toModelName + '" id "' + fk + '".'; var error = new Error(msg); error.statusCode = error.status = 404; cb(error); } - + var findByIdFunc = this.prototype['__findById__' + relationName]; define('__findById__' + relationName, { isStatic: false, @@ -568,9 +568,9 @@ Model.scopeRemoting = function(scopeName, scope, define) { http: {verb: 'get', path: '/' + pathName + '/count'}, accepts: {arg: 'where', type: 'object', description: 'Criteria to match model instances'}, description: 'Counts ' + scopeName + ' of ' + this.modelName + '.', - returns: {arg: 'count', type: 'number'} + returns: {arg: 'count', type: 'number'} }); - + }; Model.nestRemoting = function(relationName, options, cb) { @@ -579,7 +579,7 @@ Model.nestRemoting = function(relationName, options, cb) { options = {}; } options = options || {}; - + var regExp = /^__([^_]+)__([^_]+)$/; var relation = this.relations[relationName]; if (relation && relation.modelTo && relation.modelTo.sharedClass) { @@ -587,17 +587,17 @@ Model.nestRemoting = function(relationName, options, cb) { var sharedClass = this.sharedClass; var sharedToClass = relation.modelTo.sharedClass; var toModelName = relation.modelTo.modelName; - + var pathName = options.pathName || relation.options.path || relationName; var paramName = options.paramName || 'nk'; - + var http = [].concat(sharedToClass.http || [])[0]; - + if (relation.multiple) { var httpPath = pathName + '/:' + paramName; var acceptArgs = [ - { - arg: paramName, type: 'any', http: { source: 'path' }, + { + arg: paramName, type: 'any', http: { source: 'path' }, description: 'Foreign key for ' + relation.name, required: true } @@ -606,7 +606,7 @@ Model.nestRemoting = function(relationName, options, cb) { var httpPath = pathName; var acceptArgs = []; } - + // A method should return the method name to use, if it is to be // included as a nested method - a falsy return value will skip. var filter = cb || options.filterMethod || function(method, relation) { @@ -615,31 +615,31 @@ Model.nestRemoting = function(relationName, options, cb) { return '__' + matches[1] + '__' + relation.name + '__' + matches[2]; } }; - + sharedToClass.methods().forEach(function(method) { var methodName; if (!method.isStatic && (methodName = filter(method, relation))) { var prefix = relation.multiple ? '__findById__' : '__get__'; var getterName = options.getterName || (prefix + relationName); - + var getterFn = relation.modelFrom.prototype[getterName]; if (typeof getterFn !== 'function') { throw new Error('Invalid remote method: `' + getterName + '`'); } - + var nestedFn = relation.modelTo.prototype[method.name]; if (typeof nestedFn !== 'function') { throw new Error('Invalid remote method: `' + method.name + '`'); } - + var opts = {}; - + opts.accepts = acceptArgs.concat(method.accepts || []); opts.returns = [].concat(method.returns || []); opts.description = method.description; opts.rest = extend({}, method.rest || {}); opts.rest.delegateTo = method.name; - + opts.http = []; var routes = [].concat(method.http || []); routes.forEach(function(route) { @@ -649,7 +649,7 @@ Model.nestRemoting = function(relationName, options, cb) { opts.http.push(copy); } }); - + if (relation.multiple) { sharedClass.defineMethod(methodName, opts, function(fkId) { var args = Array.prototype.slice.call(arguments, 1); @@ -681,17 +681,17 @@ Model.nestRemoting = function(relationName, options, cb) { } } }); - + if (options.hooks === false) return; // don't inherit before/after hooks - + self.once('mounted', function(app, sc, remotes) { var listenerTree = extend({}, remotes.listenerTree || {}); listenerTree.before = listenerTree.before || {}; listenerTree.after = listenerTree.after || {}; - + var beforeListeners = remotes.listenerTree.before[toModelName] || {}; var afterListeners = remotes.listenerTree.after[toModelName] || {}; - + sharedClass.methods().forEach(function(method) { var delegateTo = method.rest && method.rest.delegateTo; if (delegateTo) { @@ -711,7 +711,7 @@ Model.nestRemoting = function(relationName, options, cb) { } }); }); - + } else { throw new Error('Relation `' + relationName + '` does not exist for model `' + this.modelName + '`'); } diff --git a/lib/persisted-model.js b/lib/persisted-model.js index 6140e899..97599516 100644 --- a/lib/persisted-model.js +++ b/lib/persisted-model.js @@ -43,9 +43,9 @@ PersistedModel.setup = function setupPersistedModel() { PersistedModel.enableChangeTracking(); }); } - + PersistedModel.setupRemoting(); -} +}; /*! * Throw an error telling the user that the method is not available and why. @@ -260,7 +260,7 @@ PersistedModel.destroyById = function deleteById(id, cb) { /** * Alias for destroyById. */ -PersistedModel.removeById = PersistedModel.destroyById +PersistedModel.removeById = PersistedModel.destroyById; /** * Alias for destroyById. @@ -338,7 +338,7 @@ PersistedModel.prototype.save = function (options, callback) { // then save function save() { inst.trigger('save', function (saveDone) { - inst.trigger('update', function (updateDone) { + inst.trigger('update', function (updateDone) { Model.upsert(inst, function(err) { inst._initProperties(data); updateDone.call(inst, function () { @@ -430,7 +430,7 @@ PersistedModel.prototype.reload = function reload(callback) { PersistedModel.prototype.setId = function(val) { var ds = this.getDataSource(); this[this.getIdName()] = val; -} +}; /** * Get the `id` value for the `PersistedModel`. @@ -442,7 +442,7 @@ PersistedModel.prototype.getId = function() { var data = this.toObject(); if(!data) return; return data[this.getIdName()]; -} +}; /** * Get the id property name of the constructor. @@ -452,7 +452,7 @@ PersistedModel.prototype.getId = function() { PersistedModel.prototype.getIdName = function() { return this.constructor.getIdName(); -} +}; /** * Get the id property name of the constructor. @@ -469,7 +469,7 @@ PersistedModel.getIdName = function() { } else { return 'id'; } -} +}; PersistedModel.setupRemoting = function() { var PersistedModel = this; @@ -597,7 +597,7 @@ PersistedModel.setupRemoting = function() { {arg: 'since', type: 'number', description: 'Find deltas since this checkpoint'}, {arg: 'remoteChanges', type: 'array', description: 'an array of change objects', http: {source: 'body'}} - ], + ], returns: {arg: 'result', type: 'object', root: true}, http: {verb: 'post', path: '/diff'} }); @@ -612,7 +612,7 @@ PersistedModel.setupRemoting = function() { returns: {arg: 'changes', type: 'array', root: true}, http: {verb: 'get', path: '/changes'} }); - + setRemoting(PersistedModel, 'checkpoint', { description: 'Create a checkpoint.', returns: {arg: 'checkpoint', type: 'object', root: true}, @@ -649,22 +649,22 @@ PersistedModel.setupRemoting = function() { http: {verb: 'post', path: '/:id/rectify-change'} }); } -} +}; /** * Get a set of deltas and conflicts since the given checkpoint. * * See `Change.diff()` for details. - * + * * @param {Number} since Find deltas since this checkpoint * @param {Array} remoteChanges An array of change objects - * @param {Function} callback + * @param {Function} callback */ PersistedModel.diff = function(since, remoteChanges, callback) { var Change = this.getChangeModel(); Change.diff(this.modelName, since, remoteChanges, callback); -} +}; /** * Get the changes to a model since a given checkpoint. Provide a filter object @@ -720,11 +720,11 @@ PersistedModel.changes = function(since, filter, callback) { })); }); }); -} +}; /** * Create a checkpoint. - * + * * @param {Function} callback */ @@ -736,11 +736,11 @@ PersistedModel.checkpoint = function(cb) { sourceId: sourceId }, cb); }); -} +}; /** * Get the current checkpoint id. - * + * * @callback {Function} callback * @param {Error} err * @param {Number} currentCheckpointId @@ -750,7 +750,7 @@ PersistedModel.checkpoint = function(cb) { PersistedModel.currentCheckpoint = function(cb) { var Checkpoint = this.getChangeModel().getCheckpointModel(); Checkpoint.current(cb); -} +}; /** * Replicate changes since the given checkpoint to the given target model. @@ -793,7 +793,7 @@ PersistedModel.replicate = function(since, targetModel, options, callback) { callback = callback || function defaultReplicationCallback(err) { if(err) throw err; - } + }; var tasks = [ getSourceChanges, @@ -848,13 +848,13 @@ PersistedModel.replicate = function(since, targetModel, options, callback) { callback && callback(null, conflicts); } -} +}; /** * Create an update list (for `Model.bulkUpdate()`) from a delta list * (result of `Change.diff()`). - * - * @param {Array} deltas + * + * @param {Array} deltas * @param {Function} callback */ @@ -899,13 +899,13 @@ PersistedModel.createUpdates = function(deltas, cb) { if(err) return cb(err); cb(null, updates); }); -} +}; /** * Apply an update list. * * **Note: this is not atomic** - * + * * @param {Array} updates An updates list (usually from Model.createUpdates()) * @param {Function} callback */ @@ -937,11 +937,11 @@ PersistedModel.bulkUpdate = function(updates, callback) { }); async.parallel(tasks, callback); -} +}; /** * Get the `Change` model. - * + * * @throws {Error} Throws an error if the change model is not correctly setup. * @return {Change} */ @@ -953,11 +953,11 @@ PersistedModel.getChangeModel = function() { assert(isSetup, 'Cannot get a setup Change model'); return changeModel; -} +}; /** * Get the source identifier for this model / dataSource. - * + * * @callback {Function} callback * @param {Error} err * @param {String} sourceId @@ -969,12 +969,12 @@ PersistedModel.getSourceId = function(cb) { this.once('dataSourceAttached', this.getSourceId.bind(this, cb)); } assert( - dataSource.connector.name, + dataSource.connector.name, 'Model.getSourceId: cannot get id without dataSource.connector.name' ); var id = [dataSource.connector.name, this.modelName].join('-'); cb(null, id); -} +}; /** * Enable the tracking of changes made to the model. Usually for replication. @@ -993,11 +993,11 @@ PersistedModel.enableChangeTracking = function() { Model.afterSave = function afterSave(next) { Model.rectifyChange(this.getId(), next); - } + }; Model.afterDestroy = function afterDestroy(next) { Model.rectifyChange(this.getId(), next); - } + }; Model.on('deletedAll', cleanup); @@ -1017,7 +1017,7 @@ PersistedModel.enableChangeTracking = function() { }); } } -} +}; PersistedModel._defineChangeModel = function() { var BaseChangeModel = registry.getModel('Change'); @@ -1030,11 +1030,11 @@ PersistedModel._defineChangeModel = function() { trackModel: this } ); -} +}; PersistedModel.rectifyAllChanges = function(callback) { this.getChangeModel().rectifyAll(callback); -} +}; /** * Handle a change error. Override this method in a subclassing model to customize @@ -1048,7 +1048,7 @@ PersistedModel.handleChangeError = function(err) { console.error(Model.modelName + ' Change Tracking Error:'); console.error(err); } -} +}; /** * Tell loopback that a change to the model with the given id has occurred. @@ -1061,6 +1061,6 @@ PersistedModel.handleChangeError = function(err) { PersistedModel.rectifyChange = function(id, callback) { var Change = this.getChangeModel(); Change.rectifyModelChanges(this.modelName, [id], callback); -} +}; PersistedModel.setup(); From 12d27768242936686364cdaf086368ffd7f90874 Mon Sep 17 00:00:00 2001 From: Rob Halff Date: Fri, 17 Oct 2014 01:14:00 +0200 Subject: [PATCH 2/6] allow comma first style and increase line length --- .jshintrc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.jshintrc b/.jshintrc index c8c31032..d9f8a8ab 100644 --- a/.jshintrc +++ b/.jshintrc @@ -5,8 +5,9 @@ "indent": 2, "undef": true, "quotmark": "single", -"maxlen": 80, +"maxlen": 150, "trailing": true, "newcap": true, -"nonew": true +"nonew": true, +"laxcomma": true } From 34f1aa354bf2a2c93f32d2fdf87c7b6d5374f604 Mon Sep 17 00:00:00 2001 From: Rob Halff Date: Fri, 17 Oct 2014 01:16:27 +0200 Subject: [PATCH 3/6] split jshint task for test & lib --- Gruntfile.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 09aa93fe..26e4feb7 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -30,8 +30,11 @@ module.exports = function(grunt) { gruntfile: { src: 'Gruntfile.js' }, - lib_test: { - src: ['lib/**/*.js', 'test/**/*.js'] + lib: { + src: ['lib/**/*.js'] + }, + test: { + src: ['test/**/*.js'] } }, watch: { @@ -39,9 +42,13 @@ module.exports = function(grunt) { files: '<%= jshint.gruntfile.src %>', tasks: ['jshint:gruntfile'] }, - lib_test: { - files: '<%= jshint.lib_test.src %>', - tasks: ['jshint:lib_test'] + lib: { + files: ['<%= jshint.lib.src %>'], + tasks: ['jshint:lib'] + }, + test: { + files: ['<%= jshint.test.src %>'], + tasks: ['jshint:test'] } }, browserify: { @@ -104,7 +111,7 @@ module.exports = function(grunt) { // list of files to exclude exclude: [ - + ], // test results reporter to use From 84b4fea666823bbd4e55b9df694c059be9942293 Mon Sep 17 00:00:00 2001 From: Rob Halff Date: Fri, 17 Oct 2014 01:17:38 +0200 Subject: [PATCH 4/6] use singlequotes --- lib/express-middleware.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/express-middleware.js b/lib/express-middleware.js index bc316769..5e79142b 100644 --- a/lib/express-middleware.js +++ b/lib/express-middleware.js @@ -20,20 +20,20 @@ function createMiddlewareNotInstalled(memberName, moduleName) { } var middlewareModules = { - "compress": "compression", - "timeout": "connect-timeout", - "cookieParser": "cookie-parser", - "cookieSession": "cookie-session", - "csrf": "csurf", - "errorHandler": "errorhandler", - "session": "express-session", - "methodOverride": "method-override", - "logger": "morgan", - "responseTime": "response-time", - "favicon": "serve-favicon", - "directory": "serve-index", - // "static": "serve-static", - "vhost": "vhost" + 'compress': 'compression', + 'timeout': 'connect-timeout', + 'cookieParser': 'cookie-parser', + 'cookieSession': 'cookie-session', + 'csrf': 'csurf', + 'errorHandler': 'errorhandler', + 'session': 'express-session', + 'methodOverride': 'method-override', + 'logger': 'morgan', + 'responseTime': 'response-time', + 'favicon': 'serve-favicon', + 'directory': 'serve-index', + // 'static': 'serve-static', + 'vhost': 'vhost' }; middlewares.bodyParser = safeRequire('body-parser'); From 027f25a22fda4d8c5dd3f2b08f9c3266ffc70ee1 Mon Sep 17 00:00:00 2001 From: Rob Halff Date: Fri, 17 Oct 2014 01:35:02 +0200 Subject: [PATCH 5/6] add laxbreak option --- .jshintrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.jshintrc b/.jshintrc index d9f8a8ab..91fb46ef 100644 --- a/.jshintrc +++ b/.jshintrc @@ -9,5 +9,6 @@ "trailing": true, "newcap": true, "nonew": true, -"laxcomma": true +"laxcomma": true, +"laxbreak": true } From b54c70c348c2b5b4a8bed5432195e9d06026ff96 Mon Sep 17 00:00:00 2001 From: Rob Halff Date: Fri, 17 Oct 2014 01:40:04 +0200 Subject: [PATCH 6/6] Use === to compare with 0 --- lib/application.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/application.js b/lib/application.js index 91fc35ed..4387b411 100644 --- a/lib/application.js +++ b/lib/application.js @@ -459,7 +459,7 @@ app.listen = function(cb) { }); var useAppConfig = - arguments.length == 0 || + arguments.length === 0 || (arguments.length == 1 && typeof arguments[0] == 'function'); if (useAppConfig) {