Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

181 override xrm namespace #278

Open
wants to merge 3 commits into
base: gh_master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Release Notes
### 6.3.0 - July 18 2022
* Added support for custom Xrm namespace.

### 6.2.0 - July 8 2022
* Use overridden API version in OData paths.
* Switch to eslint
Expand Down
8 changes: 4 additions & 4 deletions src/XrmDefinitelyTyped/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ open System.Reflection
[<assembly: AssemblyDescriptionAttribute("Tool to generate TypeScript declaration files for MS Dynamics 365/CRM client-side coding.")>]
[<assembly: AssemblyCompanyAttribute("Delegate A/S")>]
[<assembly: AssemblyCopyrightAttribute("Copyright (c) Delegate A/S 2017")>]
[<assembly: AssemblyVersionAttribute("6.2.0")>]
[<assembly: AssemblyFileVersionAttribute("6.2.0")>]
[<assembly: AssemblyVersionAttribute("6.3.0")>]
[<assembly: AssemblyFileVersionAttribute("6.3.0")>]
do ()

module internal AssemblyVersionInformation =
Expand All @@ -17,5 +17,5 @@ module internal AssemblyVersionInformation =
let [<Literal>] AssemblyDescription = "Tool to generate TypeScript declaration files for MS Dynamics 365/CRM client-side coding."
let [<Literal>] AssemblyCompany = "Delegate A/S"
let [<Literal>] AssemblyCopyright = "Copyright (c) Delegate A/S 2017"
let [<Literal>] AssemblyVersion = "6.2.0"
let [<Literal>] AssemblyFileVersion = "6.2.0"
let [<Literal>] AssemblyVersion = "6.3.0"
let [<Literal>] AssemblyFileVersion = "6.3.0"
6 changes: 6 additions & 0 deletions src/XrmDefinitelyTyped/CommandLine/Arguments.fs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ type Args private () =
altCommands=["vi"]
description="Comma-separated list of named semicolon-separated lists of view GUIDs that should be intersected. "
required=false }

{ command = "xrmNamespace"
altCommands = ["xrmNs"]
description = "Namespace to use instead of Xrm."
required = false
}
]

static member connectionArgs = [
Expand Down
1 change: 1 addition & 0 deletions src/XrmDefinitelyTyped/CommandLine/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ let getGenerationSettings parsedArgs =
viewIntersects = intersects "viewintersect"
labelMapping = labelMapping
generateMappings = getArg parsedArgs "generateMappings" parseBoolish ?| false
xrmNs = getArg parsedArgs "xrmNamespace" nsSanitizer ?| "Xrm"
}


Expand Down
120 changes: 60 additions & 60 deletions src/XrmDefinitelyTyped/CreateTypeScript/CreateFormDts.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ let unionWithNull t canBeNull =
t

/// Translate internal attribute type to corresponding TypeScript interface.
let getAttributeInterface ty canBeNull =
let getAttributeInterface ty canBeNull xrmNs =
let returnType =
match ty with
| AttributeType.OptionSet ty -> TsType.SpecificGeneric ("Xrm.OptionSetAttribute", [ ty ])
| AttributeType.OptionSet ty -> TsType.SpecificGeneric (sprintf "%s.OptionSetAttribute" xrmNs, [ ty ])
| AttributeType.MultiSelectOptionSet ty
-> TsType.SpecificGeneric ("Xrm.MultiSelectOptionSetAttribute", [ ty ])
| AttributeType.Default ty -> TsType.SpecificGeneric ("Xrm.Attribute", [ ty ])
| AttributeType.Lookup ty -> TsType.Custom (sprintf "Xrm.LookupAttribute<%s>" ty)
| x -> TsType.Custom (sprintf "Xrm.%AAttribute" x)
-> TsType.SpecificGeneric (sprintf "%s.MultiSelectOptionSetAttribute" xrmNs, [ ty ])
| AttributeType.Default ty -> TsType.SpecificGeneric (sprintf "%s.Attribute" xrmNs, [ ty ])
| AttributeType.Lookup ty -> TsType.Custom (sprintf "%s.LookupAttribute<%s>" xrmNs ty)
| x -> TsType.Custom (sprintf "%s.%AAttribute" xrmNs x)
unionWithNull returnType canBeNull

let getAttributeMap ty canBeNull =
let getAttributeMap ty canBeNull xrmNs =
let returnType =
match ty with
| AttributeType.OptionSet ty
| AttributeType.MultiSelectOptionSet ty
| AttributeType.Default ty -> ty
| AttributeType.Number -> TsType.Number
| AttributeType.Date -> TsType.Date
| AttributeType.Lookup ty -> TsType.Custom (sprintf "Xrm.EntityReference<%s>" ty)
| AttributeType.Lookup ty -> TsType.Custom (sprintf "%s.EntityReference<%s>" xrmNs ty)
unionWithNull returnType canBeNull

/// Gets the corresponding enum of the option set if possible
Expand All @@ -41,20 +41,20 @@ let getOptionSetType = function
| _ -> TsType.Number

/// Translate internal control type to corresponding TypeScript interface.
let getControlInterface cType aType canBeNull =
let getControlInterface cType aType canBeNull xrmNs =
let returnType =
match aType, cType with
| None, ControlType.Default -> TsType.Custom "Xrm.BaseControl"
| None, ControlType.Default -> TsType.Custom (sprintf "%s.BaseControl" xrmNs)
| Some (AttributeType.Default TsType.String), ControlType.Default
-> TsType.Custom "Xrm.StringControl"
| Some at, ControlType.Default -> TsType.SpecificGeneric ("Xrm.Control", [ getAttributeInterface at canBeNull ])
| aType, ControlType.OptionSet -> TsType.SpecificGeneric ("Xrm.OptionSetControl", [ getOptionSetType aType ])
-> TsType.Custom (sprintf "%s.StringControl" xrmNs)
| Some at, ControlType.Default -> TsType.SpecificGeneric (sprintf "%s.Control" xrmNs, [ getAttributeInterface at canBeNull xrmNs ])
| aType, ControlType.OptionSet -> TsType.SpecificGeneric (sprintf "%s.OptionSetControl" xrmNs, [ getOptionSetType aType ])
| aType, ControlType.MultiSelectOptionSet
-> TsType.SpecificGeneric ("Xrm.MultiSelectOptionSetControl", [ getOptionSetType aType ])
-> TsType.SpecificGeneric (sprintf "%s.MultiSelectOptionSetControl" xrmNs, [ getOptionSetType aType ])
| Some (AttributeType.Lookup _), ControlType.Lookup tes
| _, ControlType.Lookup tes -> TsType.Custom (sprintf "Xrm.LookupControl<%s>" tes)
| _, ControlType.SubGrid tes -> TsType.Custom (sprintf "Xrm.SubGridControl<%s>" tes)
| _, x -> TsType.Custom (sprintf "Xrm.%AControl" x)
| _, ControlType.Lookup tes -> TsType.Custom (sprintf "%s.LookupControl<%s>" xrmNs tes)
| _, ControlType.SubGrid tes -> TsType.Custom (sprintf "%s.SubGridControl<%s>" xrmNs tes)
| _, x -> TsType.Custom (sprintf "%s.%AControl" xrmNs x)
unionWithNull returnType canBeNull

/// Default collection functions which also use the "get" function name.
Expand All @@ -75,24 +75,24 @@ let defaultCollectionFuncs defaultType =


/// Generate Xrm.Page.data.entity.attributes.get(<string>) functions.
let getAttributeCollection (attributes: XrmFormAttribute list) =
let getAttributeCollection (attributes: XrmFormAttribute list) (xrmNs: string) =
let getFuncs =
attributes
|> List.map (fun (name,ty,canBeNull) ->
let paramType = getConstantType name
let returnType = getAttributeInterface ty canBeNull
let returnType = getAttributeInterface ty canBeNull xrmNs
Function.Create("get", [Variable.Create("name", paramType)], returnType))

