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.constant()
A validator that ensures a value cannot be modified after insertion.
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

hashCode int
The hash code for this object.
no setterinherited
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
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
type → ValidateType?
final

Methods

compile(ManagedType typeBeingValidated, {Type? relationshipInverseType}) → dynamic
Subclasses override this method to perform any one-time initialization tasks and check for correctness.
constrainSchemaObject(APIDocumentContext context, APISchemaObject object) → void
Adds constraints to an APISchemaObject imposed by this validator.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
validate(ValidationContext context, dynamic input) → void
Validates the input value.

Operators

operator ==(Object other) bool
The equality operator.
inherited