-
Notifications
You must be signed in to change notification settings - Fork 507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Transform Metadata is lost when importing class via dependency #1518
Comments
@whgoss Iʻm having this same issue...Iʻm not sure if theres a solution. When I import from a real folder in the project it works.. ..when I import the domain objects via paths..it doesnʻt..
This is a huge problem with how i want to use this... It works top level...but when the object contains @type annotations and other..they are ignored if its from the defined path in tsconfig...but not if its directly in the src folder. Iʻm wondering about symbolic links instead but this wouldnʻt really work for a real team environment.. |
iʻm further along....i need access to metadata storage somehow to attempt to fix it... |
@kalani96746 I'm using VS Code and am able to attach to my running process with that, enabling the breakpoints etc that are visible in the screenshots. As for the process itself, it's running in a Docker container but I'm sure there's a way to connect to a process outside Docker. Let me know if you need any more details. |
I am having the same issue, I have a package (common) with the entities of my application, in order to use them in the backend and in the frontend. When I use an entity imported from the package, the decorators of the entities are not working. |
I am facing the same issue where my common models are not transformed from plain objets. I checked and found that "defaultMetadataStorage" object is initialised as a separate object for every dependency. "_typeMetadatas" in this object is blank when main project is searching for metadata of the class |
Hello, it is indeed really hard to reproduce, just the setup would take up a lot of time. Thanks. |
Description
This is a complicated setup, so bear with me.
I have two projects, Project A and Project B. Project A is a library released through GitHub that is then imported into Project B. Project A contains Javascript and TypeScript, and is transpiled into Javascript via Babel with the type information exposed alongside the transpiled Javascript via
tsc --project tsconfig.types.json
(more on this later).When trying to use the imported classes with the TypeStack
@Transform()
decorator, the transform metadata does not appear to be coming across successfully from Project A to Project B. As you can see from the screenshot below, when running Project B theMetadataStorage
instance lists my imported class as a POJO instead of my class name (see entry 0 under_transformMetadatas
) and any associated properties are listed asundefined
. As a result, none of my@Transform()
decorators are working. Interestingly enough, all of my custom decorators in Project A are working fine in Project B, it's just transformations that appear to be broken.Now, I have painstakingly followed all of the proposed solutions/workarounds related to this ticket #384 to ensure that my
node_modules
structure is flattened. I've exposedclass-transformer
,class-validator
,class-transformer-validator
andreflect-metadata
as peer dependencies in Project A and ensured the versions are the same in both projects. I've verified that those dependencies only exist a single time in mynode_modules
directory in Project B and even pointed to the./node_modules/class-transformer
in mytsconfig.json
(see files below). I also addedimport 'reflect-metadata';
as the first line of code in Project B.My suspicion is that
MetadataStorage
is using the transpiled Javascript object and disregarding any information in the corresponding.d.ts
file.Project A
tsconfig.json
Project A
tsconfig.types.json
for emitting type informationProject B
tsconfig.json
Minimal code-snippet showcasing the problem
To show what's happening in my project, this is the class I'm trying to use that's in Project A and imported into Project B.
Here's the class I'm trying to transform into a
BandwidthWebhookApiRequest
viatransformAndValidate()
(using this wrapper package https://www.npmjs.com/package/class-transformer-validator):Expected behavior
I would expect this
ApiRequestArgs
to be successfully transformed into aBandwidthWebhookApiRequest
, with theApiRequestArgs.body
property being transformed into aBandwidthWebhook
and mapped to theBandwidthWebhookApiRequest.webhooks
property. Something like this:Actual behavior
What happens is that, because the transform metadata is malformed, it doesn't know how to apply custom transformation I set in my code and I'm simply given an empty
BandwidthWebhookApiRequest
object.After stepping through the class transformer code, the
transform()
function inTransformOperationExecutor.js
tries to map theApiRequestArgs.body
property toBandwidthWebhookApiRequest.body
instead of theBandwidthWebhookApiRequest.webhooks
(see the screenshot below).The text was updated successfully, but these errors were encountered: