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)
}
We can actually make this much more simple (and powerful):
This generates metatada:
The real implementation will use a ES6 Map not an array...
The function
_createSchemaFromMetadata
becomes then very simple 👍The only missing bit is
.with('username', 'birthyear').without('password', 'access_token');
but we I think.required()
gets you the same.