Skip to content

Commit

Permalink
Add support for reference sets(beta) to the typings generator
Browse files Browse the repository at this point in the history
  • Loading branch information
alihcsumer committed Jun 13, 2024
1 parent b572e26 commit 6821de6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ const mxExports = [
"ActionValue",
"DynamicValue",
"EditableValue",
"EditableListValue",
"FileValue",
"ListValue",
"NativeIcon",
"NativeImage",
"ListActionValue",
"ListAttributeValue",
"ListAttributeListValue",
"ListExpressionValue",
"ListReferenceValue",
"ListReferenceSetValue",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,16 @@ function toClientPropType(
.flatMap(ats => ats.attributeType)
.map(at => toAttributeClientType(at.$.name));
const unionType = toUniqueUnionType(types);
return prop.$.dataSource ? `ListAttributeValue<${unionType}>` : `EditableValue<${unionType}>`;

if (!prop.associationTypes?.length) {
return prop.$.dataSource ? `ListAttributeValue<${unionType}>` : `EditableValue<${unionType}>`;
}
else {
const reftypes = prop.associationTypes
.flatMap(ats => ats.associationType)
.map(at => toAttributeOutputType(at.$.name, !!prop.$.dataSource, unionType));
return toUniqueUnionType(reftypes);
}
}
case "association": {
if (!prop.associationTypes?.length) {
Expand Down Expand Up @@ -278,6 +287,17 @@ export function toAssociationOutputType(xmlType: string, linkedToDataSource: boo
}
}

export function toAttributeOutputType(xmlType: string, linkedToDataSource: boolean, unionAttributeType: string) {
switch (xmlType) {
case "Reference":
return linkedToDataSource ? `ListAttributeValue<${unionAttributeType}>` : `EditableValue<${unionAttributeType}>`;
case "ReferenceSet":
return linkedToDataSource ? `ListAttributeListValue<${unionAttributeType}>` : `EditableListValue<${unionAttributeType}>`;
default:
return "any";
}
}

function toSelectionClientType(xmlType: string) {
switch (xmlType) {
case "Single":
Expand Down

0 comments on commit 6821de6

Please sign in to comment.