Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation Combinators (using Decoder) #168

Open
anthonyjoeseph opened this issue Mar 9, 2022 · 0 comments
Open

Validation Combinators (using Decoder) #168

anthonyjoeseph opened this issue Mar 9, 2022 · 0 comments

Comments

@anthonyjoeseph
Copy link

anthonyjoeseph commented Mar 9, 2022

馃殌 Feature request

yup, joi, zod, superstruct, ajv, and validate.js all have a big library of combinators for the sake of validation

io-ts is a 'runtime type system'
This PR is meant to expand it into a 'runtime validation' system

Using 'decoders' b/c they compose

Current Behavior

Validation combinators must be implemented manually

Desired Behavior

An extensive, verbose & granular library of common validators

Suggested Solution

By type:

  • Array

    • length
    • minLength
    • elem
    • isUniq
    • intersects
  • boolean

    • fromString
    • fromNumber
  • date

    • UnknownDate
    • fromISOString
    • fromISOStringCoerce
    • fromNumber
    • fromUnixTime
  • Either

    • either
  • Error (Decoder errors)

    • recoverWith
    • replace
  • Eq

    • is
    • oneOf
    • keyMatches
  • json

    • fromString
  • NewType

    • fromCarrierOf
  • NonEmptyArray

    • UnknownNonEmptyArray
    • fromArray
  • number

    • truncate
    • precision
    • maxPrecision
    • port
    • floor
    • round
    • abs
    • negate
    • positive
    • negative
    • parseInt
  • Option

    • option
  • Ord

    • lt
    • gt
    • leq
    • geq
    • between
  • Set

    • UnknownSet
    • fromArray
  • string

    • length
    • minLength
    • truncate
    • nonEmptyString
    • alphanumerical
    • base64
    • creditCard
    • dataUri
    • domainName
    • email
    • hex
    • hostname
    • ip
    • isoDate
    • isoDuration
    • normalize
    • regex
    • token
    • uri
    • uuid

partial implementation (playground)

The decoders & combinators are split into four categories:

  • Refine - these decoders will only narrow the type
  • Parse - these decoders will change the type arbitrarily
  • Build - these combinators will build decoders from other decoders
  • Util - simple refinements & endomorphisms used to create decoders

Hopefully, enough implementation is specified to understand the intent

If I made a PR of this or some subset of it, would you consider it?

Who does this impact? Who is this for?

Users looking for a runtime validation library

Describe alternatives you've considered

A fork of this library, or maybe new one entirely? io-ts-validations? io-ts-decoders?

Maybe the decoders that are simply 'maps', with no chance of failure (e.g. string.truncate) could purely live in Util, since they're trivial to implement as Decoders?

Additional context

closes #151
closes #59

Your environment

Software Version(s)
fp-ts 2.11.8
io-ts 2.2+
io-ts-types N / A
TypeScript 3.5.0+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant