Skip to content

Commit 0a52a78

Browse files
committed
Reorganize WebEntities internal interfaces into sub-namespaces; add lookup field to JSDoc
1 parent 1ca63d5 commit 0a52a78

3 files changed

Lines changed: 90 additions & 38 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [Unreleased]
44
### Changed
5+
- WebEntities internal interfaces reorganized into sub-namespaces under `_`: `Scalars`, `Read`, `Write`, `Binds`, and `Lookup`, replacing the previous flat layout
6+
- Lookup value properties (`_*_value`) now include the lookup field's logical name in their JSDoc comment
57
- WebEntities relationship variables are now split into typed `ManyToOne`, `OneToMany`, and `ManyToMany` sub-interfaces, directly mirroring the SDK metadata structure
68
- Intersect (many-to-many junction) entities now generate full interfaces identical to regular entities, replacing the previous simplified read-only path
79
- Intersect entity JSDoc now includes `Logical Name:`, an `Intersect Table` marker, and the two participating entities

src/CreateTypeScript/CreateWebEntities.fs

Lines changed: 84 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ open IntermediateRepresentation
77

88

99
let INTERNAL_NS = "_"
10+
let SCALAR_NS = "Scalars"
11+
let READ_NS = "Read"
12+
let WRITE_NS = "Write"
13+
let BINDS_NS = "Binds"
14+
let LOOKUP_NS = "Lookup"
1015

1116
(** Interface name helper functions *)
12-
let withNamespace (ns: string) (str: string) = $"{ns}.{str}"
13-
1417
let entityTag =
1518
Variable.Create("\"@odata.etag\"", TsType.String)
1619

@@ -48,7 +51,19 @@ let getAttributeComment (attr: XrmAttribute) (options: OptionSet list option) =
4851
match options with
4952
| Some opts -> getEnumLink opts attr
5053
| None -> ""
51-
Comment.Attribute(attr.displayName, colType = attr.colType, ?tes = attr.targetEntitySets, link = link)
54+
55+
let logicalName =
56+
match attr.specialType with
57+
| SpecialType.EntityReference -> attr.logicalName
58+
| _ -> ""
59+
60+
Comment.Attribute(
61+
attr.displayName,
62+
colType = attr.colType,
63+
?tes = attr.targetEntitySets,
64+
link = link,
65+
logicalName = logicalName
66+
)
5267

5368
let getScalarType (attr: XrmAttribute) =
5469
match attr.specialType with
@@ -293,41 +308,36 @@ let getBlankEntityInterfaces (nameMap: Map<string, EntityInfo>) (entity: XrmEnti
293308
logicalName = entity.logicalName
294309
)
295310

296-
let rScalars = "ReadableScalars"
297-
let cScalars = "CreatableScalars"
298-
let uScalars = "UpdatableScalars"
311+
let rScalars = "Readable"
312+
let cScalars = "Creatable"
313+
let uScalars = "Updatable"
299314

300-
let cBinds = "CreatableBinds"
301-
let uBinds = "UpdatableBinds"
315+
let cBinds = "Creatable"
316+
let uBinds = "Updatable"
302317

303-
let wRelations = "WriteRelationships"
304-
let wM2O = "WriteManyToOne"
305-
let wO2M = "WriteOneToMany"
306-
let wM2M = "WriteManyToMany"
307-
308-
let rRelations = "ReadRelationships"
309-
let rM2O = "ReadManyToOne"
310-
let rO2M = "ReadOneToMany"
311-
let rM2M = "ReadManyToMany"
318+
let relations = "Relationships"
319+
let m2o = "ManyToOne"
320+
let o2m = "OneToMany"
321+
let m2m = "ManyToMany"
312322

313323
let frmt = "Formatted"
314-
let lookupN = "LookupNames"
315-
let lookupV = "LookupValues"
324+
let lookupN = "LogicalNames"
325+
let lookupV = "Values"
316326

