UNPKG

@tsed/schema

Version:
34 lines (33 loc) 1.13 kB
import { DecoratorTypes, isArray } from "@tsed/core"; import { JsonEntityFn } from "./jsonEntityFn.js"; /** * @ignore */ function groupsClass(groups, entity) { const entries = Object.entries(groups[0]); entity.children.forEach((propEntity) => { const groups = entries.filter(([, props]) => props.includes(propEntity.propertyName)).map(([key]) => key); const decorator = Groups(...groups); decorator(propEntity.target, propEntity.propertyKey); }); } export function Groups(...groups) { return JsonEntityFn((entity) => { if (entity.is(DecoratorTypes.CLASS)) { groupsClass(groups, entity); return; } if (entity.is(DecoratorTypes.PROP)) { entity.schema.groups(groups, true); return; } if (entity.is(DecoratorTypes.PARAM)) { let groupsName = ""; if (groups.length == 2 && isArray(groups[1])) { groupsName = groups[0]; groups = groups[1]; } entity.parameter.schema().groups(groups).groupsName(groupsName); } }); }