Skip to content

Commit fc53e95

Browse files
committed
Refactor Comment.Create parameter and truncate long lookup target lists
1 parent 3ab5363 commit fc53e95

5 files changed

Lines changed: 54 additions & 67 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44
### Changed
5+
- Lookup JSDoc "Table:" lines now truncate to 5 target entities, appending `+N more` when there are additional targets
56
- Refactored `Comment` type to use `XrmAttributeType` DU (24 SDK attribute types) instead of strings for type-safe formatting
67
- Extracted `XrmAttributeType` and `RelType` DUs to `Domain.fs` for better organization and constraint satisfaction (Set operations in form intersection)
78
- Moved formatting logic into `Comment.ToCommentStrings()` and `XrmAttributeType.fromDisplayName()` for cleaner separation of concerns

src/CreateTypeScript/CreateWebEntities.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ let defToFormattedVars (a, comment, _, _) =
107107
Variable.Create(formattedName a, TsType.String, comment, optional = true )
108108

109109
let getEntityRefDef nameFormat (a: XrmAttribute) =
110-
nameFormat a, [ a, Comment.Create (a.displayName, colType = a.colType), a.varType, Some guidName ]
110+
nameFormat a, [ a, Comment.Create (a.displayName, colType = a.colType, ?tes = a.targetEntitySets), a.varType, Some guidName ]
111111

112112
let getResultDef (ent: XrmEntity) (attr: XrmAttribute) =
113113
let vType = attr.varType
114114
let name = attr.logicalName
115-
let comment = Comment.Create(attr.displayName, colType = attr.colType, link = getLink ent attr)
115+
let comment = Comment.Create(attr.displayName, colType = attr.colType, ?tes = attr.targetEntitySets, link = getLink ent attr)
116116

117117
match attr.specialType with
118118
| SpecialType.EntityReference -> getEntityRefDef guidName attr
@@ -165,7 +165,7 @@ let getLookupNameVariable (a: XrmAttribute) =
165165
Variable.Create(
166166
lookupName a,
167167
unionType,
168-
Comment.Create(a.displayName, colType = a.colType),
168+
Comment.Create(a.displayName, colType = a.colType, ?tes = a.targetEntitySets),
169169
optional = true
170170
)
171171
)

src/Interpretation/InterpretEntityMetadata.fs

Lines changed: 43 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,49 @@ open IntermediateRepresentation
77
open InterpretOptionSetMetadata
88
open Microsoft.Xrm.Sdk.Metadata
99

