angel3_validate.server library Null safety

Support for using angel_validate with the Angel Framework.

Classes

AngelMatcher
An asynchronous Matcher that runs in the context of an Angel app.
ContextAwareMatcher
A special Matcher that is aware of the context in which it is being executed.
CustomMatcher
A useful utility class for implementing other matchers through inheritance. Derived classes should call the base constructor with a feature name and description, and an instance matcher, and should implement the featureValueOf abstract method.
Description
Matchers build up their error messages by appending to Description objects.
isInstanceOf<T>
DEPRECATED Use isA instead.
Matcher
The base class for all matchers.
StringDescription
The default implementation of Description. This should rarely need substitution, although conceivably it is a place where other languages could be supported.
TypeMatcher<T>
A Matcher subclass that supports validating the Type of the target object.
ValidationResult
The result of attempting to validate input data.
Validator
Enforces the validity of input data, according to Matchers.

Constants

anything → const Matcher
A matcher that matches any value.
_IsAnything()
isArgumentError → const TypeMatcher<ArgumentError>
A matcher for ArgumentError.
TypeMatcher<ArgumentError>()
isCastError → const TypeMatcher<CastError>
A matcher for CastError.
@Deprecated('CastError has been deprecated in favor of TypeError. ' 'Use `isA<TypeError>()` or, if you need compatibility with older SDKs, ' 'use `isA<CastError>()` and ignore the deprecation.')
TypeMatcher<CastError>()
isConcurrentModificationError → const TypeMatcher<ConcurrentModificationError>
A matcher for ConcurrentModificationError.
TypeMatcher<ConcurrentModificationError>()
isCyclicInitializationError → const TypeMatcher<CyclicInitializationError>
A matcher for CyclicInitializationError.
TypeMatcher<CyclicInitializationError>()
isEmpty → const Matcher
Returns a matcher that matches the isEmpty property.
_Empty()
isException → const TypeMatcher<Exception>
A matcher for Exception.
TypeMatcher<Exception>()
isFalse → const Matcher
A matcher that matches anything except the Boolean value true.
_IsFalse()
isFormatException → const TypeMatcher<FormatException>
A matcher for FormatException.
TypeMatcher<FormatException>()
isList → const TypeMatcher<List>
A matcher for List.
TypeMatcher<List>()
isMap → const TypeMatcher<Map>
A matcher for Map.
TypeMatcher<Map>()
isNaN → const Matcher
A matcher that matches the numeric value NaN.
_IsNaN()
isNegative → const Matcher
A matcher which matches if the match argument is negative.
_OrderingMatcher(0, false, true, false, 'a negative value', false)
isNonNegative → const Matcher
A matcher which matches if the match argument is zero or positive.
_OrderingMatcher(0, true, false, true, 'a non-negative value', false)
isNonPositive → const Matcher
A matcher which matches if the match argument is zero or negative.
_OrderingMatcher(0, true, true, false, 'a non-positive value', false)
isNonZero → const Matcher
A matcher which matches if the match argument is non-zero.
_OrderingMatcher(0, false, true, true, 'a value not equal to')
isNoSuchMethodError → const TypeMatcher<NoSuchMethodError>
A matcher for NoSuchMethodError.
TypeMatcher<NoSuchMethodError>()
isNotEmpty → const Matcher
Returns a matcher that matches the isNotEmpty property.
_NotEmpty()
isNotNaN → const Matcher
A matcher that matches any non-NaN value.
_IsNotNaN()
isNotNull → const Matcher
A matcher that matches any non-null value.
_IsNotNull()
isNull → const Matcher
A matcher that matches any null value.
_IsNull()
isNullThrownError → const TypeMatcher<NullThrownError>
A matcher for NullThrownError.
TypeMatcher<NullThrownError>()
isPositive → const Matcher
A matcher which matches if the match argument is positive.
_OrderingMatcher(0, false, false, true, 'a positive value', false)
isRangeError → const TypeMatcher<RangeError>
A matcher for RangeError.
TypeMatcher<RangeError>()
isStateError → const TypeMatcher<StateError>
A matcher for StateError.
TypeMatcher<StateError>()
isTrue → const Matcher
A matcher that matches the Boolean value true.
_IsTrue()
isUnimplementedError → const TypeMatcher<UnimplementedError>
A matcher for UnimplementedError.
TypeMatcher<UnimplementedError>()
isUnsupportedError → const TypeMatcher<UnsupportedError>
A matcher for UnsupportedError.
TypeMatcher<UnsupportedError>()
isZero → const Matcher
A matcher which matches if the match argument is zero.
_OrderingMatcher(0, true, false, false, 'a value equal to')
returnsNormally → const Matcher
A matcher that matches a function call against no exception.
_ReturnsNormally()

Properties

isAlphaDash Matcher
Asserts that a String is alphanumeric, but also lets it contain dashes or underscores.
final
isAlphaNum Matcher
Asserts that a String is alphanumeric, but also lets it contain dashes or underscores.
final
isBool Matcher
Asserts that a value either equals true or false.
final
isChecked Matcher
Asserts that a value, presumably from a checkbox, is positive.
final
isConfirmed ContextAwareMatcher
Asserts that for a key x, the context contains an identical item x_confirmed.
read / write
isEmail Matcher
Asserts that a String complies to the RFC 5322 e-mail standard.
final
isInt Matcher
Asserts that a value is an int.
final
isIso8601DateString Matcher
Ensures that a string is an ISO-8601 date string.
final
isNonEmptyString Matcher
Asserts that a value is a non-empty String.
final
isNum Matcher
Asserts that a value is a num.
final
isString Matcher
Asserts that a value is a String.
final
isUrl Matcher
Asserts that a String is an http:// or https:// URL.
final

Functions

addStateInfo(Map matchState, Map values) → void
Useful utility for nesting match states.
allOf(Object? arg0, [Object? arg1, Object? arg2, Object? arg3, Object? arg4, Object? arg5, Object? arg6]) Matcher
This returns a matcher that matches if all of the matchers passed as arguments (up to 7) match.
anyElement(Object? valueOrMatcher) Matcher
Returns a matcher which matches Iterables in which at least one element matches the given valueOrMatcher.
anyOf(Object? arg0, [Object? arg1, Object? arg2, Object? arg3, Object? arg4, Object? arg5, Object? arg6]) Matcher
Matches if any of the given matchers evaluate to true.
asyncApplyValidator(Validator validator, Map data, Angel app) Future<ValidationResult>
Asynchronously apply a validator, running any AngelMatchers.
autoParse(Map inputData, Iterable<String> fields) Map<String, dynamic>
Converts the desired fields to their numeric representations, if present.
autoParseBody(List<String> fields) RequestHandler
Auto-parses numbers in req.bodyAsMap.
autoParseQuery(List<String> fields) RequestHandler
Auto-parses numbers in req.queryParameters.
closeTo(num value, num delta) Matcher
Returns a matcher which matches if the match argument is within delta of some value.
collapseWhitespace(String string) String
Utility function to collapse whitespace runs to single spaces and strip leading/trailing whitespace.
contains(Object? expected) Matcher
Returns a matcher that matches if the match argument contains the expected value.
containsAll(Iterable expected) Matcher
Matches Iterables which contain an element matching every value in expected in any order, and may contain additional values.
containsAllInOrder(Iterable expected) Matcher
Matches Iterables which contain an element matching every value in expected in the same order, but may contain additional values interleaved throughout.
containsPair(Object? key, Object? valueOrMatcher) Matcher
Returns a matcher which matches maps containing the key-value pair with key => valueOrMatcher.
containsValue(Object? value) Matcher
Returns a matcher which matches maps containing the given value.
differentFrom(String key) ContextAwareMatcher
Asserts that for a key x, the value of x is not equal to the value for key.
endsWith(String suffixString) Matcher
Returns a matcher that matches if the match argument is a string and ends with suffixString.
equals(Object? expected, [int limit = 100]) Matcher
Returns a matcher that matches if the value is structurally equal to expected.
equalsIgnoringCase(String value) Matcher
Returns a matcher which matches if the match argument is a string and is equal to value when compared case-insensitively.
equalsIgnoringWhitespace(String value) Matcher
Returns a matcher which matches if the match argument is a string and is equal to value, ignoring whitespace.
escape(String str) String
Returns str with all whitespace characters represented as their escape sequences.
everyElement(Object? valueOrMatcher) Matcher
Returns a matcher which matches Iterables in which all elements match the given valueOrMatcher.
filter(Map inputData, Iterable<String> only) Map<String, dynamic>
Removes undesired fields from a Map.
filterBody(Iterable<String> only) RequestHandler
Filters unwanted data out of req.bodyAsMap.
filterQuery(Iterable<String> only) RequestHandler
Filters unwanted data out of req.queryParameters.
greaterThan(Object value) Matcher
Returns a matcher which matches if the match argument is greater than the given value.
greaterThanOrEqualTo(Object value) Matcher
Returns a matcher which matches if the match argument is greater than or equal to the given value.
hasLength(Object? matcher) Matcher
Returns a matcher that matches if an object has a length property that matches matcher.
idExistsInService(String servicePath, {String idField = 'id', String? description}) AngelMatcher
Returns an AngelMatcher that verifies that an item with the given idField exists in the service at servicePath, without throwing a 404 or returning null.
inClosedOpenRange(num low, num high) Matcher
Returns a matcher which matches if the match argument is greater than or equal to a low and less than high.
inExclusiveRange(num low, num high) Matcher
Returns a matcher which matches if the match argument is greater than low and less than high.
inInclusiveRange(num low, num high) Matcher
Returns a matcher which matches if the match argument is greater than or equal to low and less than or equal to high.
inOpenClosedRange(num low, num high) Matcher
Returns a matcher which matches if the match argument is greater than low and less than or equal to high.
isA<T>() TypeMatcher<T>
Returns a matcher that matches objects with type T.
isIn(Object? expected) Matcher
Returns a matcher that matches if the match argument is in the expected value. This is the converse of contains.
isNot(Object? valueOrMatcher) Matcher
Returns a matcher that inverts valueOrMatcher to its logical negation.
lessThan(Object value) Matcher
Returns a matcher which matches if the match argument is less than the given value.
lessThanOrEqualTo(Object value) Matcher
Returns a matcher which matches if the match argument is less than or equal to the given value.
matchAsync(FutureOr<Matcher> matcher(String, Object), FutureOr feature(), [String description = 'satisfies asynchronously created matcher']) AngelMatcher
Returns an AngelMatcher that asynchronously resolves a feature, builds a matcher, and executes it.
matches(Pattern re) Matcher
Returns a matcher that matches if the match argument is a string and matches the regular expression given by re.
matchWithAngel(FutureOr<Matcher> f(Object, Map, Angel), [String description = 'satisfies asynchronously created matcher']) AngelMatcher
Returns an AngelMatcher that applies an asynchronously-created Matcher to the input.
matchWithAngelBinary(FutureOr<Matcher> f(Map context, Angel), [String description = 'satisfies asynchronously created matcher']) AngelMatcher
Calls matchWithAngel without the initial parameter.
matchWithAngelNullary(FutureOr<Matcher> f(), [String description = 'satisfies asynchronously created matcher']) AngelMatcher
Calls matchWithAngel without any parameters.
matchWithAngelUnary(FutureOr<Matcher> f(Angel), [String description = 'satisfies asynchronously created matcher']) AngelMatcher
Calls matchWithAngel without the initial two parameters.
maxLength(int length) Matcher
Limits the maximum length of a string.
minLength(int length) Matcher
Enforces a minimum length on a string.
orderedEquals(Iterable expected) Matcher
Returns a matcher which matches Iterables that have the same length and the same elements as expected, in the same order.
pairwiseCompare<S, T>(Iterable<S> expected, bool comparator(S, T), String description) Matcher
A pairwise matcher for Iterables.
predicate<T>(bool f(T), [String description = 'satisfies function']) Matcher
Returns a matcher that uses an arbitrary function that returns true or false for the actual value.
predicateWithAngel(FutureOr<bool> f(String, Object, Angel), [String description = 'satisfies function']) AngelMatcher
Returns an AngelMatcher that uses an arbitrary function that returns true or false for the actual value.
predicateWithContext(bool f(Object, String, Map, Map), [String description = 'satisfies function']) ContextAwareMatcher
Returns a ContextAwareMatcher for the given predicate.
requiredAny(Iterable<String> keys) → ContextValidator
Assert that a key x is present, if any of the given keys are as well.
requiredIf(Iterable<String> keys) → ContextValidator
Assert that a key x is present, if all of the given keys are as well.
requiredWithout(Iterable<String> keys) → ContextValidator
Assert that a key x is present, if at least one of the given keys is not.
requiredWithoutAll(Iterable<String> keys) → ContextValidator
Assert that a key x is present, if none of the given keys are.
requireField(String field) String
Marks a field name as required.
requireFields(Iterable<String> fields) String
Marks multiple fields as required.
same(Object? expected) Matcher
Returns a matches that matches if the value is the same instance as expected, using identical.
sameAs(String key) ContextAwareMatcher
Asserts that for a key x, the value of x is equal to the value for key.
startsWith(String prefixString) Matcher
Returns a matcher that matches if the match argument is a string and starts with prefixString.
stringContainsInOrder(List<String> substrings) Matcher
Returns a matcher that matches if the match argument is a string and contains a given list of substrings in relative order.
unorderedEquals(Iterable expected) Matcher
Returns a matcher which matches Iterables that have the same length and the same elements as expected, but not necessarily in the same order.
unorderedMatches(Iterable expected) Matcher
Returns a matcher which matches Iterables whose elements match the matchers in expected, but not necessarily in the same order.
validate(Validator validator, {String errorMessage = 'Invalid data.'}) RequestHandler
Validates the data in req.bodyAsMap, and sets the body to filtered data before continuing the response.
validateEvent(Validator validator, {String errorMessage = 'Invalid data.'}) HookedServiceEventListener<dynamic, dynamic, Service<Never, Never>>
Validates the data in e.data, and sets the data to filtered data before continuing the service event.
validateQuery(Validator validator, {String errorMessage = 'Invalid data.'}) RequestHandler
Validates the data in req.queryParameters, and sets the query to filtered data before continuing the response.
wrapAngelMatcher(dynamic x) AngelMatcher
Returns an AngelMatcher that represents x.
wrapContextAwareMatcher(dynamic x) ContextAwareMatcher
Wraps x in a ContextAwareMatcher.
wrapMatcher(Object? valueOrMatcher) Matcher
Takes an argument and returns an equivalent Matcher.

Typedefs

CustomErrorMessageFunction = String Function(dynamic item)
Generates an error message based on the given input.
DefaultValueFunction = dynamic Function()
Returns a value based the result of a computation.
Filter = bool Function(dynamic value)
Determines if a value is valid.

Exceptions / Errors

ValidationException
Occurs when user-provided data is invalid.