Skip to content

Commit

Permalink
Merge pull request #15 from mobilusoss/issue-14
Browse files Browse the repository at this point in the history
close #14
  • Loading branch information
mohemohe authored Nov 13, 2019
2 parents 8fc03c8 + bbccb8e commit 7b6c1b7
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 40 deletions.
2 changes: 1 addition & 1 deletion lib/app/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ module.exports = function(sails) {
function loadHookDefinitions(hooks, cb) {

// Mix in user-configured hook definitions
_.extend(hooks, sails.config.hooks);
_.assignIn(hooks, sails.config.hooks);

// Make sure these changes to the hooks object get applied
// to sails.config.hooks to keep logic consistent
Expand Down
8 changes: 4 additions & 4 deletions lib/app/private/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ module.exports = function inspect () {
'Tip: Use `sails.config` to access your app\'s runtime configuration.'+
'\n\n' +
util.format('%d Models:\n', _(sails.models).toArray().value().length) +
_(sails.models).toArray().filter(function (it) {return !it.junctionTable;}).pluck('globalId').value() +
_(sails.models).toArray().filter(function (it) {return !it.junctionTable;}).map('globalId').value() +
'\n\n' +
util.format('%d Controllers:\n', _(sails.controllers).toArray().value().length)+
_(sails.controllers).toArray().pluck('globalId').map(function (it) {return it+'Controller';}).value() +
_(sails.controllers).toArray().map('globalId').map(function (it) {return it+'Controller';}).value() +
'\n\n' +
// 'Routes:\n'+
// _(sails.routes).toArray().filter(function (it) {return !it.junctionTable;}).pluck('globalId').map(function (it) {return it+'Controller';}).value() +
// _(sails.routes).toArray().filter(function (it) {return !it.junctionTable;}).map('globalId').map(function (it) {return it+'Controller';}).value() +
// '\n\n' +
util.format('%d Hooks:\n', _(sails.hooks).toArray().value().length)+
_(sails.hooks).toArray().pluck('identity').value() +
_(sails.hooks).toArray().map('identity').value() +
'\n' +
'';
};
8 changes: 7 additions & 1 deletion lib/hooks/blueprints/actionUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ var actionUtil = {
where = _.omit(where, function(p) {
if (isUndefined(p)) {return true;}
});
// values = _.filter(values, function(p) {
// return !isUndefined(p);
// });

// Omit jsonp callback param (but only if jsonp is enabled)
var jsonpOpts = req.options.jsonp && !req.isSocket;
Expand Down Expand Up @@ -297,7 +300,7 @@ var actionUtil = {
var valuesArray = _.map(bodyData, function(element){
var values;
// Merge properties of the element into req.options.value, omitting the blacklist
values = mergeDefaults(element, _.omit(req.options.values, 'blacklist'));
values = mergeDefaults(element, _.omit(req.options.values, ['blacklist']));
// Omit properties that are in the blacklist (like query modifiers)
values = _.omit(values, blacklist || []);
// Omit any properties w/ undefined values
Expand All @@ -306,6 +309,9 @@ var actionUtil = {
return true;
}
});
// values = _.filter(values, function(p) {
// return !isUndefined(p);
// });

return values;
});
Expand Down
4 changes: 2 additions & 2 deletions lib/hooks/blueprints/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ module.exports = function(sails) {
// options for req.options
var _bindRoute = function (path, action, options) {
options = options || routeOpts;
options = _.extend({}, options, {action: action, controller: controllerId});
options = _.assignIn({}, options, {action: action, controller: controllerId});
sails.router.bind ( path, _getAction(action), null, options);

};
Expand Down Expand Up @@ -411,7 +411,7 @@ module.exports = function(sails) {

// Merge custom overrides from our app into the BlueprintController
// in Sails core.
_.extend(BlueprintController, modules);
_.assignIn(BlueprintController, modules);

// Add _middlewareType keys to the functions, for debugging
_.each(BlueprintController, function(fn, key) {
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/blueprints/onRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = function(sails) {
_.isString(target.blueprint)) {

// On a match, merge leftover items in the target object into route options:
options = _.merge(options, _.omit(target, 'blueprint'));
options = _.merge(options, _.omit(target, ['blueprint']));
// Note: this (^) could be moved up into lib/router/bind.js, since its
// only pertinent for core options such as `skipAssets`. There would need
// to be changes in other hooks as well.
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/cors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module.exports = function(sails) {

// Else if cors is set to a string, use that has the origin
else if (typeof config.cors === 'string') {
optionsRouteConfigs[path][verb || 'default'] = _.extend({origin: config.cors},{methods: verb});
optionsRouteConfigs[path][verb || 'default'] = _.assignIn({origin: config.cors},{methods: verb});
sails.router.bind(route, prepareSendHeaders({origin:config.cors}), null);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/csrf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = function(sails) {
}
};
// Add the csrfToken directly to the config'd routes, so that the CORS hook can process it
sails.config.routes = _.extend(csrfRoute, sails.config.routes);
sails.config.routes = _.assignIn(csrfRoute, sails.config.routes);
},

initialize: function(cb) {
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/http/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = function(sails) {

// Merge SSL into server options
var serverOptions = sails.config.http.serverOptions || {};
_.extend(serverOptions, sails.config.ssl);
_.assignIn(serverOptions, sails.config.ssl);

// Lodash 3's _.merge attempts to transform buffers into arrays;
// so if we detect an array, then transform it back into a buffer.
Expand Down
10 changes: 5 additions & 5 deletions lib/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ module.exports = function(sails) {
definition = _normalize(definition);

// Merge default definition with overrides in the definition passed in
_.extend(definition.config, this.config, definition.config);
_.extend(definition.middleware, this.middleware, definition.middleware);
_.extend(definition.routes.before, this.routes.before, definition.routes.before);
_.extend(definition.routes.after, this.routes.after, definition.routes.after);
_.extend(this, definition);
_.assignIn(definition.config, this.config, definition.config);
_.assignIn(definition.middleware, this.middleware, definition.middleware);
_.assignIn(definition.routes.before, this.routes.before, definition.routes.before);
_.assignIn(definition.routes.after, this.routes.after, definition.routes.after);
_.assignIn(this, definition);

// Bind context of new methods from definition
_.bindAll(this);
Expand Down
10 changes: 5 additions & 5 deletions lib/hooks/moduleloader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ module.exports = function(sails) {
configure: function() {
if (sails.config.moduleLoaderOverride) {
var override = sails.config.moduleLoaderOverride(sails, this);
_.extend(this, override);
_.assignIn(this, override);
if (override.configure) {
this.configure();
}
}
sails.config.appPath = sails.config.appPath ? path.resolve(sails.config.appPath) : process.cwd();

_.extend(sails.config.paths, {
_.assignIn(sails.config.paths, {

// Configuration
//
Expand Down Expand Up @@ -379,7 +379,7 @@ module.exports = function(sails) {
} catch (e) { return cb(e); }

// Finally, send back the merged-together set of adapters.
return cb(undefined, _.extend(classicStyleAdapters, folderStyleAdapters));
return cb(undefined, _.assignIn(classicStyleAdapters, folderStyleAdapters));

});//</fs.readdir>
});//</includeall.optional>
Expand Down Expand Up @@ -559,7 +559,7 @@ module.exports = function(sails) {

try {

_.extend(hooks, _.reduce(results.nodeModulesFolder, function(memo, module, identity) {
_.assignIn(hooks, _.reduce(results.nodeModulesFolder, function(memo, module, identity) {

// Hooks loaded from "node_modules" need to have "sails.isHook: true" in order for us
// to know that they are a sails hook
Expand Down Expand Up @@ -615,7 +615,7 @@ module.exports = function(sails) {
memo[hookName] = hook;
}
return memo;
}, {}));//</_.reduce() + _.extend()>
}, {}));//</_.reduce() + _.assignIn()>

return bindToSails(cb)(null, hooks);

Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/policies/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = function(sails) {
sails.log.verbose('Loading policy modules from app...');
sails.modules.loadPolicies(function modulesLoaded (err, modules) {
if (err) { return cb(err); }
_.extend(this.middleware, modules);
_.assignIn(this.middleware, modules);

return cb();
}.bind(this));
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/request/locals.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function _mixinLocals(req, res) {
// passed in here, to improve the optimizations
// of Express's production view cache.

_.extend(res.locals, {
_.assignIn(res.locals, {
_: _,
util: util,
session: req.session,
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module.exports = function (sails) {
}

// Expose services on `sails.services` to provide access even when globals are disabled.
_.extend(sails.services, modules);
_.assignIn(sails.services, modules);

// Expose globals (if enabled)
if (sails.config.globals.services) {
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/userhooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = function(sails) {
hooks = _.isObject(hooks) ? hooks : {};

// Add the user hooks to the list of hooks to load
_.extend(sails.hooks, hooks);
_.assignIn(sails.hooks, hooks);

return cb();

Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/views/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module.exports = function (sails) {

// Set the options for the view rendering engine. Copy all the current options into 'locals'
// in case the template engine expects them there.
_.extend(options, {
_.assignIn(options, {
locals: _.cloneDeep(options),
settings: {
'view engine': sails.config.views.engine.ext,
Expand Down
4 changes: 2 additions & 2 deletions lib/hooks/views/res.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ module.exports = function _addResViewMethod(req, res, next) {
if (sails.hooks.csrf && !_.isNull(res.locals._csrf)) {
relevantLocals._csrf = res.locals._csrf;
}
relevantLocals = _.extend(relevantLocals, locals);
relevantLocals = _.assignIn(relevantLocals, locals);

// We also filter out the `_locals` key.
// (TODO: could look into doing this longer term as an optimization-
Expand Down Expand Up @@ -300,7 +300,7 @@ module.exports = function _addResViewMethod(req, res, next) {
// Enhance the raw Express view error object
// (this error appears when a view is missing)
if (_.isObject(err) && err.view) {
err = _.extend({
err = _.assignIn({
message: util.format(
'Could not render view "%s". Tried locating view file @ "%s".%s',
relPathToView,
Expand Down
2 changes: 1 addition & 1 deletion lib/router/bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function bind( /* path, target, verb, options */ ) {
// of the keys as route options and then bind the target.
else if (_.isPlainObject(target) && (target.target || target.fn)) {
var _target = target.target || target.fn;
options = _.merge(options, _.omit(target, 'target'));
options = _.merge(options, _.omit(target, ['target']));
bind.apply(this, [path, _target, verb, options]);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion lib/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ function bodyParser (req, res, next) {

var bodyBuffer='';
if (req.method === 'GET' || req.method === 'HEAD' || req.method === 'DELETE'){
req.body = _.extend({}, req.body);
req.body = _.assignIn({}, req.body);
return next();
}

Expand Down
18 changes: 9 additions & 9 deletions lib/router/res.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ module.exports = function _buildResponse (req, _res) {


// Ensure res.headers and res.locals exist.
res = _.extend(res, {locals: {}, headers: {}, _headers: {}});
res = _.extend(res, _res);
res = _.assignIn(res, {locals: {}, headers: {}, _headers: {}});
res = _.assignIn(res, _res);

// Now that we're sure `res` is a Transform stream, we'll handle the two different
// approaches which a user of the virtual request interpreter might have taken:
Expand Down Expand Up @@ -108,14 +108,14 @@ module.exports = function _buildResponse (req, _res) {
res.statusCode = statusCode;

// Ensure `._headers` have been merged into `.headers`
_.extend(res.headers, res._headers);
_.assignIn(res.headers, res._headers);

if (newHeaders) {
if (!_.isObject(newHeaders)) {
throw new Error('`headers` must be passed to res.writeHead() as an object. Got: '+util.inspect(newHeaders, false, null));
}
// Set new headers
_.extend(res.headers, newHeaders);
_.assignIn(res.headers, newHeaders);
}

// Set status code and headers on the `_clientRes` stream so they are accessible
Expand All @@ -133,15 +133,15 @@ module.exports = function _buildResponse (req, _res) {
// Wrap res.write() and res.end() to get them to call writeHead()
var prevWrite = res.write;
res.write = function (){
res.writeHead(res.statusCode, _.extend(res._headers,res.headers));
// console.log('res.write():: called writeHead with headers=',_.extend(res._headers,res.headers));
res.writeHead(res.statusCode, _.assignIn(res._headers,res.headers));
// console.log('res.write():: called writeHead with headers=',_.assignIn(res._headers,res.headers));
prevWrite.apply(res, Array.prototype.slice.call(arguments));
};
var prevEnd = res.end;
res.end = function (){
res.writeHead(res.statusCode, _.extend(res._headers,res.headers));
res.writeHead(res.statusCode, _.assignIn(res._headers,res.headers));
// console.log('our res.end() was triggered');
// console.log('res.end():: called writeHead with headers=',_.extend(res._headers,res.headers));
// console.log('res.end():: called writeHead with headers=',_.assignIn(res._headers,res.headers));
prevEnd.apply(res, Array.prototype.slice.call(arguments));
};

Expand Down Expand Up @@ -188,7 +188,7 @@ module.exports = function _buildResponse (req, _res) {
res.charset = res.charset || 'utf-8';

// Ensure headers are set
_.extend(res.headers, res._headers);
_.assignIn(res.headers, res._headers);

// Ensure statusCode is set
// (override `this.statusCode` if `statusCode` argument specified)
Expand Down

0 comments on commit 7b6c1b7

Please sign in to comment.