Validate class

Add as metadata to persistent properties to validate their values before insertion or updating.

When executing update or insert queries, any properties with this metadata will be validated against the condition declared by this instance. Example:

    class Person extends ManagedObject<_Person> implements _Person {}
    class _Person {
      @primaryKey
      int id;

      @Validate.length(greaterThan: 10)
      String name;
    }

Properties may have more than one metadata of this type. All validations must pass for an insert or update to be valid.

By default, validations occur on update and insert queries. Constructors have arguments for only running a validation on insert or update. See runOnUpdate and runOnInsert.

This class may be subclassed to create custom validations. Subclasses must override validate.

Constructors

Validate({bool onUpdate: true, bool onInsert: true })
Invoke this constructor when creating custom subclasses. [...]
const
Validate.absent({bool onUpdate: true, bool onInsert: true })
A validator for ensuring a property does not have a value when being inserted or updated. [...]
const
Validate.compare({Comparable lessThan, Comparable greaterThan, Comparable equalTo, Comparable greaterThanEqualTo, Comparable lessThanEqualTo, bool onUpdate: true, bool onInsert: true })
A validator for comparing a value. [...]
const
Validate.length({int lessThan, int greaterThan, int equalTo, int greaterThanEqualTo, int lessThanEqualTo, bool onUpdate: true, bool onInsert: true })
A validator for validating the length of a String. [...]
const
Validate.matches(String pattern, { bool onUpdate: true, bool onInsert: true })
A validator for matching an input String against a regular expression. [...]
const
Validate.oneOf(List values, { bool onUpdate: true, bool onInsert: true })
A validator for ensuring a value is one of a set of values. [...]
const
Validate.present({bool onUpdate: true, bool onInsert: true })
A validator for ensuring a property always has a value when being inserted or updated. [...]
const

Properties

runOnInsert bool
Whether or not this validation is checked on insert queries.
final
runOnUpdate bool
Whether or not this validation is checked on update queries.
final
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

constrainSchemaObject(APIDocumentContext context, APISchemaObject object) → void
Adds constraints to an APISchemaObject imposed by this validator. [...]
getValidator(ManagedAttributeDescription forAttribute) ManagedValidator
Returns a ManagedValidator for the validation described by this object.
validate(ValidationContext context, dynamic input) → void
Custom validations override this method to provide validation behavior. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) bool
The equality operator. [...]
inherited