Giter Site home page Giter Site logo

brief's People

Contributors

poslegm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

brief's Issues

Add field name to error message

It should works like:

@Validation
case class Test(a: Int, b: Int Refined Positive)
Test.create(1, -2) // Validated.Invalid(NonEmptyChain("For field Test.b: Predicate failed: (-2 > 0)."))

It can be done here

Publish to Maven Central

  • Add sbt-ci-release
  • Choose package and organization name. I don't want to have "com.github.poslegm" %% "brief" % "version" or "dev.chugunkov" %% "brief" % "version" in build.sbt
  • Follow steps from plugin README

Custom error types

It should works like:

@Validation case class Test(a: Int Refined Positive)
Test.create(-2) // Left(List("bla bla"))

final case class CustomException(msgs: List[String] Refined NonEmpty)
  extends Exception(s"validation errors on CustomTest creation: ${msgs.mkString("[", ",", "]")}")
  with NoStackTrace
@Validation(CustomException(_)) case class CustomTest(a: Int Refined Positive)
Test.create(-2) // Left(CustomException("validation errors on CustomTest creation: [bla bla]"))

Ideally accept custom lambda into macro annotation:

@scala.annotation.compileTimeOnly("enable macro paradise to expand macro annotations")
class Validation[E](
  mapErrors: List[String] Refined NonEmpty => E = (errors: List[String] Refined NonEmpty) => errors
) extends scala.annotation.StaticAnnotation {
  def macroTransform(annottees: Any*): Any = macro ValidationMacros.apply
}

Support type aliases

  test("work with type alias") {
    type PositiveInt = Int Refined Positive
    @Validation case class Test(a: PositiveInt)
    // compilation fails
    assertEquals(Test.create(2), Validated.valid(Test(2))) 
    assertEquals(
      Test.create(-2),
      Validated.invalidNec[String, Test]("For field Test.ref: Predicate failed: (-2 > 0).")
    )
  }

create argument has type PositiveInt instead of int

Write documentation in README

  1. Motivation
  2. More complicated examples
  3. Installation guide (maven link, sbt copy-paste line)
  4. Future goals
  5. Current limitations, supported Scala versions

Support generic case classes

@Validation case class Test[T](a: T) // <- doesn't compile

Type parameters with their constraints should be propagated to generated create method parameters and argument types.

Get rid of cats.data.Validated

Validated is ok for proof of concept but it requires extra dependency on cats-core. There is no need to use it in external API.

  1. Change external API returning type to Either[List[String] Refined NonEmpty, C]
  2. Use self-made Validated or other error accumulation technique inside
  3. Remove cats-core from deps

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.