@mbwilding/tool-early-bound-generator 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # Early Bound Generator
2
+
3
+ Generate strongly-typed C# early-bound classes for Microsoft Dataverse entities, option sets, and messages directly inside Power Platform ToolBox.
4
+
5
+ ## Overview
6
+
7
+ The Early Bound Generator is a PPTB port of the popular [EarlyBoundGeneratorV2](https://github.com/daryllabar/DLaB.Xrm.XrmToolBoxTools) XrmToolBox plugin by Daryl LaBar. It reads metadata from your active Dataverse connection and generates C# classes compatible with the `Microsoft.Xrm.Sdk` and `Microsoft.PowerPlatform.Dataverse.Client` libraries.
8
+
9
+ Unlike the original XrmToolBox plugin, **code generation is implemented entirely in TypeScript and runs inside PPTB** — no PAC CLI, no .NET runtime, and no `pac modelbuilder build` invocation is required. The generated output is designed to be fully backwards compatible with EarlyBoundGeneratorV2.
10
+
11
+ ## Key Features
12
+
13
+ - **Entity classes** — strongly-typed C# classes for Dataverse entities with attributes, relationships, and option set enums
14
+ - **Option set enums** — C# enums for all local and global option sets, state codes, and status reasons
15
+ - **Service context** — a typed `OrganizationServiceContext` subclass for LINQ queries
16
+ - **Message classes** — request/response pairs for SDK messages, custom APIs, and actions
17
+ - **DLaB.ModelBuilderExtensions compatible** — settings file is the same XML format used by XrmToolBox EarlyBoundGeneratorV2
18
+ - **CamelCase naming** — full CamelCaser port including built-in dictionary and custom word support
19
+ - **Whitelist / blacklist filtering** — entity, attribute, prefix, and message filters
20
+ - **Dark/Light theme support** — follows PPTB theme settings automatically
21
+
22
+ ## Getting Started
23
+
24
+ ### Prerequisites
25
+
26
+ - Power Platform ToolBox with an active Dataverse connection
27
+ - An output directory where the generated `.cs` files will be written
28
+
29
+ ### Basic Usage
30
+
31
+ 1. Click **Open Settings** to browse to an existing `settings.xml` file, or select a folder to create a new one
32
+ 2. Configure the output directory under **Global → Output Relative Directory**
33
+ 3. Select the entities to generate under **Entities → Entities Whitelist**
34
+ 4. Click **Generate**
35
+
36
+ ## Settings
37
+
38
+ Settings are stored in a `settings.xml` file on disk, using the same format as XrmToolBox EarlyBoundGeneratorV2. Existing settings files from XrmToolBox can be opened directly.
39
+
40
+ ### Global
41
+
42
+ | Setting | Description |
43
+ | --------------------------------- | ------------------------------------------------------------------ |
44
+ | Namespace | C# namespace for all generated classes |
45
+ | Service Context Name | Class name for the generated `OrganizationServiceContext` subclass |
46
+ | Output Relative Directory | Path to write generated files, relative to the settings file |
47
+ | Suppress Generated Code Attribute | Omit `[GeneratedCode]` attributes from generated classes |
48
+ | Remove Runtime Version Comment | Strip the runtime version comment from file headers |
49
+ | CamelCase Class Names | Apply CamelCase transformation to entity class names |
50
+ | CamelCase Member Names | Apply CamelCase transformation to attribute and property names |
51
+ | Token Capitalisation Overrides | Words that override the dictionary for CamelCase capitalisation |
52
+
53
+ ### Entities
54
+
55
+ | Setting | Description |
56
+ | ------------------------------ | ------------------------------------------------------------------------ |
57
+ | Entities Whitelist | Only generate classes for these entities (logical names) |
58
+ | Entities To Skip | Exclude these entities even if they match the whitelist |
59
+ | Entity Prefixes Whitelist | Include all entities whose logical name starts with these prefixes |
60
+ | Create One File Per Entity | Write one `.cs` file per entity; otherwise combine into a single file |
61
+ | Generate Attribute Name Consts | Emit a `Fields` inner class with `const string` attribute name constants |
62
+ | Generate Entity Relationships | Emit relationship navigation properties |
63
+ | Emit Virtual Attributes | Include virtual (formatted value) attributes |
64
+ | Obsolete Deprecated | Mark deprecated attributes with `[ObsoleteAttribute]` |
65
+
66
+ ### Option Sets
67
+
68
+ | Setting | Description |
69
+ | ------------------------------ | --------------------------------------------------------------------------------- |
70
+ | Create One File Per Option Set | Write one `.cs` file per enum; otherwise combine into a single file |
71
+ | Generate Global Option Sets | Include global (solution-level) option sets |
72
+ | Adjust Casing For Enum Options | Apply CamelCase to enum member names |
73
+ | Local Option Set Format | Format string for local option set enum names (`{0}` = entity, `{1}` = attribute) |
74
+
75
+ ### Messages
76
+
77
+ | Setting | Description |
78
+ | ----------------------------------- | ------------------------------------------------------- |
79
+ | Generate Messages | Generate request/response classes for SDK messages |
80
+ | Messages Whitelist | Only generate classes for these message names |
81
+ | Messages To Skip | Exclude these messages even if they match the whitelist |
82
+ | Create One File Per Message | Write one `.cs` file per message; otherwise combine |
83
+ | Group Message Request With Response | Emit request and response in the same file |
84
+
85
+ ### Service Classes
86
+
87
+ These values are saved to the settings file for compatibility with XrmToolBox EarlyBoundGeneratorV2 but have no effect on code generation in PPTB, which implements generation directly without invoking PAC CLI.
88
+
89
+ ## Output Structure
90
+
91
+ With default settings and a whitelist of `[contact, account]`:
92
+
93
+ ```
94
+ <OutputDirectory>/
95
+ Entities/
96
+ Account.cs
97
+ Contact.cs
98
+ OptionSets/
99
+ Account_AccountCategoryCode.cs
100
+ Account_AccountClassificationCode.cs
101
+ Contact_GenderCode.cs
102
+ ...
103
+ DataverseContext.cs
104
+ ```
105
+
106
+ ## Generation Log
107
+
108
+ The Output panel shows a structured log during generation:
109
+
110
+ ```
111
+ === Early Bound Generator ===
112
+ Loading dictionary...
113
+ Fetching entity list...
114
+ Fetching metadata for 2 entities...
115
+ [account] attrs=298 withOptions=30
116
+ [contact] attrs=387 withOptions=30
117
+ Fetched 2 / 2
118
+ --- Entities (2) ---
119
+ Code written to .../Entities/Account.cs.
120
+ Code written to .../Entities/Contact.cs.
121
+ --- Option Sets (64) ---
122
+ Code written to .../OptionSets/Account_AccountCategoryCode.cs.
123
+ ...
124
+ --- Service Context ---
125
+ Code written to .../DataverseContext.cs.
126
+ === Generation Complete ===
127
+ ```
128
+
129
+ ## Building
130
+
131
+ ```bash
132
+ cd tools/early-bound-generator
133
+ npm install
134
+ npm run build
135
+ ```
136
+
137
+ ## Development
138
+
139
+ ```bash
140
+ npm run dev
141
+ ```
142
+
143
+ ## Architecture
144
+
145
+ ```
146
+ src/
147
+ ├── codegen/
148
+ │ ├── camelCaser.ts # CamelCase name transformation (full DLaB port)
149
+ │ ├── contextGenerator.ts # OrganizationServiceContext class generation
150
+ │ ├── entityGenerator.ts # Entity class generation
151
+ │ ├── filters.ts # Entity, attribute, and message filter logic
152
+ │ ├── helpers.ts # Shared codegen utilities (indents, headers, etc.)
153
+ │ ├── messageGenerator.ts # SDK message request/response generation
154
+ │ ├── naming.ts # NamingService (class/member/enum name resolution)
155
+ │ ├── optionSetGenerator.ts # Option set enum generation
156
+ │ ├── orchestrator.ts # Generation coordinator — fetches metadata and writes files
157
+ │ └── types.ts # Metadata type definitions
158
+ ├── components/
159
+ │ ├── BoolSettingRow.tsx # Checkbox setting row
160
+ │ ├── EntityAttributeEditor.tsx # Two-level entity → attributes editor
161
+ │ ├── EntityPickerDialog.tsx # Entity selection dialog
162
+ │ ├── KeyValueEditor.tsx # Key/value pair editor
163
+ │ ├── PathInput.tsx # File/folder path input with Browse button
164
+ │ ├── PropertySection.tsx # Collapsible settings section
165
+ │ ├── SettingRow.tsx # Single labelled setting row
166
+ │ ├── SettingsToolbar.tsx # Top toolbar (Generate, Open, Save)
167
+ │ ├── StringListEditor.tsx # Editable string list
168
+ │ └── TerminalPanel.tsx # Generation output panel
169
+ ├── models/
170
+ │ └── interfaces.ts # EbgSettings interface and DEFAULT_SETTINGS
171
+ ├── utils/
172
+ │ ├── builderSettingsBuilder.ts # Builds builderSettings.json object
173
+ │ ├── DataverseClient.ts # Dataverse entity metadata fetcher
174
+ │ ├── getErrorMessage.ts # Error message extraction utility
175
+ │ ├── pathUtils.ts # Path join and dirname utilities
176
+ │ └── xmlSerializer.ts # Settings XML serialisation / deserialisation
177
+ ├── App.tsx # Main application component
178
+ ├── main.tsx # Entry point with theme support
179
+ └── styles.css # CSS with light/dark theme variables
180
+ ```
181
+
182
+ ## Dataverse Entities Used
183
+
184
+ | Entity | Purpose |
185
+ | -------------------- | ----------------------------------------- |
186
+ | Entity metadata API | Fetch entity and attribute definitions |
187
+ | `sdkmessage` | Enumerate available SDK messages |
188
+ | `sdkmessagefilter` | Entity-scoped message filters |
189
+ | `sdkmessagepair` | Request/response message pair definitions |
190
+ | `sdkmessagerequest` | Message request field definitions |
191
+ | `sdkmessageresponse` | Message response field definitions |
192
+
193
+ ## Compatibility
194
+
195
+ Generated code targets the same output as XrmToolBox EarlyBoundGeneratorV2 with `DLaB.ModelBuilderExtensions`. Settings files (`.xml`) are fully interchangeable between the two tools.
196
+
197
+ ## Reference
198
+
199
+ - [EarlyBoundGeneratorV2 (XrmToolBox)](https://github.com/daryllabar/DLaB.Xrm.XrmToolBoxTools)
200
+ - [DLaB.ModelBuilderExtensions](https://www.nuget.org/packages/DLaB.ModelBuilderExtensions)
201
+ - [PPTB Types Package](https://www.npmjs.com/package/@pptb/types)
202
+ - [Microsoft Dataverse SDK](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/org-service/overview)