317327
{
318328
readableScalars = Interface.Create(rScalars, extends = [ cScalars ])
319329
creatableScalars = Interface.Create(cScalars, extends = [ uScalars ])
320330
updatableScalars = Interface.Create uScalars
321331

322-
readRelationships = Interface.Create(rRelations, extends = [ rM2O; rO2M; rM2M ])
323-
readManyToOne = Interface.Create rM2O
324-
readOneToMany = Interface.Create rO2M
325-
readManyToMany = Interface.Create rM2M
332+
readRelationships = Interface.Create(relations, extends = [ m2o; o2m; m2m ])
333+
readManyToOne = Interface.Create m2o
334+
readOneToMany = Interface.Create o2m
335+
readManyToMany = Interface.Create m2m
326336

327-
writeRelationships = Interface.Create(wRelations, extends = [ wM2O; wO2M; wM2M ])
328-
writeManyToOne = Interface.Create wM2O
329-
writeOneToMany = Interface.Create wO2M
330-
writeManyToMany = Interface.Create wM2M
337+
writeRelationships = Interface.Create(relations, extends = [ m2o; o2m; m2m ])
338+
writeManyToOne = Interface.Create m2o
339+
writeOneToMany = Interface.Create o2m
340+
writeManyToMany = Interface.Create m2m
331341

332342
creatableBinds = Interface.Create(cBinds, extends = [ uBinds ])
333343
updatableBinds = Interface.Create uBinds
@@ -340,47 +350,75 @@ let getBlankEntityInterfaces (nameMap: Map<string, EntityInfo>) (entity: XrmEnti
340350
Interface.Create(
341351
UPDATE_INTERFACE_NAME,
342352
comment,
343-
[ uScalars; wRelations; uBinds ] |> List.map (withNamespace INTERNAL_NS)
353+
[
354+
$"{INTERNAL_NS}.{SCALAR_NS}.{uScalars}"
355+
$"{INTERNAL_NS}.{WRITE_NS}.{relations}"
356+
$"{INTERNAL_NS}.{BINDS_NS}.{uBinds}" ]
344357
)
345358
create =
346359
Interface.Create(
347360
CREATE_INTERFACE_NAME,
348361
comment,
349-
[ cScalars; wRelations; cBinds ] |> List.map (withNamespace INTERNAL_NS)
362+
[
363+
$"{INTERNAL_NS}.{SCALAR_NS}.{cScalars}"
364+
$"{INTERNAL_NS}.{WRITE_NS}.{relations}"
365+
$"{INTERNAL_NS}.{BINDS_NS}.{cBinds}" ]
350366
)
351367
read =
352368
Interface.Create(
353369
entity.schemaName,
354370
comment,
355-
[ rScalars; rRelations; frmt; lookupN; lookupV ] |> List.map (withNamespace $"{entity.schemaName}.{INTERNAL_NS}")
356-
) }
371+
[
372+
$"{entity.schemaName}.{INTERNAL_NS}.{SCALAR_NS}.{rScalars}"
373+
$"{entity.schemaName}.{INTERNAL_NS}.{READ_NS}.{relations}"
374+
$"{entity.schemaName}.{INTERNAL_NS}.{frmt}"
375+
$"{entity.schemaName}.{INTERNAL_NS}.{LOOKUP_NS}.{lookupN}"
376+
$"{entity.schemaName}.{INTERNAL_NS}.{LOOKUP_NS}.{lookupV}" ]
377+
)
378+
}
357379

358380
/// Create entity interfaces
359381
let getEntityInterfaceLines nameMap (schemaNames: Set<string>) (entity: XrmEntity) =
360382
let entityInterfaces = getBlankEntityInterfaces nameMap entity
361383

362-
let internalInterfaces =
384+
let scalarInterfaces =
363385
[
364386
{ entityInterfaces.readableScalars with vars = getScalarVars (fun a -> not a.createable) entity }
365387
{ entityInterfaces.creatableScalars with vars = getScalarVars (fun a -> a.createable && not a.updateable) entity }
366388
{ entityInterfaces.updatableScalars with vars = getScalarVars (fun a -> a.updateable) entity }
389+
]
367390

391+
let readInterfaces =
392+
[
368393
entityInterfaces.readRelationships
369394
{ entityInterfaces.readManyToOne with vars = getManyToOneVars nameMap schemaNames false entity.manyToOneRelationships }
370395
{ entityInterfaces.readOneToMany with vars = getOneToManyVars nameMap schemaNames false entity.oneToManyRelationships }
371396
{ entityInterfaces.readManyToMany with vars = getManyToManyVars nameMap schemaNames false entity }
397+
]
372398

