Skip to content

Commit

Permalink
feat!: typed validators (#118)
Browse files Browse the repository at this point in the history
### New Features
* **Typing**: Validators may have a specific input and especially output type.
* `V.objectType()` builder can be used to build an ObjectValidator with inferred type.
* Validator (output/result) type can be acquired with `VType<typeof validator>`. 
* Direct, chainable support for most used "next" validation rules (e.g. `V.number().min(1).max(2)`): 
  * `V.string()` supports `notEmpty`, `notBlank` and `pattern`.
  * `V.number()` supports `min` and `max`.

### Breaking changes: 
* V.string() and some other validators do not support String object as input any more.
* V.number() does not support Number object as input any more.
* Validators that accept multiple subvalidators (`V.optional`, `V.required`, `V.check`, `V.if`, `V.whenGroup`, `V.json` and `ObjectModel#next`) are combined using `V.compositionOf` instead of `V.allOf` as composition makes more sense in general. However, if there are multiple parents with next validators, those are still combined with `V.allOf` as they are not aware of each other.
* Internal Validator#validatePath returns now a promise (success, or reject) of value directly instead of ValidationResult
  • Loading branch information
ssaarela authored Nov 8, 2024
1 parent 24a7a43 commit 0331072
Show file tree
Hide file tree
Showing 23 changed files with 1,535 additions and 1,150 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"lerna": "8.1.2",
"prettier": "2.7.1",
"ts-node": "10.9.1",
"typescript": "5.2.2",
"typescript": "5.6.3",
"moment": "2.30.1",
"luxon": "3.4.4",
"@types/luxon": "3.4.2"
Expand Down
214 changes: 125 additions & 89 deletions packages/core/README.md

Large diffs are not rendered by default.

Loading

0 comments on commit 0331072

Please sign in to comment.