v5 discussion #189
Replies: 3 comments 6 replies
-
Btw, any v5 release ETA? |
Beta Was this translation helpful? Give feedback.
-
Log of the progress notices on Goyave's Discord29/09/2022As you may know, v5 is a rewrite of a big portion of the framework. I am working on each core package and try to improve them.
25/10/2022Yesterday and today I managed to add support for map validation. That means that you will be able to validate an object and its properties without knowing the properties name (like a In the following example: all properties of the object "object" in the body must be integers (and there must be at least one property in the object) func WildcardValidation(r *goyave.RequestV5) v.RuleSetV5 {
return v.RuleSetV5{
"object.*": v.ListV5{v.Required(), v.Integer()},
}
} 26/10/2022When using numeric validation rules (integer or float validation), you will be able to specify the target bit size. For example, you may want an int that fits into an I had the idea to do this when I encountered an error when inserting a DB record with a smallint type, but the input was larger than what smallint can store, leading to a DB error. It will be easier to make sure this doesn't happen with these new validators. 12/11/2022Today I implemented the auth package for v5. It is still untested though. Although the development of v5 is very slow, we are one step closer to a preview release. Once the existing packages are upgraded, I would like to start creating preview releases to let everyone try it out and hopefully get some feedback. This process would be very flexible because I would still be able to change things according to feedback before deciding to freeze one design aspect. Preview releases won't be documented as well as the current v4 release, and won't be stable. Tests will be written with time and documentation when I am certain the design won't change anymore. Breaking changes between two preview releases are to be expected. 13/11/2022Today I settled for a new concept: Components. A Component is simply a structure that has access to all server resources (config, loggers, db, lang). Here is a list of examples of structures that you already are familiar with that are now components:
This new concept was necessary since we moved on from an all-global system. As all components of a Goyave app may need access to those resources, I decided to add some convenience to avoid having to pass config and DB instances around all the time. I also implemented the 23/11/2022I had some time this week to work on Goyave. I decided to rewrite the core part of the validation system again to solve some issues with it. Namely the validation order and comparison. Rule sets are now a slice instead of a map, which lets developers define the exact order they want fields to be validated. This reduces the validation package complexity and reduces the non-explicit behaviors. The syntax is a little bit heavier than before (due to the necessity to add keyed fields to struct literals), but I think the change is worth it. Example: func BodyValidation(r *goyave.Request) v.RuleSet {
return v.RuleSet{
{Path: "field", Rules: v.Lis{
v.Required(),
v.Int(),
}},
{Path: "array", Rules: v.List{
v.Required(),
v.Array(),
v.Between(3, 50),
}},
{Path: "array[]", Rules: v.List{
v.Int(),
v.Between(4, 5),
}},
{Path: "foo", Rules: v.List{
v.Required(),
v.GreaterThan("array[]"),
}},
{Path: "composed", Rules: OtherBodyValidation(r)},
}
} I successfully implemented func BodyValidation(r *goyave.Request) v.RuleSet {
return v.RuleSet{
{Path: "a", Rules: v.List{
v.Required(),
v.Bool(),
}},
{Path: "b", Rules: v.List{
v.RequiredIf(func(ctx *v.Context) bool {
// Using a path here is not necessary since it's a very simple case
// But in a more complex scenario, using a path like this makes retrieving data
// much easier and safer.
c := walk.MustParse("a").First(ctx.Data)
if c.Found != walk.Found {
return false
}
return c.Value.(bool) // Type-assert is safe since we know "a" has been validated already
}),
v.Float64(),
}},
}
} I am happy with the new implementation of the validator. It feels more robust and more explicit while removing a lot of code complexity. I still need to write a lot of tests and implement all the already existing validation rules. I also wanted to talk about a new schedule at my company, which will help me get more time to develop the framework. Every 4 weeks I will have more time to work on the framework from now on. Outside of these weeks, don't expect to see any progress made for v5. |
Beta Was this translation helpful? Give feedback.
-
I'm proud to present the first preview version! I'm looking forward to hearing your feedback! |
Beta Was this translation helpful? Give feedback.
-
I'm starting to think a bit more about v5 and would like to discuss my ideas with the community. This post is mostly a place where I brainstorm and you are invited to join if you want to, your feedback is always welcome!
samber/lo
.The changes would be so big that a big part of the code-base would have to be rewritten and projects using v4 would probably not be able to upgrade. In short, there would be big design shifts. Therefore whenever v5 releases, I would like to keep maintaining a v4 branch.
Beta Was this translation helpful? Give feedback.
All reactions