399+
let writeInterfaces =
400+
[
373401
entityInterfaces.writeRelationships
374402
{ entityInterfaces.writeManyToOne with vars = getManyToOneVars nameMap schemaNames true entity.manyToOneRelationships }
375-
{ entityInterfaces.writeOneToMany with vars = getOneToManyVars nameMap schemaNames true entity.oneToManyRelationships }
403+
{ entityInterfaces.writeOneToMany with vars = getOneToManyVars nameMap schemaNames true entity.oneToManyRelationships }
376404
{ entityInterfaces.writeManyToMany with vars = getManyToManyVars nameMap schemaNames true entity }
405+
]
377406

407+
let bindInterfaces =
408+
[
378409
{ entityInterfaces.creatableBinds with vars = getBindVars nameMap (fun a -> a.createable && not a.updateable) entity }
379410
{ entityInterfaces.updatableBinds with vars = getBindVars nameMap (fun a -> a.updateable) entity }
411+
]
412+
413+
let lookupInterfaces =
414+
[
415+
{ entityInterfaces.lookupValues with vars = getLookupValueVars entity.attributes }
416+
{ entityInterfaces.lookupNames with vars = getLookupNameVars entity.attributes }
417+
]
380418

419+
let internalInterfaces =
420+
[
381421
{ entityInterfaces.formatted with vars = getFormattedVars entity }
382-
{ entityInterfaces.lookupNames with vars = getLookupNameVars entity.attributes }
383-
{ entityInterfaces.lookupValues with vars = getLookupValueVars entity.attributes }
384422
]
385423

386424
let update = { entityInterfaces.update with vars = [ entityId (entity, true) ] }
@@ -395,7 +433,17 @@ let getEntityInterfaceLines nameMap (schemaNames: Set<string>) (entity: XrmEntit
395433
[ Namespace.Create(
396434
entity.schemaName,
397435
interfaces = [ create; update ],
398-
namespaces = [ Namespace.Create(INTERNAL_NS, interfaces = internalInterfaces) ]
436+
namespaces =
437+
[ Namespace.Create(
438+
INTERNAL_NS,
439+
interfaces = internalInterfaces,
440+
namespaces =
441+
[ Namespace.Create(SCALAR_NS, interfaces = scalarInterfaces)
442+
Namespace.Create(READ_NS, interfaces = readInterfaces)
443+
Namespace.Create(WRITE_NS, interfaces = writeInterfaces)
444+
Namespace.Create(BINDS_NS, interfaces = bindInterfaces)
445+
Namespace.Create(LOOKUP_NS, interfaces = lookupInterfaces) ]
446+
) ]
399447
) ]
400448
)
401449
|> CreateCommon.skipNsIfEmpty

src/TypeScript/Comment.fs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ type Comment =
2424
| _ -> () ]
2525
|> Comment.Wrap
2626

27-
static member Attribute(displayName, ?colType, ?tes, ?link, ?label, ?isPrimaryId) =
27+
static member Attribute(displayName, ?colType, ?tes, ?link, ?label, ?isPrimaryId, ?logicalName) =
28+
let logicalName = defaultArg logicalName ""
2829
let tes = Option.defaultValue [||] tes
2930
let link = defaultArg link ""
3031
let label = defaultArg label ""
31-
32+
3233
[ if not (IsNullOrWhiteSpace displayName) then yield $"**{displayName.Trim()}**"
3334
if defaultArg isPrimaryId false then yield "Primary ID"
3435
match colType with Some t -> yield $"Column Type: {t}" | None -> ()
36+
if not (IsNullOrWhiteSpace logicalName) then yield $"Lookup Field: `{logicalName.Trim()}`"
3537
if tes.Length > 0 then
3638
let maxDisplay = 5
3739
let shown = tes |> Array.truncate maxDisplay |> Array.map (fun (ln, _, dn) -> $"{dn} (`{ln}`)") |> String.concat " | "

0 commit comments

Comments
 (0)