elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
9.74k stars 207 forks source link

🐞 fix: implement normalization support for class instances with getter functions #718

Closed m1212e closed 1 month ago

m1212e commented 1 month ago

When returning class instances which use getter functions, normalization does not work in stripping those fields. Typeboxes Clean does not remove getter instances on objects in certain scenarios. This came to my mind because the prisma ORM uses this when defining extensions resulting in the inability to return database query outputs directly. My PR adjusts the clean call to traverse the prototype tree of a passed object, gathering all values located behind a get call and merging them with the original value. It does so in a performance sensitive manner, I check if the operations are required before blindly applying them.

Would be great if you could take a look @SaltyAom and I'd be happy to receive feedback/make any necessary changes. Thanks for your work!

m1212e commented 1 month ago

https://github.com/sinclairzx81/typebox/issues/842