diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1bd1d1c..6a9d085 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,6 @@ name: CI -on: [push] +on: [push, pull_request] jobs: lint: diff --git a/CHANGELOG.md b/CHANGELOG.md index 22ddefc..9ab3cef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,23 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + ## [Unreleased] +## [3.0.0] - 2025-05-16 + +### Changed +- Updated contribution guidelines. +- Updated CI workflow to run on Pull Request. +- Updated README.md to include more information and examples of code usage as well as corrected some old examples. +- Added contributors to the CONTRIBUTORS file. + +### Deleted +- Removed `uuid` as a dependency. + +### Added +- Added explanation about chaining API to README.md. + ## [2.0.1] - 2024-07-16 ### Changed @@ -57,7 +72,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added base source code files for the project. - Base `README.md` file. -[unreleased]: https://github.com/Naapperas/zon/compare/v2.0.1...HEAD +[Unreleased]: https://github.com/Naapperas/zon/compare/v3.0.0...HEAD +[3.0.0]: https://github.com/Naapperas/zon/compare/v2.0.1...v3.0.0 [2.0.1]: https://github.com/Naapperas/zon/compare/v2.0.0...v2.0.1 [2.0.0]: https://github.com/Naapperas/zon/compare/v1.1.0...v2.0.0 [1.1.0]: https://github.com/Naapperas/zon/compare/v1.0.0...v1.1.0 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d356b13..19b4191 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,3 +36,8 @@ Pull requests should be used to propose changes to the codebase. When creating a - **All pull requests** should be tagged with the appropriate labels. If you are unsure about which labels to use, please use the `help wanted` label. - **All pull requests** should (but are not strictly required to) be accompanied by a description of the alternatives considered when making the changes in the pull request. +All changes must be summarized in [CHANGELOG.md](CHANGELOG.md). + +Furthermore, new contributors can add themselves to the list of contributors, present at [CONTRIBUTORS](CONTRIBUTORS). + + diff --git a/CONTRIBUTORS b/CONTRIBUTORS index b90c860..abf3634 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1 +1,3 @@ -Nuno Pereira \ No newline at end of file +Nuno Pereira +cachho +Almas Akchabayev <> \ No newline at end of file diff --git a/README.md b/README.md index ddfc787..a5f0df1 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,42 @@ In its essence, `zon` behaves much like `zod`. If you have used `zod`, you will > [!NOTE] > There are some differences in the public API between `zon` and `zod`. Those mostly stem from the fact that Python does not have type inference like Typescript has. There are other slight deviations between `zon` and `zod`. +### General + +#### Validate + +To validate against a schema, use `validator.validate()` + +```python +validator = zon.string() +message = validator.validate("Hello World!") # returns 'Hello World!' +``` + +Alternatively, you may use `validator.safe_validate()`. +`save_validate` will tell you whether the validation was successful, without throwing an error. Depending on the needs of your project, you can do this to handle exceptions more elegantly. + +```python +validator = zon.string() +success, message = validator.safe_validate("Hello World!") # returns (True, 'Hello World!') +``` + +#### Chaining + +Most validators can be chained together, just like `zod`: + +```python +validator = zon.string().min(5).max(10).email() +``` + +This is equivalent to: + +```python +validator = zon.string() +validator = validator.min(5) +validator = validator.max(10) +validator = validator.email() +``` + ### Basic types `zon` features most of `zod`'s basic types: @@ -147,7 +183,7 @@ zon.element_list(zon.string()) Like strings, lists also have some extra methods that check the length of the list: ```python -validator = zon.list(...) +validator = zon.element_list(...) validator.min(5) validator.max(10) @@ -187,7 +223,7 @@ validator = zon.record({ "name": zon.string(), "age": zon.number(), "isAwesome": zon.boolean(), - "friends": zon.array(zon.string()), + "friends": zon.element_list(zon.string()), "address": zon.record({ "street": zon.string(), "city": zon.string(), diff --git a/pyproject.toml b/pyproject.toml index f9f8f96..25fb16a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "zon" -version = "2.0.0" +version = "3.0.0" authors = [ { name="Nuno Pereira", email="nunoafonso2002@gmail.com" }, ] @@ -21,8 +21,7 @@ classifiers = [ ] dependencies = [ "validators>0.28", - "typing_extensions>4.12", - "uuid==1.30" + "typing_extensions>4.12" ] [project.optional-dependencies] diff --git a/zon/__init__.py b/zon/__init__.py index 4d346c3..4b8e596 100644 --- a/zon/__init__.py +++ b/zon/__init__.py @@ -6,7 +6,7 @@ # Why is this needed even? from __future__ import annotations -__version__ = "2.0.0" +__version__ = "3.0.0" __author__ = "Nuno Pereira" __email__ = "nunoafonso2002@gmail.com" __license__ = "MIT" @@ -181,7 +181,9 @@ def _default_validate(self, data: T, ctx: ValidationContext) -> T: ) @final - def _validate(self, data: T) -> tuple[Literal[True], T] | tuple[Literal[False], ZonError]: + def _validate( + self, data: T + ) -> tuple[Literal[True], T] | tuple[Literal[False], ZonError]: """Validates the supplied data. Args: