feat(export): export defaultMetadataStorage
Description
This PR exports default metadata storage which allow picking & subclassing class decorated with class-transfomer.
Checklist
- [x] the pull request title describes what this PR does (not a vague title like
Update index.md) - [x] the pull request targets the default branch of the repository (
develop) - [x] the code follows the established code style of the repository
-
npm run prettier:checkpasses -
npm run lint:checkpasses
-
- [x] tests are added for the changes I made (if any source code was modified)
- [x] documentation added or updated
- [x] I have run the project locally and verified that there are no errors
Fixes
fixes #[issue number], fixes #[issue number]
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
This is related to this issue: https://github.com/typestack/class-transformer/issues/815 This is needed for https://github.com/typestack/class-transformer/issues/563
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 🙏
is there any update on the status of this PR?
A very useful and necessary feature