Module type Changeset_lib.S
Types
type 'a labelThe type of the changeset labels corresponding to the fields defined in the type
source.
Exceptions
Binding
type bindingThe type of bindings used by the
put_changesfunction.
Errors
Changeset
val empty : tThe empty changeset.
val is_empty : t ‑> Base.boolis_empty treturns true if the changes is empty, false otherwise.
val is_valid : t ‑> Base.boolis_valid treturnstrueif the changesettdoes not contain any error orfalseotherwise.
val from_record : source ‑> tfrom_record xreturns a changeset in which all the elements inxare loaded as changes.
val put_change : 'a label ‑> 'a ‑> t ‑> tput_change l x tputs a change associating the labellwith valuexin the changesett.
val put_changes : binding Base.list ‑> t ‑> tput_change bs tappliesput_changeto the list of bindingbsin the changesettfrom left to right.
val mem_label : _ label ‑> t ‑> Base.boolmem_label l treturnstrueif there is a binding oflin the changesettorfalseotherwise.
val mem_error : error ‑> t ‑> Base.boolmem_error e treturnstrueif the error belongs to the changesettorfalseotherwise.
val find : 'a label ‑> t ‑> 'a Base.optionfind l treturns the value associated with the labellin the changesettwrapped in an option value. It returnsNoneif the labellis unbound int.
val find_exn : 'a label ‑> t ‑> 'afind l treturns the value associated with labellin the changesett. It raises the exceptionNot_foundif the labellis unbound int.
val apply : t ‑> (source, t) Base.Result.tapply treturns:Ok xwherexis a value of typesourceif the changesettis valid and all the labels are present in the changes oft.Error t'otherwise, wheret'corresponds to the changesettif it was not valid, ortexpanded with anerror(l => "is missing")if the changeset was valid but alabellwas not found.
val apply_exn : t ‑> sourceapply treturns a value of typesourceif the changesettis valid and all the labels are present in the changes oft. It raises the exceptionInvalid_changesotherwise.
val show_errors : t ‑> Base.stringshow_errors treturns a string in the json format of the errors contained in the changesett.
Validations
val validate_change : 'a label ‑> ('a ‑> Base.string Base.list) ‑> t ‑> tvalidate_change l f tappliesfto the value associated with labellin the changesettand adds the list of error messages returned to the errors of the changesett, all being indexed by labell. If there is no binding for labellin changesett, the validation is not applied.
val require : 'a label ‑> ?message:Base.string ‑> t ‑> trequire l tvalidates that there is a binding oflin the changesett. If not, the errormessageindexed by the labellis added to the changesett. Default error message is"is required".
type length_opt=[|`is of Base.int|`min of Base.int|`max of Base.int]Options for length validations are the ones above where:
`is n: the length must be exactlyn.`min n: the length must be greater than or equal ton.`max n: the length must be less than or equal ton.
Error messages for
validate_length,validate_array_lengthandvalidate_list_lengthare the following:`is n:"should be %d element(s)"`min n:"should be at least %d element(s)"`max n:"should be at most %d element(s)"
Error messages for
validate_string_lengthare the following:`is n:"should be %d character(s)"`min n:"should be at least %d character(s)"`max n:"should be at most %d character(s)"
val validate_length : 'a label ‑> ('a ‑> Base.int) ‑> length_opt Base.list ‑> t ‑> tvalidate_length l f opts tvalidates that the length calculated by applyingfto the value indexed by the labellin the changesettrespects theopts.
val validate_string_length : Base.string label ‑> length_opt Base.list ‑> t ‑> tvalidate_string_length l opts tvalidates that the length of the string indexed by the labellin the changesettrespects theopts.
val validate_array_length : 'a Base.array label ‑> length_opt Base.list ‑> t ‑> tvalidate_array_length l opts tvalidates that the length of the array indexed by the labellin the changesettrespects theopts.
val validate_list_length : 'a Base.list label ‑> length_opt Base.list ‑> t ‑> tvalidate_list_length l opts tvalidates that the length of the list indexed by the labellin the changesettrespects theopts.
type 'a ord_opt=[|`equal_to of 'a|`greater_than of 'a|`greater_than_or_equal_to of 'a|`less_than of 'a|`less_than_or_equal_to of 'a]
val validate : 'a label ‑> (module Base.Comparator.S with type t = 'a) ‑> 'a ord_opt Base.list ‑> t ‑> tvalidate l cmp opts tvalidates that the value indexed by the labellin the changesettrespects theoptsusing thecomparefunction provided by the first-class modulecmp.
val validate_int : Base.int label ‑> Base.int ord_opt Base.list ‑> t ‑> tvalidate_int l opts tvalidates that the integer indexed by labellin the changesettrespects theopts.
val validate_float : Base.float label ‑> Base.float ord_opt Base.list ‑> t ‑> tvalidate_float l opts tvalidates that float indexed by labellin the changesettrespects theopts.
val validate_bool : Base.bool label ‑> Base.bool ord_opt Base.list ‑> t ‑> tvalidate_bool l opts tvalidates that the boolean indexed by labellin the changesettrespects theopts.
val validate_char : Base.char label ‑> Base.char ord_opt Base.list ‑> t ‑> tvalidate_char l opts tvalidates that the char indexed by labellin the changesettrespects theopts.
val validate_string : Base.string label ‑> Base.string ord_opt Base.list ‑> t ‑> tvalidate_string l opts tvalidates that the string indexed by labellin the changesettrespects theopts.
val validate_inclusion : 'a label ‑> ('a ‑> 'a ‑> Base.bool) ‑> 'a Base.list ‑> ?message:Base.string ‑> t ‑> tvalidate_inclusion equal l xs ?message tvalidates that the value indexed by labellin the changesettis a an included inxs. If not, an errormessageindexed by the labellis added to the changesett. Default error message is"is invalid".
val validate_exclusion : 'a label ‑> ('a ‑> 'a ‑> Base.bool) ‑> 'a Base.list ‑> ?message:Base.string ‑> t ‑> tvalidate_excluded equal l xs ?message tvalidates that the value indexed by labellin the changesettis not included inxs. If not, an errormessageindexed by the labellis added to the changesett. Default error message is"is reserved".
val validate_acceptance : Base.bool label ‑> ?message:Base.string ‑> t ‑> tvalidate_string l ?message tvalidates that the change indexed by labellin the changesettistrue. If not, an errormessageindexed by the labellis added to the changesett. Default error message is"must be accepted".
val validate_format : Base.string label ‑> Str.regexp ‑> ?message:Base.string ‑> t ‑> tvalidate_format l reg ?message tvalidates that the change indexed by labellin the changesettis accepted by the regexr. If not, an errormessageindexed by the labellis added to the changesett. Default error message is"has invalid format".