Skip to content

Commit

Permalink
Generate types for metadata attribute properties
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdwater committed Sep 3, 2024
1 parent 58bd02c commit c11f356
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface Property {
| "widgets"
| "selection";
isList?: string;
isMetaData?: string;
defaultValue?: string;
required?: string;
isDefault?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,22 @@ function toClientPropType(
.flatMap(ats => ats.attributeType)
.map(at => toAttributeClientType(at.$.name));
const unionType = toUniqueUnionType(types);

const linkedToDataSource = !!prop.$.dataSource;

if (prop.$.isMetaData === "true") {
if (!linkedToDataSource) {
throw new Error(`[XML] Attribute property can only have isMetaData="true" when linked to a datasource`);
}
return `AttributeMetaData<${unionType}>`
}

if (!prop.associationTypes?.length) {
return prop.$.dataSource ? `ListAttributeValue<${unionType}>` : `EditableValue<${unionType}>`;
return toAttributeOutputType("Reference", linkedToDataSource, unionType);
}
else {
const reftypes = prop.associationTypes
.flatMap(ats => ats.associationType)
.map(at => toAttributeOutputType(at.$.name, !!prop.$.dataSource, unionType));
.map(at => toAttributeOutputType(at.$.name, linkedToDataSource, unionType));
return toUniqueUnionType(reftypes);
}
}
Expand Down

0 comments on commit c11f356

Please sign in to comment.