-
Notifications
You must be signed in to change notification settings - Fork 3
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: typed validators #118
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #118 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 16 18 +2
Lines 3921 4182 +261
Branches 638 659 +21
==========================================
+ Hits 3921 4182 +261
|
94f6a79
to
f51a1ba
Compare
Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
* initial object type builder * number & string validator chaining Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
57f4db9
to
e85ed72
Compare
Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typing the existing validators is a large effort. This approach seems quite reasonable. Getting it to this point and releasing it as a beta version was a good idea.
As a general comment for the next updates, in a lot of cases the validators are still using any
for the input value. unknown
would behave the same way for the caller, and be much safer inside the validator function.
Breaking change: V.number() does not support Number object any more Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
* ObjectValidators parent next validators as allOf * V.array, V.if and V.whenGroup validators with multiple (compositionOf) item validators Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
…lidationResult wrapper * Validator#validatePath either returns Promise.resolve(value) or reject with violation(s) * This allows better type inference as failure case doesn't mix with success case Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
New Features
V.objectType()
builder can be used to build an ObjectValidator with inferred type.VType<typeof validator>
.V.number().min(1).max(2)
):V.string()
supportsnotEmpty
,notBlank
andpattern
.V.number()
supportsmin
andmax
.Breaking changes:
V.optional
,V.required
,V.check
,V.if
,V.whenGroup
,V.json
andObjectModel#next
) are combined usingV.compositionOf
instead ofV.allOf
as composition makes more sense in general. However, if there are multiple parents with next validators, those are still combined withV.allOf
as they are not aware of each other.