jayalfredprufrock / nestjs-typebox

Various utilities for integrating Typebox and NestJs for both validation and OpenApi schema generation
MIT License
26 stars 4 forks source link

❓ 3.0 Release Requirements #57

Closed JoeHillyard closed 4 weeks ago

JoeHillyard commented 4 months ago

I am looking to migrate multiple Nest projects to drizzle and this library would be a huge help!

I can see that 3.0 is in pre-release, what are the requirements for the final release? Any good first issues I can help with?

Thanks!

jayalfredprufrock commented 4 months ago

Hi there, the main reason I have been holding off on v3 is I have been hoping somebody would package a generic typebox-based validation library that could do most of the heavy lifting for validating and transforming request/response payloads so this library could focus mainly on nest integration, decorators, openapi support, etc. There has been quite a lot of movement in typebox around transformers, error handling when using complex union types, cleaning/default values, etc., but typebox is meant to be fairly low-level and requires registering custom formatters for even standard things like validating emails. (though the maintainer has example implementations for many popular formats). An opinionated layer on top that smooths out some of the complexities is what I'm hoping to find/build.

Otherwise, I consider v3 stable and use it in several production APIs. I'll likely do another review of existing libraries soon and hopefully find a suitable library to integrate with. I don't mind writing it myself, but it would probably be better as a separate library so the wider typebox community could benefit. Just as soon as I have a longer-term plan in place I'll lift the pre-release flag and announce a public roadmap for the future. In the meantime, please send any issues/ideas my way to improve this library, as I do have every intention to keep supporting it while I use NestJs as my daily driver framework.

JoeHillyard commented 1 month ago

Could this library do some of that heavy lifting? Appreciate it's a little dated now, just making sure I understand the scope of what you want this library to do / not do.

jayalfredprufrock commented 4 weeks ago

@JoeHillyard Just released v3. Typebox now has a canonical approach to sanitizing/transforming/defaults that requires much less boilerplate and provides full support for complex union/intersection types. I was able to replace much of the fragile code I hacked together with a similar approach to Typebox's parse utility: https://github.com/sinclairzx81/typebox/blob/master/src/value/parse/parse.ts

The main difference in my implementation is this library will walk the schemas at startup time, caching any references, and keeping track of whether each schema utilizes defaults and/or transforms. This allows the validation step to skip walking the schema multiple times when defaults/transforms aren't being used.

My current projects aren't utilizing transforms or defaults, but some quick sanity tests all appear to be working just fine. I'm going to close this out now that v3 is released. Do let me know if you run across any issues using this new approach. Thanks!