Skip to content
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

feat(export): export defaultMetadataStorage #1715

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

thongxuan
Copy link

Description

This PR exports default metadata storage which allow picking & subclassing class decorated with class-transfomer.

Checklist

  • the pull request title describes what this PR does (not a vague title like Update index.md)
  • the pull request targets the default branch of the repository (develop)
  • the code follows the established code style of the repository
    • npm run prettier:check passes
    • npm run lint:check passes
  • tests are added for the changes I made (if any source code was modified)
  • documentation added or updated
  • I have run the project locally and verified that there are no errors

Fixes

fixes #[issue number], fixes #[issue number]

@diffy0712
Copy link

Hello @thongxuan,

did you create any issue (or could you find any open issue) for this pr detailing the need for this? If not, could you please describe when would this export be used?

Thank you

@scottwday
Copy link

This is related to this issue: #815
This is needed for #563

@elliot-sabitov
Copy link

elliot-sabitov commented Oct 3, 2024

Hello @thongxuan,

did you create any issue (or could you find any open issue) for this pr detailing the need for this? If not, could you please describe when would this export be used?

Thank you

We use defaultMetadataStorage to get typeMetadata like so:

const typeMeta = classTransformerMetadataStorage.findTypeMetadata(
            meta.target,
            meta.propertyName,
          )

Which is convenient in cases where you have a @Type(() => MyClass) annotation on a class property, and you want to get the MyClass for instantiation or other purposes, we then can call typeMeta.typeFunction()to get the MyClass in this case.

We have generic components that parse a schema maintained in a set of class-validator and class-transformer annotated classes, and these components utilize these annotation values to render Vite/React UI components or handle micro-service endpoint logic utilizing routing-controllers.

Having this default metadata storage being exportable would be super helpful! Right now, we have to have it like this:

import { defaultMetadataStorage } from 'class-transformer/cjs/storage.js';

but this may require additional configuration and it would be much better if we can simply just do:

import { defaultMetadataStorage } from 'class-transformer';

and be able to utilize defaultMetadataStorage where applicable 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants