Aliheym / typeorm-transactional

A Transactional Method Decorator for TypeORM that uses Async Local Storage or cls-hooked to handle and propagate transactions between different repositories and service methods.
MIT License
201 stars 27 forks source link

Support for AsyncLocalStorage? #22

Closed natoszme closed 11 months ago

natoszme commented 1 year ago

Hi there!

First of all, thanks for this implementation, seems really cool! I'm about to start a project using Nest and this was the best library I found for transaction management. The only thing stopping me from using it is the fact that cls-hooked uses async_hooks under the hood, which is considered unstable:

Stability: 1 - Experimental. Please migrate away from this API, if you can. We do not recommend using the createHook, AsyncHook, and executionAsyncResource APIs as they have usability issues, safety risks, and performance implications. Async context tracking use cases are better served by the stable AsyncLocalStorage API.

Is there any plan to migrate from cls-hooked to native's AsyncLocalStorage? I think it'd be an amazing stability improvement for this library. In fact there is this implementation for resolving quite the same problem (but without maintenance).

Thank you for your work!

Aliheym commented 1 year ago

Hi, I think that's a great idea. I've figured out AsyncLocalStorage more and I really like it. I think it would be a good idea to use it and drop the cls-hooked dependency. Thanks for this point.

The only thing I'm worried about is that now we'll have to stop to support some versions of Node.js.

natoszme commented 1 year ago

I know that it may not be so simple, but something similar to what cls-hooked does may be done (using cls-hooked for node < 16, AsyncLocalStorage for node >= 16)

natoszme commented 1 year ago

hi there! @Aliheym are there any plans to implement this one? thanks!

Aliheym commented 1 year ago

hi there! @Aliheym are there any plans to implement this one? thanks!

Hi, yes. I am planning to start to implement it on this week. 🙂

ahmedkoshek commented 1 year ago

Hi @Aliheym, any updates on supporting AsyncLocalStorage. The only thing stopping me from using it is the fact that cls-hooked uses async_hooks under the hood, which is considered unstable.