Skip to content

Commit

Permalink
throw error to warn no metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
iyobo committed Oct 21, 2023
1 parent 5f77521 commit 43983cb
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/util/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ export function ensureArray<T>(item: T | T[]): T[] {
}

export function getPropertiesOfClassValidator(targetConstructor: Function): Record<string, string[]> {
const metadataStorage = getMetadataStorage();
const targetMetadatas = metadataStorage
.getTargetValidationMetadatas(targetConstructor, undefined, false, false, undefined);
const groupedMetadatas = metadataStorage.groupByPropertyName(targetMetadatas);
return Object.fromEntries(Object.entries(groupedMetadatas).map(([property, decorators]) => {
const CM = decorators.map(decorator => metadataStorage.getTargetValidatorConstraints(decorator.constraintCls).map(v => v.name));
return [property, CM.flat()];
}));
try {
const metadataStorage = getMetadataStorage();
const targetMetadatas = metadataStorage
.getTargetValidationMetadatas(targetConstructor, undefined, false, false, undefined);
const groupedMetadatas = metadataStorage.groupByPropertyName(targetMetadatas);
return Object.fromEntries(Object.entries(groupedMetadatas).map(([property, decorators]) => {
const CM = decorators.map(decorator => metadataStorage.getTargetValidatorConstraints(decorator.constraintCls).map(v => v.name));
return [property, CM.flat()];
}));
}catch(e){
throw new Error('There was an error trying to read decorator metadata. This typically happens when you build your TS code with a compiler like EsBuild that does not respect the "emitDecorators:true" configuration. Please recompile your amala project with tsc or a derivative/combination that involves tsc.')
}
}

const cvCodex = {
Expand Down

0 comments on commit 43983cb

Please sign in to comment.