@xrmforge/devkit 0.7.1 → 0.7.3
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/dist/templates/AGENT.md
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
# XrmForge - AI Agent Instructions
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Quality Philosophy
|
|
4
|
+
|
|
5
|
+
The goal is not "code that compiles" or "code that passes a linter". The goal is
|
|
6
|
+
code that reads like a description of the business logic. A developer opening a
|
|
7
|
+
file should immediately understand what happens, without Xrm API docs, without
|
|
8
|
+
OData knowledge, without deciphering GUIDs or magic numbers.
|
|
9
|
+
|
|
10
|
+
Every string that references a Dataverse resource (field name, entity name,
|
|
11
|
+
OptionSet value, tab name, section name, notification ID, navigation property)
|
|
12
|
+
MUST come from a generated constant or a named constant from constants.ts.
|
|
13
|
+
No exceptions. No workarounds. No helper wrappers that accept raw strings.
|
|
14
|
+
|
|
15
|
+
Abstraction layers that merely wrap single API calls with string parameters
|
|
16
|
+
(getValue, setValue, setDisabled, addOnChange) destroy type safety and must not
|
|
17
|
+
exist. The correct abstraction is `typedForm()` (language-level proxy), not
|
|
18
|
+
string wrappers (API-level indirection). Business logic belongs in named
|
|
19
|
+
functions with domain-specific names, not in anonymous chains of API calls.
|
|
4
20
|
|
|
5
21
|
## Packages
|
|
6
22
|
|
|
@@ -533,6 +549,48 @@ Never recreate them. Use the typed API directly.
|
|
|
533
549
|
| `SetNotification(attr, msg)` | `form.$context.getControl(Fields.X).setNotification(msg, NOTIFICATION_IDS.x)` |
|
|
534
550
|
| `SetSectionDisabled(tab, sec, off)` | `form.$context.ui.tabs.get(Tabs.X).sections.get(Sections.Y).setVisible(!off)` |
|
|
535
551
|
|
|
552
|
+
### GUID Handling (common CRM anti-pattern)
|
|
553
|
+
|
|
554
|
+
D365 returns GUIDs in various formats: `{A1B2C3D4-...}`, `a1b2c3d4-...`, `A1B2C3D4-...`.
|
|
555
|
+
Legacy code commonly has helpers like `CompareGuid()`, `GetCompatibleGuid()`,
|
|
556
|
+
`NormalizeGuid()`, `StripBraces()`. **Do NOT recreate these.**
|
|
557
|
+
|
|
558
|
+
`formLookupId()` from @xrmforge/helpers already normalizes GUIDs (removes braces).
|
|
559
|
+
GUID comparison is then a simple `===`:
|
|
560
|
+
|
|
561
|
+
```typescript
|
|
562
|
+
// WRONG: legacy GUID helpers
|
|
563
|
+
function CompareGuid(a, b) { return a.replace(/[{}]/g,'').toLowerCase() === b.replace(/[{}]/g,'').toLowerCase(); }
|
|
564
|
+
const id = GetCompatibleGuid(form.getAttribute("customerid").getValue()[0].id);
|
|
565
|
+
|
|
566
|
+
// CORRECT: formLookupId normalizes automatically
|
|
567
|
+
const customerId = formLookupId(form.customerid); // already clean: "a1b2c3d4-..."
|
|
568
|
+
if (customerId === otherNormalizedId) { ... } // simple ===
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
### Typed repetition beats untyped loops
|
|
572
|
+
|
|
573
|
+
When multiple fields need the same operation (e.g. 8 address fields), write
|
|
574
|
+
8 typed lines instead of 1 loop with raw strings:
|
|
575
|
+
|
|
576
|
+
```typescript
|
|
577
|
+
// WRONG: DRY reflex, but raw strings bypass type safety
|
|
578
|
+
for (const f of ['address1_name', 'address1_line1', 'address1_city']) {
|
|
579
|
+
form.$unsafe(f)?.addOnChange(handler);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// CORRECT: more lines, but every field is compile-time validated
|
|
583
|
+
form.address1_name.addOnChange(handler);
|
|
584
|
+
form.address1_line1.addOnChange(handler);
|
|
585
|
+
form.address1_city.addOnChange(handler);
|
|
586
|
+
form.address1_postalcode.addOnChange(handler);
|
|
587
|
+
form.address1_country.addOnChange(handler);
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
8 typed lines are better than 1 loop with raw strings. The type system
|
|
591
|
+
catches renamed/removed fields at compile time. A loop with raw strings
|
|
592
|
+
only fails at runtime. DRY is a recommendation, type safety is mandatory.
|
|
593
|
+
|
|
536
594
|
**Rule of thumb:** If a helper function just wraps a single Xrm API call with a
|
|
537
595
|
string parameter, it MUST NOT exist. The typed API is shorter, safer, and provides
|
|
538
596
|
IDE autocomplete. Only keep shared helpers that contain actual domain logic
|
|
@@ -87,9 +87,14 @@ function collectTsFiles(dir) {
|
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
89
|
* Check a pattern rule against all files.
|
|
90
|
+
* @param {string} label - Description of the check
|
|
91
|
+
* @param {string[]} files - Files to check
|
|
92
|
+
* @param {RegExp} regex - Pattern to match (violation)
|
|
93
|
+
* @param {string[]} excludeFiles - File paths to exclude
|
|
94
|
+
* @param {RegExp[]} excludePatterns - Line patterns to exclude (not violations even if regex matches)
|
|
90
95
|
* @returns Number of violations
|
|
91
96
|
*/
|
|
92
|
-
function checkPattern(label, files, regex, excludeFiles = []) {
|
|
97
|
+
function checkPattern(label, files, regex, excludeFiles = [], excludePatterns = []) {
|
|
93
98
|
const violations = [];
|
|
94
99
|
for (const file of files) {
|
|
95
100
|
const relPath = relative(process.cwd(), file);
|
|
@@ -100,6 +105,7 @@ function checkPattern(label, files, regex, excludeFiles = []) {
|
|
|
100
105
|
const line = lines[i];
|
|
101
106
|
const trimmed = line.trim();
|
|
102
107
|
if (trimmed.startsWith('//') || trimmed.startsWith('*') || trimmed.startsWith('/*')) continue;
|
|
108
|
+
if (excludePatterns.some((ep) => ep.test(trimmed))) continue;
|
|
103
109
|
if (regex.test(line)) {
|
|
104
110
|
violations.push(` ${relPath}:${i + 1}: ${trimmed}`);
|
|
105
111
|
}
|
|
@@ -214,11 +220,16 @@ checkPattern(
|
|
|
214
220
|
|
|
215
221
|
// ── Handler Pattern ──────────────────────────────────────────────────────────
|
|
216
222
|
|
|
217
|
-
// 3l. Exported handlers without wrapHandler
|
|
223
|
+
// 3l. Exported handlers without wrapHandler or wrapCommand
|
|
218
224
|
checkPattern(
|
|
219
|
-
'Exported handlers without wrapHandler',
|
|
225
|
+
'Exported handlers without wrapHandler/wrapCommand',
|
|
220
226
|
formFiles,
|
|
221
|
-
/^export\s+(const|async\s+function|function)\s+\w+(?!.*wrapHandler)/,
|
|
227
|
+
/^export\s+(const|async\s+function|function)\s+\w+(?!.*(?:wrapHandler|wrapCommand))/,
|
|
228
|
+
[],
|
|
229
|
+
[
|
|
230
|
+
// Re-exports: `export const form_OnLoad = onLoad;` (alias for a wrapped handler)
|
|
231
|
+
/^export\s+const\s+\w+\s*=\s*[a-zA-Z][a-zA-Z0-9]*\s*;/,
|
|
232
|
+
],
|
|
222
233
|
);
|
|
223
234
|
|
|
224
235
|
// ── Raw $select ──────────────────────────────────────────────────────────────
|