不要怂,就是干,撸起袖子干!

deprecate notNull built-in validator

1 parent 5d219eaf
......@@ -5,10 +5,9 @@ var Validator = require("validator")
function noop() {}
// Backwards compat for people using old validation function
// We cannot use .extend, since it coerces the first arg to string
Validator.notNull = function (val) {
return [null, undefined].indexOf(val) === -1
// Deprecate this.
Validator.notNull = function () {
throw new Error('Warning "notNull" validation has been deprecated in favor of Schema based "allowNull"');
}
// https://github.com/chriso/validator.js/blob/1.5.0/lib/validators.js
......@@ -245,8 +244,7 @@ DaoValidator.prototype._customValidators = function() {
DaoValidator.prototype._builtinAttrValidate = function(value, field) {
var self = this;
// check if value is null (if null not allowed the Schema pass will capture it)
if (!('notNull' in this.modelInstance.validators[field]) &&
(value === null || typeof value === 'undefined')) {
if (value === null || typeof value === 'undefined') {
return Promise.resolve();
}
......
......@@ -952,9 +952,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
var Tasks = this.sequelize.define('Task', {
name: {
type: Sequelize.STRING,
validate: {
notNull: { args: true, msg: 'name cannot be null' }
}
allowNull: false,
},
code: {
type: Sequelize.STRING,
......@@ -974,7 +972,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
expect(errors).to.be.an('Array')
expect(errors).to.have.length(2)
expect(errors[0].record.code).to.equal('1234')
expect(errors[0].errors.name[0].message).to.equal('name cannot be null')
expect(errors[0].errors.name[0].message).to.equal('notNull Violation')
expect(errors[1].record.name).to.equal('bar')
expect(errors[1].record.code).to.equal('1')
expect(errors[1].errors.code[0].message).to.equal('Validation len failed')
......@@ -988,8 +986,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
name: {
type: Sequelize.STRING,
validate: {
notNull: { args: true, msg: 'name cannot be null' }
}
notEmpty: true,
},
},
code: {
type: Sequelize.STRING,
......
......@@ -68,10 +68,6 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
fail: "a",
pass: "9.2"
}
, notNull : {
fail: null,
pass: 0
}
, isNull : {
fail: 0,
pass: null
......@@ -291,8 +287,8 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
var Model = this.sequelize.define('model', {
name: {
type: Sequelize.STRING,
allowNull: false,
validate: {
notNull: true, // won't allow null
notEmpty: true // don't allow empty strings
}
}
......@@ -313,8 +309,8 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
var Model = this.sequelize.define('model', {
name: {
type: Sequelize.STRING,
allowNull: false,
validate: {
notNull: true, // won't allow null
notEmpty: true // don't allow empty strings
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!