let defaultFuncs = defaultCollectionFuncs "Xrm.Attribute<any>"
Interface.Create("Attributes", extends = ["Xrm.AttributeCollectionBase"],
let defaultFuncs = defaultCollectionFuncs (sprintf "%s.Attribute<any>" xrmNs)
Interface.Create("Attributes", extends = [ sprintf "%s.AttributeCollectionBase" xrmNs],
funcs = getFuncs @ defaultFuncs)

/// Generate Xrm.Page.data.entity.attributes Map.
let getAttributeCollectionMap (attributes: XrmFormAttribute list) =
let getAttributeCollectionMap (attributes: XrmFormAttribute list) (xrmNs: string)=
let getVars =
attributes
|> List.map (fun (name,ty,canBeNull) ->
let returnType = getAttributeMap ty canBeNull
let returnType = getAttributeMap ty canBeNull xrmNs
Variable.Create(name, returnType))

Interface.Create("AttributeValueMap", vars = getVars)
Expand All @@ -102,29 +102,29 @@ let includeControl (name: string) crmVersion =
(not (name.StartsWith("header_")) && not (name.StartsWith("footer_"))) || crmVersion .>= (6,0,0,0)

/// Generate Xrm.Page.ui.controls.get(<string>) functions.
let getControlCollection (controls: XrmFormControl list) (crmVersion: Version)=
let getControlCollection (controls: XrmFormControl list) (crmVersion: Version) (xrmNs: string)=
let getFuncs =
controls
|> List.map (fun (name, aType, cType, isBpf, canBeNull) ->
let paramType = getConstantType name
let returnType = getControlInterface cType aType canBeNull
let returnType = getControlInterface cType aType canBeNull xrmNs
match includeControl name crmVersion with
| false -> None
| true ->
Some (Function.Create("get", [Variable.Create("name", paramType)], returnType))
)
|> List.choose id

let defaultFuncs = defaultCollectionFuncs "Xrm.BaseControl"
Interface.Create("Controls", extends = ["Xrm.ControlCollectionBase"],
let defaultFuncs = defaultCollectionFuncs (sprintf "%s.BaseControl" xrmNs)
Interface.Create("Controls", extends = [ (sprintf "%s.ControlCollectionBase" xrmNs)],
funcs = getFuncs @ defaultFuncs)

/// Generate Xrm.Page.ui.controls map.
let getControlCollectionMap (controls: XrmFormControl list) (crmVersion: Version)=
let getControlCollectionMap (controls: XrmFormControl list) (crmVersion: Version) (xrmNs: string)=
let getVars =
controls
|> List.map (fun (name, aType, cType, isBpf, canBeNull) ->
let returnType = getControlInterface cType aType canBeNull
let returnType = getControlInterface cType aType canBeNull xrmNs
match includeControl name crmVersion with
| false -> None
| true -> Some (Variable.Create(name, returnType))
Expand All @@ -134,45 +134,45 @@ let getControlCollectionMap (controls: XrmFormControl list) (crmVersion: Version
Interface.Create("ControlMap", vars = getVars)

/// Generate Xrm.Page.ui.tabs.get(<string>) functions.
let getTabCollection (tabs: XrmFormTab list) =
let getTabCollection (tabs: XrmFormTab list) (xrmNs: string) =
let getFuncs =
tabs
|> List.map (fun (iname, name, sections) ->
let paramType = getConstantType name
let returnType = sprintf "Xrm.PageTab<Tabs.%s>" iname |> TsType.Custom
let returnType = sprintf "%s.PageTab<Tabs.%s>" xrmNs iname |> TsType.Custom
Function.Create("get", [Variable.Create("name", paramType)], returnType))

let defaultFuncs =
defaultCollectionFuncs
"Xrm.PageTab<Xrm.Collection<Xrm.PageSection>>"
(sprintf "%s.PageTab<%s.Collection<%s.PageSection>>" xrmNs xrmNs xrmNs)

Interface.Create("Tabs", extends = ["Xrm.TabCollectionBase"],
Interface.Create("Tabs", extends = [(sprintf "%s.TabCollectionBase" xrmNs)],
funcs = getFuncs @ defaultFuncs)


/// Generate Xrm.Page.ui.tabs.get(<someTab>).sections.get(<string>) functions.
let getSectionCollections (tabs: XrmFormTab list) =
let getSectionCollections (tabs: XrmFormTab list) (xrmNs: string) =
let getFuncs sections =
sections
|> List.map (fun name ->
let paramType = getConstantType name
Function.Create("get", [ Variable.Create("name", paramType) ],
TsType.Custom "Xrm.PageSection"))
TsType.Custom (sprintf "%s.PageSection" xrmNs)))

let defaultFuncs = defaultCollectionFuncs "Xrm.PageSection"
let defaultFuncs = defaultCollectionFuncs (sprintf "%s.PageSection" xrmNs)
tabs |> List.map (fun (iname, name, sections) ->
Interface.Create(iname, extends = ["Xrm.SectionCollectionBase"],
Interface.Create(iname, extends = [(sprintf "%s.SectionCollectionBase" xrmNs)],
funcs = getFuncs sections @ defaultFuncs))



/// Generate Xrm.Page.getAttribute(<string>) functions.
let getAttributeFuncs (attributes: XrmFormAttribute list) =
let getAttributeFuncs (attributes: XrmFormAttribute list) (xrmNs: string) =
let attrFuncs =
attributes
|> List.map (fun (name, ty, canBeNull) ->
let paramType = getConstantType name
let returnType = getAttributeInterface ty canBeNull
let returnType = getAttributeInterface ty canBeNull xrmNs
Function.Create("getAttribute",
[ Variable.Create("attributeName", paramType) ], returnType))

Expand All @@ -183,20 +183,20 @@ let getAttributeFuncs (attributes: XrmFormAttribute list) =

let delegateFunc =
Function.Create("getAttribute",
[ Variable.Create("delegateFunction", TsType.Custom("Xrm.Collection.MatchingDelegate<Xrm.Attribute<any>>"))],
TsType.Custom("Xrm.Attribute<any>[]"))
[ Variable.Create("delegateFunction", TsType.Custom(sprintf "%s.Collection.MatchingDelegate<%s.Attribute<any>>" xrmNs xrmNs))],
TsType.Custom(sprintf "%s.Attribute<any>[]" xrmNs))

attrFuncs @ [ defaultFunc; delegateFunc ]



/// Generate Xrm.Page.getControl(<string>) functions.
let getControlFuncs (controls: XrmFormControl list) (crmVersion: Version)=
let getControlFuncs (controls: XrmFormControl list) (crmVersion: Version) (xrmNs: string) =
let ctrlFuncs =
controls
|> List.map (fun (name, aType, cType, isBpf, canBeNull) ->
let paramType = getConstantType name
let returnType = getControlInterface cType aType canBeNull
let returnType = getControlInterface cType aType canBeNull xrmNs
match includeControl name crmVersion with
| false -> None
| true ->
Expand All @@ -212,45 +212,45 @@ let getControlFuncs (controls: XrmFormControl list) (crmVersion: Version)=

let delegateFunc =
Function.Create("getControl",
[ Variable.Create("delegateFunction", TsType.Custom("Xrm.Collection.MatchingDelegate<Xrm.Control<any>>"))],
TsType.Custom("Xrm.Control<any>[]"))
[ Variable.Create("delegateFunction", TsType.Custom(sprintf "%s.Collection.MatchingDelegate<%s.Control<any>>" xrmNs xrmNs))],
TsType.Custom(sprintf "%s.Control<any>[]" xrmNs))

ctrlFuncs @ [ defaultFunc; delegateFunc ]



/// Generate internal namespace for keeping track all the collections.
let getFormNamespace (form: XrmForm) crmVersion generateMappings =
let getFormNamespace (form: XrmForm) crmVersion generateMappings xrmNs =
let baseInterfaces =
[ getAttributeCollection form.attributes
getControlCollection form.controls crmVersion
getTabCollection form.tabs ]
[ getAttributeCollection form.attributes xrmNs
getControlCollection form.controls crmVersion xrmNs
getTabCollection form.tabs xrmNs ]
Namespace.Create(form.name,
interfaces =
(if generateMappings then
baseInterfaces @
[getAttributeCollectionMap form.attributes
getControlCollectionMap form.controls crmVersion]
[getAttributeCollectionMap form.attributes xrmNs
getControlCollectionMap form.controls crmVersion xrmNs]
else baseInterfaces),
namespaces =
[ Namespace.Create("Tabs", interfaces = getSectionCollections form.tabs) ])
[ Namespace.Create("Tabs", interfaces = getSectionCollections form.tabs xrmNs) ])


/// Generate the interface for the Xrm.Page of the form.
let getFormInterface (form: XrmForm) crmVersion =
let getFormInterface (form: XrmForm) crmVersion (xrmNs : string) =
let superClass =
sprintf "Xrm.PageBase<%s.Attributes,%s.Tabs,%s.Controls>"
form.name form.name form.name
sprintf "%s.PageBase<%s.Attributes,%s.Tabs,%s.Controls>"
xrmNs form.name form.name form.name

Interface.Create(form.name, extends = [superClass],
funcs =
getAttributeFuncs form.attributes @
getControlFuncs form.controls crmVersion)
getAttributeFuncs form.attributes xrmNs @
getControlFuncs form.controls crmVersion xrmNs)


/// Generate the namespace containing all the form interface and internal
/// namespaces for collections.
let getFormDts (form: XrmForm) crmVersion generateMappings =
let getFormDts (form: XrmForm) crmVersion xdtSettings =
let nsName =
sprintf "Form.%s%s"
(form.entityName |> Utility.sanitizeString)
Expand All @@ -261,7 +261,7 @@ let getFormDts (form: XrmForm) crmVersion generateMappings =
Namespace.Create(
nsName,
declare = true,
namespaces = [ getFormNamespace form crmVersion generateMappings],
interfaces = [ getFormInterface form crmVersion])
namespaces = [ getFormNamespace form crmVersion xdtSettings.generateMappings xdtSettings.xrmNs],
interfaces = [ getFormInterface form crmVersion xdtSettings.xrmNs])
|> nsToString

1 change: 1 addition & 0 deletions src/XrmDefinitelyTyped/Domain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type XdtGenerationSettings = {
viewIntersects: Intersect [] option
labelMapping: (string * string)[] option
generateMappings: bool
xrmNs: string
}

type EntityName = string
Expand Down
10 changes: 6 additions & 4 deletions src/XrmDefinitelyTyped/Generation/FileGeneration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ let versionExtendFile crmVersion gSettings outputDir (resName,fileName) preffix
|> Seq.map (getResourceLines >> stripReferenceLines)
|> (getResourceLines resName |> Seq.singleton |> Seq.append)
|> List.concat
|> Seq.map (fun l -> l.Replace("_XRMNS_", gSettings.xrmNs))
|> fun lines ->
File.WriteAllLines(
sprintf "%s/%s" outputDir fileName, lines)
File.WriteAllLines(
sprintf "%s/%s" outputDir fileName, lines
)

let generateJSExtResourceFiles crmVersion gSettings =

Expand Down Expand Up @@ -258,7 +260,7 @@ let generateWebEntityDefs ns state =
defs

/// Generate the Form definitions
let generateFormDefs state crmVersion generateMappings =
let generateFormDefs state crmVersion xdtSettings =
printf "Generation Form definitions..."
let getFormType xrmForm = xrmForm.formType ?|> sprintf "/%s" ?| ""

