sails
Advanced tools
Comparing version 1.0.2 to 1.0.3-0
@@ -92,4 +92,10 @@ /** | ||
routes: {}, | ||
middleware: {} | ||
middleware: {}, | ||
// Set implicit default for sniffing tactic. | ||
// Respected by helpers, actions, shell scripts, certain Waterline | ||
// methods like .transaction(), and the `initialize` function in hooks. | ||
// implementationSniffingTactic: 'analogOrClassical' | ||
// ^^ TODO: actually set this | ||
}; | ||
@@ -96,0 +102,0 @@ }; |
@@ -5,5 +5,6 @@ /** | ||
var util = require('util'); | ||
var STRIP_COMMENTS_RX = /(\/\/.*$)|(\/\*[\s\S]*?\*\/)|(\s*=[^,\)]*(('(?:\\'|[^'\r\n])*')|("(?:\\"|[^"\r\n])*"))|(\s*=[^,\)]*))/mg; | ||
/** | ||
@@ -47,7 +48,7 @@ * runBootstrap() | ||
var timer = setTimeout(function bootstrapTookTooLong() { | ||
sails.log.warn(util.format( | ||
'Bootstrap is taking a while to execute its callback (%d milliseconds).\n'+ | ||
'If this is unexpected, maybe double-check it\'s getting called.\n'+ | ||
'https://sailsjs.com/config/bootstrap', | ||
timeoutMs)); | ||
sails.log.warn( | ||
'Bootstrap is taking a while to finish ('+timeoutMs+' milliseconds).\n'+ | ||
'If this is unexpected, and if the bootstrap function uses a callback,\n'+ | ||
'maybe double-check to be sure that callback is getting called.\n'+ | ||
' [?] Read more: https://sailsjs.com/config/bootstrap'); | ||
}, timeoutMs); | ||
@@ -58,7 +59,24 @@ | ||
try { | ||
var seemsToExpectCallback = true; | ||
if (sails.config.implementationSniffingTactic === 'analogOrClassical') { | ||
var hasParameters = (function(fn){ | ||
var fnStr = fn.toString().replace(STRIP_COMMENTS_RX, ''); | ||
var parametersAsString = fnStr.slice(fnStr.indexOf('(')+1, fnStr.indexOf(')')); | ||
// console.log('::',parametersAsString, parametersAsString.replace(/\s*/g,'').length); | ||
return parametersAsString.replace(/\s*/g,'').length !== 0; | ||
})(sails.config.bootstrap);//† | ||
seemsToExpectCallback = hasParameters; | ||
} | ||
if (sails.config.bootstrap.constructor.name === 'AsyncFunction') { | ||
var promise = sails.config.bootstrap(proceed); | ||
// Note that here, we don't write in the usual `return done(e)` style. | ||
// This is deliberate -- to provide a conspicuous reminder that we aren't | ||
// trying to get up to any funny business with the promise chain. | ||
var promise; | ||
if (seemsToExpectCallback) { | ||
promise = sails.config.bootstrap(proceed); | ||
} else { | ||
promise = sails.config.bootstrap(function(unusedErr){ | ||
proceed(new Error('Unexpected attempt to invoke callback. Since this "bootstrap" function does not appear to expect a callback parameter, this stub callback was provided instead. Please either explicitly list the callback parameter among the arguments or change this code to no longer use a callback.')); | ||
}) | ||
.then(function(){ | ||
proceed(); | ||
}); | ||
}//fi | ||
promise.catch(function(e) { | ||
@@ -71,3 +89,10 @@ proceed(e); | ||
else { | ||
sails.config.bootstrap(proceed); | ||
if (seemsToExpectCallback) { | ||
sails.config.bootstrap(proceed); | ||
} else { | ||
sails.config.bootstrap(function(unusedErr){ | ||
proceed(new Error('Unexpected attempt to invoke callback. Since this "bootstrap" function does not appear to expect a callback parameter, this stub callback was provided instead. Please either explicitly list the callback parameter among the arguments or change this code to no longer use a callback.')); | ||
}); | ||
return proceed(); | ||
} | ||
} | ||
@@ -74,0 +99,0 @@ } catch (e) { return proceed(e); } |
@@ -60,4 +60,7 @@ /** | ||
else { | ||
try { | ||
actions[identity] = machineAsAction(action); | ||
actions[identity] = machineAsAction(_.extend({ | ||
implementationSniffingTactic: sails.config.implementationSniffingTactic||undefined, | ||
}, action)); | ||
} | ||
@@ -64,0 +67,0 @@ // If a machine couldn't be built from the action, bail. |
@@ -29,8 +29,9 @@ /** | ||
helpers: { | ||
// Custom usage options: | ||
// Custom usage/miscellaneous options: | ||
usageOpts: { | ||
arginStyle: 'serial', | ||
execStyle: 'natural', | ||
execStyle: 'natural' | ||
}, | ||
// Experimental: Programmatically provide a dictionary of helpers. | ||
@@ -407,5 +408,10 @@ moduleDefinitions: undefined, | ||
} else { | ||
sails.helpers[machine.getMethodName(identity)] = machine.buildWithCustomUsage(_.extend({ | ||
def: nmDef | ||
}, sails.config.helpers.usageOpts)); | ||
sails.helpers[machine.getMethodName(identity)] = machine.buildWithCustomUsage(_.extend( | ||
{}, | ||
sails.config.helpers.usageOpts, | ||
{ | ||
def: nmDef, | ||
implementationSniffingTactic: sails.config.implementationSniffingTactic | ||
} | ||
)); | ||
} | ||
@@ -412,0 +418,0 @@ |
@@ -8,6 +8,6 @@ /** | ||
var async = require('async'); | ||
var STRIP_COMMENTS_RX = /(\/\/.*$)|(\/\*[\s\S]*?\*\/)|(\s*=[^,\)]*(('(?:\\'|[^'\r\n])*')|("(?:\\"|[^"\r\n])*"))|(\s*=[^,\)]*))/mg; | ||
module.exports = function(sails) { | ||
@@ -24,4 +24,6 @@ | ||
// Flag to indicate whether or not this hook's `initialize` function is asynchronous (i.e. declared with `async`). | ||
// Flags to indicate whether or not this hook's `initialize` function is asynchronous (i.e. declared with `async`) | ||
// and whether or not it has any parameters. | ||
var hasAsyncInit; | ||
var initSeemsToExpectParameters; | ||
@@ -95,9 +97,22 @@ // A few sanity checks to make sure te provided definition does not contain any reserved properties. | ||
// console.log(self.identity, self.initialize.toString()); | ||
try { | ||
// console.log(self.identity, self.initialize.toString()); | ||
var seemsToExpectCallback = true; | ||
if (sails.config.implementationSniffingTactic === 'analogOrClassical') { | ||
seemsToExpectCallback = initSeemsToExpectParameters; | ||
// (TODO: also locate and update relevant error messages) | ||
} | ||
if (hasAsyncInit) { | ||
var promise = self.initialize(cb); | ||
// Note that here, we don't write in the usual `return done(e)` style. | ||
// This is deliberate -- to provide a conspicuous reminder that we aren't | ||
// trying to get up to any funny business with the promise chain. | ||
var promise; | ||
if (seemsToExpectCallback) { | ||
promise = self.initialize(cb); | ||
} else { | ||
promise = self.initialize(function(unusedErr){ | ||
cb(new Error('Unexpected attempt to invoke callback. Since this "initialize" function does not appear to expect a callback parameter, this stub callback was provided instead. Please either explicitly list the callback parameter among the arguments or change this code to no longer use a callback.')); | ||
}) | ||
.then(function(){ | ||
cb(); | ||
}); | ||
}//fi | ||
promise.catch(function(e) { | ||
@@ -108,6 +123,12 @@ cb(e); | ||
}); | ||
} else { | ||
if (seemsToExpectCallback) { | ||
self.initialize(cb); | ||
} else { | ||
self.initialize(function(unusedErr){ | ||
cb(new Error('Unexpected attempt to invoke callback. Since this "initialize" function does not appear to expect a callback parameter, this stub callback was provided instead. Please either explicitly list the callback parameter among the arguments or change this code to no longer use a callback.')); | ||
}); | ||
return cb(); | ||
} | ||
} | ||
else { | ||
self.initialize(cb); | ||
} | ||
} catch (e) { return cb(e); } | ||
@@ -192,4 +213,11 @@ }); | ||
// Set a flag if this hook has an async `initialize` function. | ||
// Set a flag if this hook has an async `initialize` function, and | ||
// whether or not that function seems to be expecting any parameters. | ||
hasAsyncInit = this.initialize.constructor.name === 'AsyncFunction'; | ||
initSeemsToExpectParameters = (function(fn){ | ||
var fnStr = fn.toString().replace(STRIP_COMMENTS_RX, ''); | ||
var parametersAsString = fnStr.slice(fnStr.indexOf('(')+1, fnStr.indexOf(')')); | ||
// console.log('::',parametersAsString, parametersAsString.replace(/\s*/g,'').length); | ||
return parametersAsString.replace(/\s*/g,'').length !== 0; | ||
})(this.initialize);//† | ||
@@ -196,0 +224,0 @@ |
@@ -228,6 +228,7 @@ /** | ||
}; | ||
};//ƒ | ||
try { | ||
// Catch errors in async actions. See more notes about async route handlers in the `bindFunction` code below. | ||
// > FUTURE: optimize by precomputing this constructor.name check | ||
if (sails._actions[actionIdentity].constructor.name === 'AsyncFunction') { | ||
@@ -234,0 +235,0 @@ // Call the action with the specified identity, passing in req and res, as well as `mockRes` to catch unauthorized |
{ | ||
"name": "sails", | ||
"author": "Mike McNeil <@mikermcneil>", | ||
"version": "1.0.2", | ||
"version": "1.0.3-0", | ||
"description": "API-driven framework for building realtime apps, using MVC conventions (based on Express and Socket.io)", | ||
@@ -46,4 +46,4 @@ "license": "MIT", | ||
"include-all": "^4.0.0", | ||
"machine": "^15.0.0-21", | ||
"machine-as-action": "^10.0.0-0", | ||
"machine": "^15.2.2", | ||
"machine-as-action": "^10.2.0", | ||
"machinepack-process": "^2.0.2", | ||
@@ -71,3 +71,3 @@ "machinepack-redis": "^1.1.1", | ||
"vary": "1.1.2", | ||
"whelk": "^6.0.0" | ||
"whelk": "^6.0.1" | ||
}, | ||
@@ -74,0 +74,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1507690
32258
1
Updatedmachine@^15.2.2
Updatedmachine-as-action@^10.2.0
Updatedwhelk@^6.0.1