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

deprecate notNull built-in validator

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