From c11f356c672e1740f9ec16696465d465e7a5d051 Mon Sep 17 00:00:00 2001 From: Arjo Bruijnes Date: Wed, 14 Aug 2024 16:11:33 +0200 Subject: [PATCH] Generate types for metadata attribute properties --- .../src/typings-generator/WidgetXml.ts | 1 + .../src/typings-generator/generateClientTypes.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/pluggable-widgets-tools/src/typings-generator/WidgetXml.ts b/packages/pluggable-widgets-tools/src/typings-generator/WidgetXml.ts index 77259028..8f5b548e 100644 --- a/packages/pluggable-widgets-tools/src/typings-generator/WidgetXml.ts +++ b/packages/pluggable-widgets-tools/src/typings-generator/WidgetXml.ts @@ -44,6 +44,7 @@ export interface Property { | "widgets" | "selection"; isList?: string; + isMetaData?: string; defaultValue?: string; required?: string; isDefault?: string; diff --git a/packages/pluggable-widgets-tools/src/typings-generator/generateClientTypes.ts b/packages/pluggable-widgets-tools/src/typings-generator/generateClientTypes.ts index 190b39d3..2ddb8bff 100644 --- a/packages/pluggable-widgets-tools/src/typings-generator/generateClientTypes.ts +++ b/packages/pluggable-widgets-tools/src/typings-generator/generateClientTypes.ts @@ -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); } }