Skip to content

Instantly share code, notes, and snippets.

@dgonzalez
Last active October 14, 2019 14:49
Show Gist options
  • Save dgonzalez/d1ce21f6f280e69a7969dbb03c2909d0 to your computer and use it in GitHub Desktop.
Save dgonzalez/d1ce21f6f280e69a7969dbb03c2909d0 to your computer and use it in GitHub Desktop.
joi-validators

joi-decorators

What do we want?

Something similar to (roughly, not even syntactically ok):

------
class User {
  @Min(10)
  @Max(10)
  @NotNull
  private _name: string
}
------ or
class User {
  private _name: string

  @Min(10)
  @Max(10)
  @NotNull
  set name (): string {

  }
}

validator = new JoiValidator(...) // <- this is what we want.

user:User = new User(...)

errors:Error = validator.validate(user)

for (let error:Error of errors) {
  console.log(error)
}

@dgonzalez
Copy link
Author

I can see a problem with it... we are then tied to Joi which it is fine because it is a de-facto standard but we need to compromise on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment