MCPcopy Create free account
hub / github.com/zenstackhq/zenstack / getAllFields

Function getAllFields

packages/language/src/utils.ts:635–660  ·  view source on GitHub ↗
(
    decl: DataModel | TypeDef,
    includeIgnored = false,
    seen: Set<DataModel | TypeDef> = new Set(),
)

Source from the content-addressed store, hash-verified

633 * Gets all fields of a data model or type def, including inherited fields from base models and mixins.
634 */
635export function getAllFields(
636 decl: DataModel | TypeDef,
637 includeIgnored = false,
638 seen: Set<DataModel | TypeDef> = new Set(),
639): DataField[] {
640 if (seen.has(decl)) {
641 return [];
642 }
643 seen.add(decl);
644
645 const fields: DataField[] = [];
646 for (const mixin of decl.mixins) {
647 if (mixin.ref) {
648 fields.push(...getAllFields(mixin.ref, includeIgnored, seen));
649 }
650 }
651
652 if (isDataModel(decl) && decl.baseModel) {
653 if (decl.baseModel.ref) {
654 fields.push(...getAllFields(decl.baseModel.ref, includeIgnored, seen));
655 }
656 }
657
658 fields.push(...decl.fields.filter((f) => includeIgnored || !hasAttribute(f, '@ignore')));
659 return fields;
660}
661
662/**
663 * Gets all attributes of a data model or type def, including inherited attributes

Callers 15

mixin.test.tsFile · 0.90
scopeProviderMethod · 0.90
validateMethod · 0.90
validateFieldsMethod · 0.90
typeDefHasModelFieldMethod · 0.90
validateRelationFieldMethod · 0.90
isIdFieldFunction · 0.90
getIdFieldsFunction · 0.90

Calls 3

isDataModelFunction · 0.90
pushMethod · 0.80
hasAttributeFunction · 0.70

Tested by

no test coverage detected