Closed Patton-L closed 8 months ago
Hm, if I remember correctly, there was some issue with proxying functions instead of objects. If I remember correctly, JavaScript then complained, that the object's signature doesn't implement the [[Call]]
method or something, so that's why I used a function as the "target", which has all features of objects in addition to being callable.
The problem is, that we don't know the actual type before creating the proxy. It ts created at bootstrap, but the instance it proxies to is created on each request anew. And the Proxy cannot trap the typeof
call :(
Can you tell me what your use-case is? I will try to revisit if there's some way to get around this.
@Papooch the usecase is using nestjs-cls with typeorm 0.3.17 (we used to use 0.2.34). After we upgraded to 0.3.17, then this line of code (where isDataSource
is defined here) ended up being false since the proxy was a function instead of object
the usecase is switching on the typeorm DataSource
depending on a header value passed in a request (req.headers
)
I see, hmm. Your options are currently:
cls.get(...)
.I'll try to think of some other way in the new version and add this information to the documentation.
A fix has been merged and will be released in a future version (v4
) together with other breaking changes and features.
Proxy is defined as
()=>null
at https://github.com/Papooch/nestjs-cls/blob/main/packages/core/src/lib/proxy-provider/proxy-provider-manager.ts#L95C20-L95C25Is there a specific reason for doing that instead of defining it as an empty object? It's causing object retrieved from cls has
typeof proxiedObject
equal to function instead of object.