valor: Simple general structured validation library

[ library, mit, validation ] [ Propose Tags ]

Please see the README on GitHub at https://github.com/reygoch/valor#readme


[Skip to Readme]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.0.0.1, 0.1.0.0, 1.0.0.0
Change log ChangeLog.md
Dependencies base (>=4.7 && <5), text, transformers [details]
License MIT
Copyright 2018 Luka Hadžiegrić
Author Luka Hadžiegrić
Maintainer reygoch@gmail.com
Category Validation
Home page https://github.com/reygoch/valor#readme
Bug tracker https://github.com/reygoch/valor/issues
Source repo head: git clone https://github.com/reygoch/valor
Uploaded by LukaHadziegric at 2018-06-18T11:56:37Z
Distributions LTSHaskell:1.0.0.0, NixOS:1.0.0.0, Stackage:1.0.0.0
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 1615 total (20 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-06-18 [all 1 reports]

Readme for valor-0.0.0.1

[back to package description]

Valor Logo

Valor

General, simple and easy to use structured validation library that gives you control over the error and input types.

Motivation

Currently there are a few validation libraries out there, most notably forma and digestive-functors. They are acceptable but they are mostly geard towards the web. Even with that in mind, I find them a bit impractical to use so I've decided to make a validation library of my own.

In no particular order here are the main problems I have with them:

  • They limit what you can validate and what you get as a result of that validation. Forma expects a JSON Value as an input and gives you either parsed data as a result or an error in the form of a JSON Value.

    Additionally, digestive-functors use a custom result type that you need to get familiar with to some extent.

  • They are essentially parsers, and I personally don't like to manually handle conversion of JSON fields from e.g. string to integers and other data types.

    Sure, it might be useful to tell the user that he entered text instead of a number, but in that case I'd argue that your submission form is bad.

    Even in this case, it should still be possible to validate plain JSON with Valor, but if that is your use case I'd recommend you use forma for that since it was specifically designed with JSON in mind.

  • They don't really play well with servant. Let's say that we have a record SomeData. If we wanted to allow users to submit that data to the server we'd have something like this :

    "api" :> ReqBody '[JSON] SomeData :> Post '[JSON] SomeResponse
    

    User would send SomeData encoded as JSON to the server, servant would automagically parse it and pass it to the Handler for further processing.

    If we wanted to validate this data with let's say forma than we would have to write something like this:

    "api" :> ReqBody '[JSON] Value :> Post '[JSON] SomeResponse
    

    in which case we lose nice semantics from the first example where it is obvious what data is being sent to the server (or at least what should've been sent).

    Since servant doesn't allow us to declare validation in the type, validation always has to happen in the Handler at which point it is no longer in the JSON form and library like forma is not of much use to us unless we convert SomeData to JSON and parse it once again.