Validations
SomeGraphs.Validations
—
Module
Validate graph data.
Rendering graphs requires two objects: data and configuration. Both objects need to be internally consistent, as does their combination. This is especially relevant for the graph configuration. When creating UI for filling in these objects, we can do limited validation of each field on its own based on its type (e.g. (e.g., ensure that a "color" field contains a valid color name). Some restrictions, however, are not easily deduced from the field type, or relate different fields to each other. Replicating all the restrictions in the UI is tedious and error prone.
We therefore provide a framework here for validating the objects and generate a hopefully informative error message if anything is wrong. This can be used by the UI to validate the data without worrying about the details.
SomeGraphs.Validations.Validated
—
Type
A common type for objects that support validation, that is, that one can invoke
validate
on.
SomeGraphs.Validations.ValidationContext
—
Type
A context (path of field names and/or indices) leading to a validated value. A string indicates access of a data member, an integer indicates accessing a vector or matrix element.
SomeGraphs.Validations.location
—
Function
stringify_context(context::ValidationContext)::AbstractString
Convert a
ValidationContext
to a string for error messages.
SomeGraphs.Validations.validate
—
Function
validate(context::ValidationContext, value::Validated)::Nothing end
validate(context::ValidationContext, value::Validated, extra::Any)::Nothing end
validate(context::ValidationContext, value::Validated, extra::Any, another::Any)::Nothing end
Validate the
value
which was accessed via the
context
, possibly using some
extra
informative. Will throw
ArgumentError
if the value isn't valid.
SomeGraphs.Validations.validate_in
—
Function
validate_in(validation::Function, context::ValidationContext, where::Union{AbstractString, Integer})::Nothing
Invoke the
validation
function with the
context
updated to include some
where
.
SomeGraphs.Validations.validate_field
—
Function
validate_field(context::ValidationContext, field::AbstractString, value::Validated)::Nothing
validate_field(context::ValidationContext, field::AbstractString, value::Validated, extra::Any)::Nothing
validate_field(context::ValidationContext, field::AbstractString, value::Validated, extra::Any, another::Any)::Nothing
Validate the
value
of a
field
.
SomeGraphs.Validations.validate_is_at_least
—
Function
validate_is_at_least(context::ValidationContext, value::Maybe{Real}, minimum::Real)::Nothing
Validate that a
value
is at least some
minimum
(if it is specified).
SomeGraphs.Validations.validate_is_above
—
Function
validate_is_above(context::ValidationContext, value::Maybe{Real}, minimum::Real)::Nothing
Validate that a
value
is above some
minimum
(if it is specified).
SomeGraphs.Validations.validate_is_at_most
—
Function
validate_is_at_most(context::ValidationContext, value::Maybe{Real}, maximum::Real)::Nothing
Validate that a
value
is at most some
maximum
(if it is specified).
SomeGraphs.Validations.validate_is_below
—
Function
validate_is_below(context::ValidationContext, value::Maybe{Real}, maximum::Real)::Nothing
Validate that a
value
is below some
maximum
(if it is specified).
SomeGraphs.Validations.validate_is_range
—
Function
validate_is_range(
context::ValidationContext,
low_where::AbstractString,
low_value::Maybe{Real},
high_where::AbstractString,
high_value::Maybe{Real},
)::Nothing
Validate that if both
low_value
and
high_value
are specified, they define a non-empty range.
SomeGraphs.Validations.validate_is_color
—
Function
validate_is_color(context::ValidationContext, color::Maybe{AbstractString})::Nothing
Validate that a
color
is a valid color name (if it is specified).
SomeGraphs.Validations.validate_vector_is_not_empty
—
Function
validate_vector_is_not_empty(
context::ValidationContext,
[field::AbstractString,]
vector::AbstractVector
)::Nothing
Validate that a
field
containing a
vector
has at least one entry.
SomeGraphs.Validations.validate_vector_length
—
Function
validate_vector_length(
context::ValidationContext,
field::AbstractString,
vector::Maybe{AbstractVector},
expected_base::AbstractString,
expected_length::Integer
)::Nothing
Validate that a
field
containing a
vector
has (if it is specified) the
expected_length
of an
expected_base
field.
SomeGraphs.Validations.validate_vector_entries
—
Function
validate_vector_entries(
validation::Function,
context::ValidationContext,
[field::AbstractString,]
vector::Maybe{AbstractVector},
[mask::Maybe{Union{AbstractVector{Bool},BitVector}} = nothing]
)::Nothing
Validate all the entries of a
field
containing a
vector
using the
validation
function. It is given the entry's index, and its value. The context is updated to include the index for the duration of the function.
If a
mask
is specified, entries with a false value in the mask will not be validated.
SomeGraphs.Validations.validate_matrix_is_not_empty
—
Function
validate_matrix_is_not_empty(
context::ValidationContext,
field::AbstractString,
matrix::AbstractMatrix
)::Nothing
Validate that a
field
containing a
matrix
has at least one entry.
SomeGraphs.Validations.validate_matrix_size
—
Function
validate_matrix_size(
context::ValidationContext,
matrix::Maybe{AbstractMatrix},
field::AbstractString,
expected_size::Tuple{Integer, Integer}
)::Nothing
Validate that a
field
containing
matrix
has (if it is specified) the
expected_size
of a
base_field
.
SomeGraphs.Validations.validate_matrix_entries
—
Function
validate_matrix_entries(
validation::Function,
context::ValidationContext,
field::AbstractString,
matrix::Maybe{AbstractMatrix}
)::Nothing
Validate all the entries of a
field
containing a
matrix
using the
validation
function. It is given the entry's row and column indices, and its value. The context is updated to include the indices for the duration of the function.
SomeGraphs.Validations.validate_dict_is_not_empty
—
Function
validate_dict_is_not_empty(
context::ValidationContext,
[field::AbstractString,]
dict::AbstractDict,
)::Nothing
Validate that a
field
containing a
dict
has at least one entry.
SomeGraphs.Validations.validate_dict_entries
—
Function
validate_dict_entries(
validation::Function,
context::ValidationContext,
[field::AbstractString,]
dict::Maybe{AbstractDict}
)::Nothing
Validate all the entries of a
field
containing a
dict
using the
validation
function. It is given the entry's key and value. The context is updated to include the key for the duration of the function.
Index
-
SomeGraphs.Validations -
SomeGraphs.Validations.Validated -
SomeGraphs.Validations.ValidationContext -
SomeGraphs.Validations.location -
SomeGraphs.Validations.validate -
SomeGraphs.Validations.validate_dict_entries -
SomeGraphs.Validations.validate_dict_is_not_empty -
SomeGraphs.Validations.validate_field -
SomeGraphs.Validations.validate_in -
SomeGraphs.Validations.validate_is_above -
SomeGraphs.Validations.validate_is_at_least -
SomeGraphs.Validations.validate_is_at_most -
SomeGraphs.Validations.validate_is_below -
SomeGraphs.Validations.validate_is_color -
SomeGraphs.Validations.validate_is_range -
SomeGraphs.Validations.validate_matrix_entries -
SomeGraphs.Validations.validate_matrix_is_not_empty -
SomeGraphs.Validations.validate_matrix_size -
SomeGraphs.Validations.validate_vector_entries -
SomeGraphs.Validations.validate_vector_is_not_empty -
SomeGraphs.Validations.validate_vector_length