Skip to content

Commit

Permalink
Merge pull request #31 from bsh-generator/inline-validator
Browse files Browse the repository at this point in the history
Inline validator
  • Loading branch information
bsh-generator authored Oct 30, 2024
2 parents 9ebbc77 + 98b44d4 commit d2f82fb
Show file tree
Hide file tree
Showing 46 changed files with 633 additions and 1,755 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release
on:
push:
branches:
- main
- beta
pull-request:
branches:
- main
- beta

jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: read
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install

- name: Run tests
run: npm test

- name: Build project
run: npm run build
77 changes: 55 additions & 22 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@

# Changelog

## Previous Releases

### 0.6.5

- fix some issues.
- give the access to all library types.
- introduce inline validator, to validate primitive values:

````ts
import { v, m } from 'src'

type Ctx = { role: string } // the context
const emailValidator = v.primitive<string /* type */, Ctx /* context? */>(
v.string().required().email() /* validations */
)

emailValidator.apply("test.com")

console.log(emailValidator.valid) // false
console.log(emailValidator.message) // Invalid email format
````

- fix some bugs

### 0.6.0

- add validator status to define the status of the validator after being executed [#commet](https://github.com/bsh-generator/bshg_validation_ts/tree/7901e77f88f88bf047af7ff9dc78a62363d39abb)
- update the loggers [#commet](https://github.com/bsh-generator/bshg_validation_ts/tree/a8476b8b069e5eeab001203c464e13a45401ccd2)
- add validator status to define the status of the validator after being
executed [#commet](https://github.com/bsh-generator/bshg_validation_ts/tree/7901e77f88f88bf047af7ff9dc78a62363d39abb)
- update the
loggers [#commet](https://github.com/bsh-generator/bshg_validation_ts/tree/a8476b8b069e5eeab001203c464e13a45401ccd2)
- start using tests in the library
- Simplify Access to Validation Status and Messages [#2](https://github.com/bsh-generator/bshg_validation_ts/issues/2)

Expand All @@ -28,19 +51,19 @@
- **Improved Documentation**: Clearer and more comprehensive.

- **Async Validation**:
- Support for asynchronous validation rules with `onErrorAsync()`.
- Async batch validations for multiple objects.
- Support for asynchronous validation rules with `onErrorAsync()`.
- Async batch validations for multiple objects.

- **Context Validation**:
- Alter validation behavior based on context information.
- Dynamic rules based on specific conditions.
- Alter validation behavior based on context information.
- Dynamic rules based on specific conditions.

- **Unified Error Messages**:
- Single `message` property for both string and function messages.
- Single `message` property for both string and function messages.

- **Bug Fixes**:
- Stability and performance improvements.
- Enhanced date comparison logic.
- Stability and performance improvements.
- Enhanced date comparison logic.

### 0.3.2

Expand All @@ -54,37 +77,44 @@

### 0.3.0

- remove `validationResult` from validator options, and replace it with methods for more type safe for the return type of the validation.
- remove `validationResult` from validator options, and replace it with methods for more type safe for the return type
of the validation.
- Develop new way to validate:
- `.validate(): boolean`: return true if the validation passes.
- `.validateInfo(): {success, results}`: return object with the validation details if it fails.
- `.validateThrow()`: throw an Error of type `BshValidationError` if validation fails.
- `.validate(): boolean`: return true if the validation passes.
- `.validateInfo(): {success, results}`: return object with the validation details if it fails.
- `.validateThrow()`: throw an Error of type `BshValidationError` if validation fails.
- update validate methods to accept object to be validated, as you can still using `.init()`
- Introduce `v.template<Type>()`: create template for validators to instantiate validators from it.
- Introduce `validator.options(ValidatorOptions)`: override the default options.
- Introduce `Batch Validation`: Enable batch validation of multiple objects or fields at once, returning aggregated results.
- Introduce `Batch Validation`: Enable batch validation of multiple objects or fields at once, returning aggregated
results.
- Provide multi-language support for validation messages, allowing users to define error messages in various languages.

### 0.2.0

- Added `.as()` method to the following validators: `v.string()`, `v.number()`, `v.boolean()`, `v.time()`, `v.date()`, `v.datetime()`. This method allows comparison with a property of the parent object.
- Introduced `.onError<ParentType>()` method to enable custom validation based on the value of the field and the parent object.
- Added `.as()` method to the following validators: `v.string()`, `v.number()`, `v.boolean()`, `v.time()`, `v.date()`,
`v.datetime()`. This method allows comparison with a property of the parent object.
- Introduced `.onError<ParentType>()` method to enable custom validation based on the value of the field and the parent
object.
- Added `%name` placeholder to dynamically include the field name in error messages.

These updates enhance the functionality and flexibility of the validation library, providing more options for custom validations and error message customization.
These updates enhance the functionality and flexibility of the validation library, providing more options for custom
validations and error message customization.

### 0.1.1

- add dynamic messages: now you can use functions for you validation messages
- add `%val` to use it in messages string to be replaced with actual field value.
- rename `.add()` -to add costumes validations- to `.onError()`
- fix issue of marking the validator functions type as undefinable by default:
- make validator function use generics to set the type as undefinable `v.string<string | undefined>()`. by default is take type `string`, and the same for the other.
- add `.undefined()` to validator functions to mark types as undefinable.
- make validator function use generics to set the type as undefinable `v.string<string | undefined>()`. by default
is take type `string`, and the same for the other.
- add `.undefined()` to validator functions to mark types as undefinable.

### 0.1.0

#### Features:

- Upgraded the library to use functions instead of extending classes, enhancing flexibility and ease of use.
- Expanded validation methods to cover various types, increasing validation options.
- Introduced the `v.costume<T>()` method, enabling users to create validators for custom types.
Expand All @@ -93,15 +123,18 @@ These updates enhance the functionality and flexibility of the validation librar
- Introduced `v.configure()` method for configuring the library according to user preferences.
- Made regex and error messages configurable, providing customization options.
- Enhanced compatibility with both front-end and back-end projects for seamless integration.
- Introduced `.import(results)` method for importing validation results from backend to frontend, facilitating sharing of results across environments.
- Introduced `.import(results)` method for importing validation results from backend to frontend, facilitating sharing
of results across environments.

#### Improvements:

- Improved documentation and logging for better clarity and understanding.
- Enhanced error handling and reporting for smoother user experience.
- Optimized performance for faster validation processes.
- Streamlined code structure for better maintainability and readability.

These updates aim to provide users with a more versatile and customizable validation library, ensuring smoother integration and enhanced validation capabilities across various project environments.
These updates aim to provide users with a more versatile and customizable validation library, ensuring smoother
integration and enhanced validation capabilities across various project environments.

### 0.0.7

Expand Down
7 changes: 6 additions & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## Our Pledge

We as members, contributors, and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion.
We as members, contributors, and maintainers pledge to make participation in our project and our community a
harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and
expression, level of experience, nationality, personal appearance, race, religion.

## Our Standards

Expand Down Expand Up @@ -104,6 +106,9 @@ For answers to common questions about this code of conduct, see the FAQ at
[https://www.contributor-covenant.org/translations][translations].

[homepage]: https://www.contributor-covenant.org

[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html

[faq]: https://www.contributor-covenant.org/faq

[translations]: https://www.contributor-covenant.org/translations
7 changes: 5 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ your contribution.

## Initial steps

Before you start working on a contribution, create an issue describing what you want to build. It's possible someone else is already working on something similar, or perhaps there is a reason that feature isn't implemented. The maintainers will point you in the right direction.
Before you start working on a contribution, create an issue describing what you want to build. It's possible someone
else is already working on something similar, or perhaps there is a reason that feature isn't implemented. The
maintainers will point you in the right direction.

<!-- ## Submitting a Pull Request
Expand All @@ -33,7 +35,8 @@ The following steps will get you setup to contribute changes to this repo:

5. implementing your feature.

6. You can do some simple experimentation in [`playgrounds`](./playgrounds) - there you will find some ready project like angular, reactjs.
6. You can do some simple experimentation in [`playgrounds`](./playgrounds) - there you will find some ready project
like angular, reactjs.

7. run the [link-playgrounds.sh](link-playgrounds.sh) script to link the project with the library code.

Expand Down
Loading

0 comments on commit d2f82fb

Please sign in to comment.