vlad.core
->Attr
(->Attr selector validation)
Positional factory function for class vlad.core.Attr.
->Chain
(->Chain left right)
Positional factory function for class vlad.core.Chain.
->Join
(->Join left right)
Positional factory function for class vlad.core.Join.
->Predicate
(->Predicate predicate information)
Positional factory function for class vlad.core.Predicate.
assign-name
(assign-name errors selectors-to-names)
`translate` expects each field to have a human readable name. `assign-name`
takes a collection of errors and a map of selectors to names and will return
the errors with names inserted.
attr
(attr selector)
(attr selector validation)
Runs a validation on the data found at `selector`. If there are nested uses
of `attr` any `:selector` attributes in errors will be updated to reflect the
full `selector`.
Example:
(validate (attr [:name] present) {:name "Vlad"})
chain
(chain)
(chain left)
(chain left right)
(chain left right & validations)
Example:
(chain
(present "Password" :password)
(length_over 7 "Password" :password))
english-translation
multimethod
Takes an error and returns a human readable version of it.
equals-field
(equals-field first-selector second-selector)
Checks that the values found at each of your selectors are equal to each
other
equals-value
(equals-value value)
Checks that the value is equal to the `value` that you
provide.
join
(join)
(join left)
(join left right)
(join left right & validations)
Example:
(join
(present "Name" :name)
(present "Age" :age))
length-in
(length-in lower upper)
Checks that the `count` of the value is over `lower` and under `upper`. No
checking is done that `lower` is lower than `upper`. This validator may
return multiple errors
length-over
(length-over size)
Checks that the `count` of the value is over `size`.
length-under
(length-under size)
Checks that the `count` of the value is under `size`.
map->Attr
(map->Attr m__6289__auto__)
Factory function for class vlad.core.Attr, taking a map of keywords to field values.
map->Chain
(map->Chain m__6289__auto__)
Factory function for class vlad.core.Chain, taking a map of keywords to field values.
map->Join
(map->Join m__6289__auto__)
Factory function for class vlad.core.Join, taking a map of keywords to field values.
map->Predicate
(map->Predicate m__6289__auto__)
Factory function for class vlad.core.Predicate, taking a map of keywords to field values.
matches
(matches pattern)
Checks that the value is a regex match for `pattern`. This uses clojure's
`re-matches` function which may not behave as you expect. Your pattern will
have to match the whole string to count as a match.
not-of
(not-of set)
Checks that the value is not found within `set`
one-of
(one-of set)
Checks that the value is found within `set`
predicate
(predicate pred information)
(predicate selector pred information)
Examples:
(predicate #(> size (count %))
{:type ::length-over :size size})
(predicate [:user :password]
#(> size (count %))
{:type ::length-over :size size})
translate-errors
(translate-errors errors translation)
Translates a sequence of errors into a map of plain english error messages.
Selectors are used as keys.
Example:
(translate-errors [{
:type :vlad.core/length-under
:selector [:password]
:name "Password"
:size 8}])
; => {[:password] "Password must be under 8 characters long."}
valid
(valid data)
`valid` is a validation that does nothing. It can be safely composed with
other validations. It is used as the identity value for reducers/monoid
functions (Don't panic. You don't need to know what that means to use vlad).
valid?
(valid? validations data)
Validation
protocol
The core of vlad is the `Validation` protocol. It simply requires that your
validation type knows how to run against some data. Implementations of
`validate` should return a sequence of errors. An error may be anything but
is generally of the form `{:type ::something :some-extra-data 123}`.
members
validate
(validate self data)