Skip to content

Commit

Permalink
fix(classes): merge metadata from Reflection and Factory fn
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Feb 19, 2021
1 parent d700af2 commit 393a7d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Empty file.
17 changes: 7 additions & 10 deletions packages/classes/src/lib/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,13 @@ function exploreMetadata(
for (const model of models) {
// if metadataStorage hasn't had metadata of the model
if (!metadataStorage.has(model)) {
// get the metadata from Reflection then populate metadataStorage and instanceStorage
let metadataList = Reflect.getMetadata(
AUTOMAP_PROPERTIES_METADATA_KEY,
model
);
// if no metadata, try getting from METADATA_FACTORY function
if (!isDefined(metadataList)) {
metadataList = (model as any)[AUTOMAPPER_METADATA_FACTORY_KEY]?.();
if (!isDefined(metadataList)) continue;
}
// get the metadata from Reflection and AUTOMAPPER_METADATA_FACTORY then populate metadataStorage and instanceStorage
const metadataList = [
...(Reflect.getMetadata(AUTOMAP_PROPERTIES_METADATA_KEY, model) || []),
...((model as any)[AUTOMAPPER_METADATA_FACTORY_KEY]?.() || []),
];
// if no metadata, skip
if (!isDefined(metadataList)) continue;
// loop through metadata list
for (const [propertyKey, { typeFn, depth }] of metadataList) {
metadataStorage.addMetadata(model, [propertyKey, typeFn]);
Expand Down

0 comments on commit 393a7d3

Please sign in to comment.