feat: add standard schema support and associated tests #2588
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds the support for standard schema, by copying their interface, extending the validator with it, and mapping class validator's "Validation Error" type to standard schema's "Issue".
I also wrote some tests, which are the same as the "nested validation" ones.
Since this function would be in the hot path, I tried to make it optimized, by avoiding recursion and preferring mutation to copy.
Supporting the Standard Schema interface is important, since it's blocking the adoption of it by NestJs (see related nestjs/nest/#14539)
edit: by itself, the PR in its current form would not be enough. We need to add a wrapper function, that takes a schema as input, and that outputs a validator containing the schema. Let me know if it sounds good to you.
Disclosure
I had to ignore the ESLint warning when copying the standard schema interface.
Checklist
Update index.md
)develop
)npm run prettier:check
passesnpm run lint:check
passesFixes
addresses #2577