Papooch / nestjs-cls

A continuation-local storage (async context) module compatible with NestJS's dependency injection.
https://papooch.github.io/nestjs-cls/
MIT License
389 stars 23 forks source link

fix(core): handle nested context correctly with UseCls decorator #119

Closed alexandre-abrioux closed 5 months ago

alexandre-abrioux commented 5 months ago

Issue

Methods decorated with @UseCls() (without runOptions) are not called when running inside a parent context.

Fix

This PR prepends the default options to the options passed down to the cls.run(options, callback) function. This way, options.ifNested is always defined (default to inherit), and the callback is always triggered in the switch (options.ifNested) ... case block.

Since @UseCls() calls run with an empty options object: cls.run({}, callback) ; it fixes the issue 👍

Papooch commented 5 months ago

Thank you for finding and fixing all these issues 💪 I'll get to revieving them as soon as I get to a computer!