@@ -7,10 +7,13 @@ open IntermediateRepresentation
77
88
99let 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-
1417let 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
5368let 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
359381let 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
0 commit comments