Domo - model a business domain with type-safe structs and field type range checks

Domo makes your structure types work for data conformance validation. And it enables automatic range checking for field types at run-time.

That is independent of database or any custom notation, only standard Elixir type definitions and pure functions.

Domo adds a new/1 constructor function to the structure module that builds an instance only if all fields conform to the struct’s t() type and all specified precondition functions for filed types return true.

That makes it possible to validate model types in microservice setups between depending applications by sharing a common model among codebases. That can be structs, user-defined types, and appropriate precondition functions.

Domo main features are:

  • new/1, new_ok/1, ensure_type!/1, and ensure_type_ok/1 functions for a struct using Domo
  • support for boolean precondition function for the user-defined type or the whole struct’s t() type to specify range checks
  • automatic generation of conformance validation function from the struct’s t() type at compile-time
  • validation of data conformance to the struct type when constructing an instance both at compile and run-times
  • dependency tracking to recompile modules when affecting type definition changes

More information here:

10 Likes

v1.2.4 – June 6, 2021

  • Speedup resolving the struct types
  • Limit the number of allowed fields types combinations to 4096
  • Support Range.t() and MapSet.t()
  • Keep type ensurers source code after compiling an umbrella project
  • Remove preconditions manifest file on mix clean command
  • List processed structs giving mix --verbose option
4 Likes

v1.2.5 – June 14, 2021

  • Add remote_types_as_any option to disable validation of specified remote types for the case of hitting the limit of 4096 type combinations. A precondition for wrapping user-defined type can be used in such cases.
1 Like

v1.2.6 - June 20, 2021

  • Validates type conformance of default values given with defstruct/1 at compile-time :star_struck:
  • Includes only the most matching type error into the error message
1 Like

v1.2.7 - July 4, 2021

  • Fix the bug to resolve remote type when giving correct alias
  • Support custom {:error, message} returned from the range validation function defined with precond/1 macro
2 Likes

v1.2.9 - August 8, 2021

Domo is lightened by extraction of the tagged_tuple library (finally! :tada:)

Documentation is rewritten from scratch.

The /example_avialia project is updated to demonstrate using of Domo to validate Ecto changesets.

Other changes:

  • Fix bug to acknowledge that type has been changed after a failed compilation.

  • Fix bug to match structs not using Domo with a field of any() type with and without precondition.

  • Add typed_fields/1 and required_fields/1 functions.

  • Add maybe_filter_precond_errors: true option that filters errors from precondition functions for better output for the user.

4 Likes

v1.3.0 - August 15, 2021

  • Change the default name of the constructor function to new! to follow Elixir naming convention.
    You can always change the name with the config :domo, :name_of_new_function, :new_func_name_here app configuration.

  • Fix bug to validate defaults for every required field in a struct except __underscored__ fields at compile-time.

  • Check whether the precondition function associated with t() type returns true at compile-time regarding defaults correctness check.

  • Add examples of integration with TypedStruct and TypedEctoSchema.

3 Likes

A post was merged into an existing topic: TaggedTuple

v1.3.2 - September 18, 2021

  • Support remote types in erlang modules like :inet.port_number()

  • Shorten the invalid value output in the error message

  • Increase validation speed by skipping fields that are not in t() type spec or have the any() type

  • Fix bug to skip validation of struct’s enforced keys default value because they are ignored during the construction anyway

  • Increase validation speed by generating TypeEnsurer modules for Date, Date.Range, DateTime, File.Stat, File.Stream, GenEvent.Stream, IO.Stream, Macro.Env, NaiveDateTime, Range, Regex, Task, Time, URI, and Version structs from the standard library at the first project compilation

  • Fix bug to call the precond function of the user type pointing to a struct

  • Increase validation speed by encouraging to use Domo or to make a precond function for struct referenced by a user type

  • Add Domo.has_type_ensurer?/1 that checks whether a TypeEnsurer module was generated for the given struct.

  • Add example of parsing and validating of the JSON via Jason + ExJSONPath + Domo

2 Likes