Comparing version 4.0.4 to 4.0.5
@@ -90,2 +90,6 @@ /** | ||
// unsafe mode completely disables input validation, and sets _runTimeTypeCheck, _inputCoercion | ||
// and _exitCoercion to `false` (they can be reactivated if chained after the call to `.unsafe()`) | ||
this._unsafeMode = false; | ||
this._runningSynchronously = false; | ||
@@ -167,2 +171,16 @@ | ||
*/ | ||
Machine.prototype.unsafe = function(flag) { | ||
this._unsafeMode = flag; | ||
if (flag === true) { | ||
this._runTimeTypeCheck = false; | ||
this._inputCoercion = false; | ||
this._exitCoercion = false; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* @param {Boolean} flag | ||
* @chainable | ||
*/ | ||
Machine.prototype.inputCoercion = function(flag) { | ||
@@ -169,0 +187,0 @@ this._inputCoercion = flag; |
@@ -34,30 +34,32 @@ /** | ||
var validationResults = validateConfiguredInputValues(self); | ||
var coercedInputValues = validationResults.values; | ||
var errors = validationResults.errors; | ||
if (!self._unsafeMode) { | ||
var validationResults = validateConfiguredInputValues(self); | ||
var coercedInputValues = validationResults.values; | ||
var errors = validationResults.errors; | ||
// Strip E_INVALID_TYPE errors if inputCoercion is enabled. | ||
if (self._inputCoercion) { | ||
// Strip out minor "E_INVALID_TYPE" errors- they are ok if we're just coercing. | ||
_.remove(errors, {code: 'E_INVALID_TYPE', minor: true}); | ||
} | ||
// Strip E_INVALID_TYPE errors if inputCoercion is enabled. | ||
if (self._inputCoercion) { | ||
// Strip out minor "E_INVALID_TYPE" errors- they are ok if we're just coercing. | ||
_.remove(errors, {code: 'E_INVALID_TYPE', minor: true}); | ||
} | ||
// If there are (still) `e.errors`, then we've got to call the error callback. | ||
if (errors.length > 0) { | ||
// If runtime type checking is enabled, trigger the error exit | ||
// if any inputs are invalid. | ||
// TODO: call a special 'failedInputValidation' exit here | ||
if(self._runTimeTypeCheck) { | ||
// Fourth argument (`true`) tells switchback to run synchronously | ||
return switchback(self._configuredExits, undefined, undefined, true)((function (){ | ||
// var err = new Error(util.format('`%s` machine: %d error(s) encountered validating inputs:\n', self.identity, errors.length, util.inspect(errors))); | ||
var err = new Error(util.format('`%s` machine encountered %d error(s) while validating runtime input values.', self.identity, errors.length)); | ||
// err.code = errors[0].code; | ||
err.code = 'E_MACHINE_RUNTIME_VALIDATION'; | ||
err.machine = self.identity; | ||
err.reason = err.message; | ||
err.status = 400; | ||
err.errors = errors; | ||
return err; | ||
})()); | ||
// If there are (still) `e.errors`, then we've got to call the error callback. | ||
if (errors.length > 0) { | ||
// If runtime type checking is enabled, trigger the error exit | ||
// if any inputs are invalid. | ||
// TODO: call a special 'failedInputValidation' exit here | ||
if(self._runTimeTypeCheck) { | ||
// Fourth argument (`true`) tells switchback to run synchronously | ||
return switchback(self._configuredExits, undefined, undefined, true)((function (){ | ||
// var err = new Error(util.format('`%s` machine: %d error(s) encountered validating inputs:\n', self.identity, errors.length, util.inspect(errors))); | ||
var err = new Error(util.format('`%s` machine encountered %d error(s) while validating runtime input values.', self.identity, errors.length)); | ||
// err.code = errors[0].code; | ||
err.code = 'E_MACHINE_RUNTIME_VALIDATION'; | ||
err.machine = self.identity; | ||
err.reason = err.message; | ||
err.status = 400; | ||
err.errors = errors; | ||
return err; | ||
})()); | ||
} | ||
} | ||
@@ -64,0 +66,0 @@ } |
{ | ||
"name": "machine", | ||
"version": "4.0.4", | ||
"version": "4.0.5", | ||
"description": "Configure and execute machines", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71203
1611