Expand All @@ -275,7 +277,7 @@ let generateFormDefs state crmVersion generateMappings =
|> Array.filter (fun (form: XrmForm) -> form.formType.IsNone || (form.formType.IsSome && form.formType.Value <> "Card" && form.formType.Value <> "InteractionCentricDashboard" && form.formType.Value <> "TaskFlowForm"))
|> Array.Parallel.map (fun xrmForm ->
let path = sprintf "%s/Form/%s%s" state.outputDir xrmForm.entityName (getFormType xrmForm)
let lines = getFormDts xrmForm crmVersion generateMappings
let lines = getFormDts xrmForm crmVersion xdtSettings
sprintf "%s/%s.d.ts" path xrmForm.name, lines)

printfn "Done!"
Expand Down
2 changes: 1 addition & 1 deletion src/XrmDefinitelyTyped/Generation/GenerationMain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let generateFromRaw gSettings rawState =
let defs =
seq {
yield! generateEnumDefs data
if not gSettings.skipForms then yield! generateFormDefs data crmVersion gSettings.generateMappings
if not gSettings.skipForms then yield! generateFormDefs data crmVersion gSettings

match crmVersion .>= (8,2,0,0) with
| true ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="..\xrm.d.ts" />
declare namespace Xrm {
declare namespace _XRMNS_ {
interface context {
/**
* Returns a Boolean value indicating if the user is using Microsoft Dynamics CRM for Microsoft Office Outlook.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="..\xrm.d.ts" />
declare namespace Xrm {
declare namespace _XRMNS_ {
//eslint-disable-next-line @typescript-eslint/no-unused-vars
interface PageTab<T extends SectionCollectionBase> {
/**
Expand Down
Loading