10-
11-
let toSome convertFunc (nullable: System.Nullable<'a>) =
12-
match nullable.HasValue with
13-
| true -> nullable.GetValueOrDefault() |> convertFunc
14-
| false -> TsType.Any
1510

1611
let typeConv = function
17-
| AttributeTypeCode.Boolean -> TsType.Boolean
18-
| AttributeTypeCode.DateTime -> TsType.Date
12+
| XrmAttributeType.ManagedProperty
13+
| XrmAttributeType.Boolean -> TsType.Boolean
14+
| XrmAttributeType.DateTime -> TsType.Date
1915

20-
| AttributeTypeCode.Memo
21-
| AttributeTypeCode.EntityName
22-
| AttributeTypeCode.String -> TsType.String
23-
24-
| AttributeTypeCode.Integer
25-
| AttributeTypeCode.Double
26-
| AttributeTypeCode.BigInt
27-
| AttributeTypeCode.Money
28-
| AttributeTypeCode.Picklist
29-
| AttributeTypeCode.State
30-
| AttributeTypeCode.Status -> TsType.Number
16+
| XrmAttributeType.Memo
17+
| XrmAttributeType.EntityName
18+
| XrmAttributeType.String -> TsType.String
19+
20+
| XrmAttributeType.Integer
21+
| XrmAttributeType.Double
22+
| XrmAttributeType.BigInt
23+
| XrmAttributeType.Money
24+
| XrmAttributeType.Picklist
25+
| XrmAttributeType.State
26+
| XrmAttributeType.Status -> TsType.Number
3127
| _ -> TsType.Any
3228

33-
let interpretVirtualAttribute (a:AttributeMetadata) (options:OptionSet option) =
34-
match a with
35-
| :? MultiSelectPicklistAttributeMetadata -> Some (TsType.Custom $"{ENUM_NS}.{options.Value.name}", SpecialType.MultiSelectOptionSet)
36-
| _ -> None
37-
38-
39-
let interpretNormalAttribute aType (a:AttributeMetadata) (options:OptionSet option) =
29+
let interpretNormalAttribute aType (options:OptionSet option) =
4030
match aType with
41-
| AttributeTypeCode.Money -> TsType.Number, SpecialType.Money
31+
| XrmAttributeType.Money -> TsType.Number, SpecialType.Money
4232

43-
| AttributeTypeCode.Picklist
44-
| AttributeTypeCode.State
45-
| AttributeTypeCode.Status -> TsType.Custom $"{ENUM_NS}.{options.Value.name}", SpecialType.OptionSet
46-
47-
| AttributeTypeCode.Lookup
48-
| AttributeTypeCode.PartyList
49-
| AttributeTypeCode.Customer
50-
| AttributeTypeCode.Owner -> TsType.String, SpecialType.EntityReference
33+
| XrmAttributeType.MultiSelectPicklist -> TsType.Custom $"{ENUM_NS}.{options.Value.name}", SpecialType.MultiSelectOptionSet
34+
| XrmAttributeType.Picklist
35+
| XrmAttributeType.State
36+
| XrmAttributeType.Status -> TsType.Custom $"{ENUM_NS}.{options.Value.name}", SpecialType.OptionSet
37+
38+
| XrmAttributeType.Lookup
39+
| XrmAttributeType.PartyList
40+
| XrmAttributeType.Customer
41+
| XrmAttributeType.Owner -> TsType.String, SpecialType.EntityReference
5142

52-
| AttributeTypeCode.Uniqueidentifier
53-
-> TsType.String, SpecialType.Guid
43+
| XrmAttributeType.Uniqueidentifier -> TsType.String, SpecialType.Guid
5444

55-
| AttributeTypeCode.Decimal -> toSome typeConv a.AttributeType, SpecialType.Decimal
56-
| _ -> toSome typeConv a.AttributeType, SpecialType.Default
45+
| XrmAttributeType.Decimal -> typeConv aType, SpecialType.Decimal
46+
| _ -> typeConv aType, SpecialType.Default
5747

5848

5949
let interpretAttribute (nameMap: Map<string, EntityInfo>) labelMapping (a: AttributeMetadata) =
60-
let aType = a.AttributeType.GetValueOrDefault()
50+
let aType = XrmAttributeType.fromDisplayName a.AttributeTypeName
6151
if a.AttributeOf <> null ||
62-
(aType = AttributeTypeCode.Virtual && a.AttributeTypeName <> AttributeTypeDisplayName.MultiSelectPicklistType)||
52+
aType = XrmAttributeType.Virtual ||
6353
a.LogicalName.StartsWith("yomi") then None, None
6454
else
6555

@@ -81,26 +71,20 @@ let interpretAttribute (nameMap: Map<string, EntityInfo>) labelMapping (a: Attri
8171
|> Some
8272
| _ -> None
8373

84-
let vTypeOption =
85-
match aType with
86-
| AttributeTypeCode.Virtual -> interpretVirtualAttribute a options
87-
| _ -> Some (interpretNormalAttribute aType a options)
74+
let vType, sType = interpretNormalAttribute aType options
8875

89-
match vTypeOption with
90-
| None -> None, None
91-
| Some (vType, sType) ->
92-
options, Some {
93-
XrmAttribute.schemaName = a.SchemaName
94-
logicalName = a.LogicalName
95-
varType = vType
96-
specialType = sType
97-
colType = XrmAttributeType.fromDisplayName a.AttributeTypeName
98-
targetEntitySets = targetEntitySets
99-
readable = a.IsValidForRead.GetValueOrDefault(false)
100-
createable = a.IsValidForCreate.GetValueOrDefault(false)
101-
updateable = a.IsValidForUpdate.GetValueOrDefault(false)
102-
displayName = getLabel a.DisplayName
103-
}
76+
options, Some {
77+
XrmAttribute.schemaName = a.SchemaName
78+
logicalName = a.LogicalName
79+
varType = vType
80+
specialType = sType
81+
colType = aType
82+
targetEntitySets = targetEntitySets
83+
readable = a.IsValidForRead.GetValueOrDefault(false)
84+
createable = a.IsValidForCreate.GetValueOrDefault(false)
85+
updateable = a.IsValidForUpdate.GetValueOrDefault(false)
86+
displayName = getLabel a.DisplayName
87+
}
10488

10589
let sanitizeNavigationProptertyName string =
10690
if string = null then "navigationPropertyNameNotDefined"

src/Interpretation/InterpretFormXml.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ let getAttribute (enums:Map<string,TsType>) (entity: XrmEntity) (cField: Control
7272
let comment =
7373
match attribute with
7474
| None -> Comment.Create cField.displayName
75-
| Some attr -> Comment.Create(attr.displayName, colType = attr.colType, ?targetEntitySets = attr.targetEntitySets, link = getLink entity attr)
75+
| Some attr -> Comment.Create(attr.displayName, colType = attr.colType, ?tes = attr.targetEntitySets, link = getLink entity attr)
7676

7777
let attrType = getAttributeType attribute
7878

@@ -136,7 +136,7 @@ let getControl (enums:Map<string,TsType>) (entity: XrmEntity) (cField:ControlFi
136136
| None -> Comment.Create cField.displayName
137137
| Some attr ->
138138
let label = if cField.displayName.Trim() <> attr.displayName.Trim() then cField.displayName else ""
139-
Comment.Create(attr.displayName, label = label, colType = attr.colType, ?targetEntitySets = attr.targetEntitySets, link = getLink entity attr)
139+
Comment.Create(attr.displayName, label = label, colType = attr.colType, ?tes = attr.targetEntitySets, link = getLink entity attr)
140140

141141
let cType =
142142
match cField.controlClass with

src/TypeScript/TypeScript.fs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ and Comment =
5353
relType: RelType option
5454
tab: string
5555
link: string }
56-
static member Create(?displayName, ?label, ?colType, ?targetEntitySets, ?relType, ?tab, ?link) =
56+
static member Create(?displayName, ?label, ?colType, ?tes, ?relType, ?tab, ?link) =
5757
{ displayName = defaultArg displayName ""
5858
label = defaultArg label ""
5959
colType = colType
60-
targetEntitySets = targetEntitySets
60+
targetEntitySets = tes
6161
relType = relType
6262
tab = defaultArg tab ""
6363
link = defaultArg link "" }
@@ -70,7 +70,9 @@ and Comment =
7070
match c.targetEntitySets with
7171
| None | Some [||] -> None
7272
| Some tes ->
73-
let formatted = tes |> Array.map (fun (ln, _, dn) -> $"{dn} (`{ln}`)") |> String.concat " | "
73+
let maxDisplay = 5
74+
let shown = tes |> Array.truncate maxDisplay |> Array.map (fun (ln, _, dn) -> $"{dn} (`{ln}`)") |> String.concat " | "
75+
let formatted = if tes.Length <= maxDisplay then shown else $"{shown} | +{tes.Length - maxDisplay} more"
7476
Some $"Table: {formatted}"
7577
let relTypeLine = c.relType |> Option.map (fun t -> $"Relationship Type: {t}")
7678
let linkLine = if String.IsNullOrWhiteSpace c.link then None else Some (sprintf "{@link %s}" (c.link.Trim()))

0 commit comments

Comments
 (0)