@xrmforge/typegen 0.6.0 → 0.7.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/MIGRATION.md +14 -3
- package/dist/index.d.ts +203 -2
- package/docs/architecture/00-README.md +26 -0
- package/docs/architecture/01-executive-summary.md +11 -0
- package/docs/architecture/02-packages.md +110 -0
- package/docs/architecture/03-generated-types.md +176 -0
- package/docs/architecture/04-cli.md +58 -0
- package/docs/architecture/05-build.md +50 -0
- package/docs/architecture/06-incremental.md +42 -0
- package/docs/architecture/07-http-client.md +59 -0
- package/docs/architecture/08-authentication.md +18 -0
- package/docs/architecture/09-testing.md +55 -0
- package/docs/architecture/10-eslint-plugin.md +82 -0
- package/docs/architecture/11-agent-md.md +38 -0
- package/docs/architecture/12-xrm-pitfalls.md +14 -0
- package/docs/architecture/13-helpers.md +50 -0
- package/docs/architecture/14-showcases.md +21 -0
- package/docs/architecture/15-ci-cd.md +49 -0
- package/docs/architecture/16-technical-debt.md +17 -0
- package/docs/architecture/17-roadmap.md +25 -0
- package/docs/architecture/18-design-principles.md +22 -0
- package/docs/architektur/00-README.md +26 -0
- package/docs/architektur/01-zusammenfassung.md +11 -0
- package/docs/architektur/02-packages.md +110 -0
- package/docs/architektur/03-generierte-typen.md +176 -0
- package/docs/architektur/04-cli.md +58 -0
- package/docs/architektur/05-build.md +50 -0
- package/docs/architektur/06-inkrementell.md +42 -0
- package/docs/architektur/07-http-client.md +59 -0
- package/docs/architektur/08-authentifizierung.md +18 -0
- package/docs/architektur/09-testing.md +55 -0
- package/docs/architektur/10-eslint-plugin.md +82 -0
- package/docs/architektur/11-agent-md.md +38 -0
- package/docs/architektur/12-xrm-fallstricke.md +14 -0
- package/docs/architektur/13-helpers.md +50 -0
- package/docs/architektur/14-showcases.md +21 -0
- package/docs/architektur/15-ci-cd.md +49 -0
- package/docs/architektur/16-technische-schulden.md +17 -0
- package/docs/architektur/17-roadmap.md +25 -0
- package/docs/architektur/18-designprinzipien.md +22 -0
- package/package.json +4 -8
- package/dist/helpers.d.ts +0 -203
- package/dist/helpers.js +0 -120
- package/dist/helpers.js.map +0 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# 11. AGENT.md System
|
|
2
|
+
|
|
3
|
+
## 11.1 Zweck
|
|
4
|
+
|
|
5
|
+
Die AGENT.md ist eine generierte Datei, die KI-Coding-Assistenten (Claude, ChatGPT, Copilot, Cursor) beibringt, wie sie optimale D365-Formularskripte mit XrmForge schreiben. Sie wird von `xrmforge init` erzeugt und im Projektstamm abgelegt.
|
|
6
|
+
|
|
7
|
+
## 11.2 Inhaltsstruktur
|
|
8
|
+
|
|
9
|
+
1. **Package-Übersicht** - Was jedes @xrmforge-Package tut
|
|
10
|
+
2. **10 Regeln: Immer** - Fields Enum, OptionSet Enum, FormContext-Cast, EntityNames, parseLookup, select, createFormMock, Modul-Exports, Tabs/Sections Enums, Fehlerbehandlung
|
|
11
|
+
3. **Regeln: Niemals** - Rohe Strings, Magic Numbers, Xrm.Page, synchrone XHR, eval, window-Zuweisungen
|
|
12
|
+
4. **Vorher/Nachher-Beispiele** - Feldzugriff, OptionSet-Vergleich, Testen
|
|
13
|
+
5. **Pattern-Erkennungstabelle** - Zuordnung von Legacy-Pattern zu XrmForge-Ersetzung
|
|
14
|
+
6. **OptionSet-Enum-Erstellungsanleitung** - Wie man Enums aus Magic Numbers in Legacy-Code erstellt
|
|
15
|
+
7. **Testen mit setupXrmMock** - Globales Xrm-Mock-Pattern
|
|
16
|
+
8. **Build-Befehle** - xrmforge build, Watch-Modus
|
|
17
|
+
9. **@types/xrm-Fallstricke** - Bekannte Probleme und Workarounds
|
|
18
|
+
10. **Dateistruktur** - Erwartetes Projektlayout
|
|
19
|
+
|
|
20
|
+
## 11.3 Template-System
|
|
21
|
+
|
|
22
|
+
Die AGENT.md ist als `src/scaffold/templates/AGENT.md` im devkit-Package gespeichert und wird zur Scaffolding-Zeit über `template-loader.ts` geladen. Es ist keine Variablenersetzung nötig (die Datei ist statisch).
|
|
23
|
+
|
|
24
|
+
## 11.4 Ergebnisse des KI-Vergleichstests
|
|
25
|
+
|
|
26
|
+
Fünf KI-Modelle wurden beim Konvertieren von Legacy-D365-JavaScript (account.js + lm_helper.js, 1.288 Zeilen) zu TypeScript mit XrmForge getestet:
|
|
27
|
+
|
|
28
|
+
| Rang | Modell | Punkte | Werkzeug | Stärke |
|
|
29
|
+
|------|--------|--------|----------|--------|
|
|
30
|
+
| 1 | Claude Opus 4.6 | 42/50 | Claude Code | Meiste Tests (62), beste Codestruktur |
|
|
31
|
+
| 2 | Claude Sonnet 4.6 | 41/50 | Claude Code | Meiste Bugs gefunden (5), bester DI-Ansatz |
|
|
32
|
+
| 3 | Cursor Composer 2 | 35/50 | Cursor IDE | Hat select() Node-API-Problem erkannt |
|
|
33
|
+
| 4 | ChatGPT GPT-4o | 30/50 | ChatGPT Web | Funktional, aber weniger XrmForge-spezifisch |
|
|
34
|
+
| 5 | MS Copilot | 12/50 | Browser-Chat | Kein Workspace-Zugriff, hat AGENT.md nie gesehen |
|
|
35
|
+
|
|
36
|
+
**Kriterien (11, maximal 5 Punkte je = 55 max):** Fields-Enum-Nutzung, OptionSet-Enums, FormContext-Typisierung, XrmForge-Helpers, Modul-Exports, Tests vorhanden, Testqualität, Fehlerbehandlung, Codequalität, gefundene Bugs, Dokumentation.
|
|
37
|
+
|
|
38
|
+
**Zentrale Erkenntnis:** Keine KI hat konsistent `@xrmforge/typegen/helpers`-Imports (select, parseLookup) verwendet. Dies bleibt die grösste Adoptionslücke.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# 12. @types/xrm-Fallstricke
|
|
2
|
+
|
|
3
|
+
Bekannte Probleme bei der Arbeit mit `@types/xrm`:
|
|
4
|
+
|
|
5
|
+
| Problem | Falsch | Richtig |
|
|
6
|
+
|---------|--------|---------|
|
|
7
|
+
| Form-Interface | `interface extends Xrm.FormContext` | `extends Omit<Xrm.FormContext, 'getAttribute' \| 'getControl'>` |
|
|
8
|
+
| AlertDialogResponse | `Xrm.Navigation.AlertDialogResponse` | `Xrm.Async.PromiseLike<void>` (Typ existiert nicht) |
|
|
9
|
+
| ConfirmDialogResponse | `Xrm.Navigation.ConfirmDialogResponse` | `Xrm.Navigation.ConfirmResult` (Typ existiert nicht) |
|
|
10
|
+
| setNotification | `setNotification(message)` | `setNotification(message, uniqueId)` (erfordert 2 Argumente) |
|
|
11
|
+
| openFile | `openFile({ fileName, ... })` | Muss `fileSize`-Eigenschaft in FileDetails enthalten |
|
|
12
|
+
| SubmitMode | `Xrm.Attributes.SubmitMode` | `Xrm.SubmitMode` |
|
|
13
|
+
| const enum in .d.ts | `const enum` in `.d.ts`-Dateien | Reguläres `enum` in `.ts`-Dateien verwenden (vitest kann const enums aus .d.ts nicht importieren) |
|
|
14
|
+
| Grid.refresh() | `grid.refresh()` | `(grid as any).refresh()` (nicht typisiert in @types/xrm) |
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# 13. @xrmforge/helpers Package
|
|
2
|
+
|
|
3
|
+
## 13.1 Problem
|
|
4
|
+
|
|
5
|
+
Der bisherige Ansatz nutzte einen `/helpers`-Subpath-Export auf `@xrmforge/typegen`. Das war verwirrend, weil typegen ein Node.js-Codegenerierungstool ist, während die Helpers browsersichere Laufzeitfunktionen sind. Der Subpath `@xrmforge/typegen/helpers` war nicht intuitiv und KI-Coding-Assistenten haben ihn durchgängig nicht gefunden.
|
|
6
|
+
|
|
7
|
+
## 13.2 Lösung
|
|
8
|
+
|
|
9
|
+
Ein eigenständiges `@xrmforge/helpers`-Package bündelt allen browsersicheren Laufzeitcode. Keine Node.js-Abhängigkeiten. Klarer, auffindbarer Import-Pfad:
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
// Import vom dedizierten helpers-Package
|
|
13
|
+
import { select, parseLookup, typedForm } from '@xrmforge/helpers';
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## 13.3 Exports
|
|
17
|
+
|
|
18
|
+
**Web-API-Helpers:**
|
|
19
|
+
- `select(...fields: string[]): string` - Erstellt `?$select=field1,field2`
|
|
20
|
+
- `selectExpand(fields: string[], expand: string): string` - Erstellt `?$select=...&$expand=...`
|
|
21
|
+
- `parseLookup(response: Record<string, unknown>, fieldName: string): LookupValue | null` - Parst `_fieldname_value` mit OData-Annotationen
|
|
22
|
+
- `parseLookups(response: Record<string, unknown>, fieldName: string): LookupValue[]` - Multi-Value-Lookup-Parsing
|
|
23
|
+
- `parseFormattedValue(response: Record<string, unknown>, fieldName: string): string | null` - Extrahiert `@OData.Community.Display.V1.FormattedValue`
|
|
24
|
+
|
|
25
|
+
**Xrm-Konstanten (8 const enums):**
|
|
26
|
+
- DisplayState, FormNotificationLevel, RequiredLevel, SubmitMode, SaveMode, ClientType, ClientState, OperationType
|
|
27
|
+
|
|
28
|
+
**typedForm()-Proxy:**
|
|
29
|
+
- `typedForm<TForm>(formContext)` - Gibt einen Proxy zurück, bei dem `form.name` an `getAttribute('name')` delegiert
|
|
30
|
+
- GET-Trap: Property-Zugriff delegiert an getAttribute(); `$context` gibt den rohen FormContext zurück; `$control(name)` gibt getControl() zurück
|
|
31
|
+
- SET-Trap: Wirft TypeError und erzwingt die Verwendung von `.setValue()`
|
|
32
|
+
- HAS-Trap: Prüft, ob ein Attribut auf dem Formular existiert
|
|
33
|
+
|
|
34
|
+
**Action/Function-Laufzeit:**
|
|
35
|
+
- `createBoundAction(entityName, actionName)` - Erstellt einen gebundenen Action-Executor
|
|
36
|
+
- `executeRequest(request)` - Führt einen Organization Request über Xrm.WebApi.online.execute aus
|
|
37
|
+
- `withProgress(message, fn)` - Umhüllt eine asynchrone Operation mit Xrm.Utility.showProgressIndicator
|
|
38
|
+
|
|
39
|
+
## 13.4 Migration
|
|
40
|
+
|
|
41
|
+
Der alte Import-Pfad `@xrmforge/typegen/helpers` wurde entfernt. Alle Imports aktualisieren:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
// Alt (entfernt)
|
|
45
|
+
import { select } from '@xrmforge/typegen/helpers';
|
|
46
|
+
import { typedForm } from '@xrmforge/formhelpers';
|
|
47
|
+
|
|
48
|
+
// Neu
|
|
49
|
+
import { select, typedForm } from '@xrmforge/helpers';
|
|
50
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# 14. Showcases
|
|
2
|
+
|
|
3
|
+
## 14.1 Markant WebResources (Produktions-Showcase)
|
|
4
|
+
|
|
5
|
+
Befindet sich im XrmForge-Workspace-Repository unter `docs/07_showcase/markant-webresources/`.
|
|
6
|
+
|
|
7
|
+
- **30 WebResources** in `src/forms/` (Account, Contact, Opportunity, Lead, Quote, Email, Task usw.)
|
|
8
|
+
- **1 gemeinsame Bibliothek** (DSGVO-Aufbewahrungsfristen-UI)
|
|
9
|
+
- **9 Testdateien** mit 59 Tests
|
|
10
|
+
- **79 generierte Typings:** 25 Form-Interfaces, 28 Entity-Interfaces, 22 OptionSet-Dateien, 4 Action-Executors
|
|
11
|
+
- **esbuild-Build** über xrmforge.config.json (32 Einträge)
|
|
12
|
+
- **Deploy-Skript** (deploy.mjs) mit @azure/identity-Authentifizierung, inkrementellem Deployment, Hash-basierter Änderungserkennung
|
|
13
|
+
- **27 Entitäten, 236 OptionSet-Enums, 95 Form-Interfaces, 7 Custom-API-Executors**
|
|
14
|
+
|
|
15
|
+
## 14.2 LMApp WebResources (KI-Vergleichs-Showcase)
|
|
16
|
+
|
|
17
|
+
Erstellt während der KI-Vergleichstests (Session 9). 18 Legacy-JavaScript-Formularskripte (~8.400 Zeilen) zu TypeScript mit XrmForge-Patterns konvertiert.
|
|
18
|
+
|
|
19
|
+
- **19 WebResources** mit Fields Enums, EntityNames, OptionSet Enums
|
|
20
|
+
- **84 Tests** in 8 Testdateien
|
|
21
|
+
- **XrmForge-optimiert:** Alle 10 AGENT.md-Regeln angewendet (FormContext-Cast, Fields Enum, EntityNames, OptionSet Enums, gemeinsames getLookupObject, Tab Enums)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# 15. CI/CD
|
|
2
|
+
|
|
3
|
+
## 15.1 GitHub Actions CI (`.github/workflows/ci.yml`)
|
|
4
|
+
|
|
5
|
+
**Auslöser:** Push auf main, Pull Requests gegen main.
|
|
6
|
+
|
|
7
|
+
**Matrix:** Node 20, Node 22 auf ubuntu-latest.
|
|
8
|
+
|
|
9
|
+
**Schritte:**
|
|
10
|
+
1. Checkout
|
|
11
|
+
2. pnpm einrichten (aus packageManager-Feld)
|
|
12
|
+
3. Node.js einrichten (Matrix-Version)
|
|
13
|
+
4. `pnpm install --frozen-lockfile`
|
|
14
|
+
5. `pnpm lint`
|
|
15
|
+
6. `pnpm -r exec tsc --noEmit` (Typecheck aller Packages)
|
|
16
|
+
7. `pnpm build`
|
|
17
|
+
8. `pnpm test`
|
|
18
|
+
9. Coverage (nur Node 22): `npx vitest run --coverage` in typegen
|
|
19
|
+
|
|
20
|
+
## 15.2 Release-Workflow (`.github/workflows/release.yml`)
|
|
21
|
+
|
|
22
|
+
**Auslöser:** Nach erfolgreicher CI bei Push auf main.
|
|
23
|
+
|
|
24
|
+
**Schritte:**
|
|
25
|
+
1. Checkout, pnpm einrichten, Node 22 einrichten
|
|
26
|
+
2. `pnpm install --frozen-lockfile`
|
|
27
|
+
3. `pnpm build`
|
|
28
|
+
4. Changesets-Action: erstellt Release-PR oder veröffentlicht auf npm
|
|
29
|
+
|
|
30
|
+
**Publish-Befehl:** `pnpm release` = `turbo run build && changeset publish`
|
|
31
|
+
|
|
32
|
+
## 15.3 Turbo-Pipeline
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
build: dependsOn: [^build], outputs: [dist/**]
|
|
36
|
+
test: dependsOn: [build]
|
|
37
|
+
typecheck: dependsOn: [^build]
|
|
38
|
+
lint: (keine Abhängigkeiten)
|
|
39
|
+
dev: cache: false, persistent: true
|
|
40
|
+
clean: cache: false
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 15.4 Changesets
|
|
44
|
+
|
|
45
|
+
Konfiguriert für öffentlichen npm-Zugriff, automatische Aktualisierung interner Abhängigkeiten auf Patch-Ebene. Veröffentlichung erfordert NPM_TOKEN Secret.
|
|
46
|
+
|
|
47
|
+
## 15.5 Veröffentlichungsreihenfolge
|
|
48
|
+
|
|
49
|
+
Aufgrund interner Abhängigkeiten: zuerst typegen, dann devkit, dann cli. Es muss `pnpm publish` verwendet werden (nicht `npm publish`), um `workspace:*`-Referenzen in echte Versionen aufzulösen.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# 16. Technische Schulden
|
|
2
|
+
|
|
3
|
+
## 16.1 Bekannte Probleme
|
|
4
|
+
|
|
5
|
+
| Problem | Status | Priorität |
|
|
6
|
+
|---------|--------|-----------|
|
|
7
|
+
| parseLookup/select wird von KI-Assistenten nicht übernommen | Offen | Hoch |
|
|
8
|
+
| release.yml doppelte Ausführungen (CI löst Release aus, Release löst CI erneut aus) | Offen | Niedrig |
|
|
9
|
+
| Keine Integrationstests gegen Live-Dataverse | Offen (OE-4) | Mittel |
|
|
10
|
+
| @xrmforge/webapi hat keine Action/Function-Unterstützung | Akzeptiert | Niedrig |
|
|
11
|
+
| devDependency-Versionen im generierten package.json sind auf alte Versionen fixiert | Offen | Niedrig |
|
|
12
|
+
|
|
13
|
+
## 16.2 Akzeptierte Einschränkungen
|
|
14
|
+
|
|
15
|
+
- **const-enum-Einschränkung:** Kann zur Laufzeit von Test-Frameworks nicht aus `.d.ts`-Dateien importiert werden. Workaround: `.ts`-Dateien mit regulärem `enum` für manuelle Typings verwenden.
|
|
16
|
+
- **Grid.refresh() erfordert `as any`:** Nicht typisiert in @types/xrm.
|
|
17
|
+
- **Eine Solution pro Entität:** Wenn eine Entität in mehreren Solutions vorkommt, wird sie nur einmal generiert.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# 17. Roadmap
|
|
2
|
+
|
|
3
|
+
## 17.1 Nächste Schritte (Prioritätsreihenfolge)
|
|
4
|
+
|
|
5
|
+
1. **parseLookup/select-Adoption** - AGENT.md-Beispiele verbessern, damit KI-Assistenten konsistent `/helpers`-Imports verwenden
|
|
6
|
+
2. **LMApp-Showcase-Neugenerierung** - Mit aktuellen Releases (testing@0.2.0, devkit@0.4.0 mit verbesserter AGENT.md)
|
|
7
|
+
3. **KI-Battle Runde 3** - Sonnet vs. Opus erneut testen nach Verbesserungen, um Fortschritt zu messen
|
|
8
|
+
4. **Dokumentationswebsite** - xrmforge.dev oder xrmforge.io (OE-3)
|
|
9
|
+
|
|
10
|
+
## 17.2 Offene Entscheidungen
|
|
11
|
+
|
|
12
|
+
| ID | Entscheidung | Status |
|
|
13
|
+
|----|--------------|--------|
|
|
14
|
+
| OE-1 | npm-Scope-Verfügbarkeit (@xrmforge) | Offen |
|
|
15
|
+
| OE-2 | GitHub-Org vs. persönliches Repo | Entschieden: persönlich (juergenbeck/XrmForge) |
|
|
16
|
+
| OE-3 | Dokumentationsdomain (xrmforge.dev oder .io) | Offen |
|
|
17
|
+
| OE-4 | Dataverse-Testumgebung für Integrationstests | Offen |
|
|
18
|
+
| OE-5 | Publisher-Prefix und Solution-Name für PCF/WebResource-Tests | Offen |
|
|
19
|
+
|
|
20
|
+
## 17.3 Zukünftige Möglichkeiten
|
|
21
|
+
|
|
22
|
+
- Relationship-Names const enum (OE-7, niedrige Priorität)
|
|
23
|
+
- @xrmforge/webapi mit Action/Function-Unterstützung (DataverseHttpClient wiederverwenden)
|
|
24
|
+
- Plugin-System für benutzerdefinierte Generatoren und Typ-Zuordnungen
|
|
25
|
+
- Serverseitige Generierung (Custom API in Dataverse)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# 18. Designprinzipien
|
|
2
|
+
|
|
3
|
+
Die 18 Designprinzipien, die die gesamte XrmForge-Entwicklung bestimmen:
|
|
4
|
+
|
|
5
|
+
1. **Erweitern, nicht ersetzen** - Typen bauen auf @types/xrm auf, überschreiben sie nie.
|
|
6
|
+
2. **TypeScript durchgängig** - 100% TypeScript-nativ. Kein .NET, kein ADAL.
|
|
7
|
+
3. **Code muss bauen** - Jeder Arbeitsschritt endet mit grünem Build + Tests.
|
|
8
|
+
4. **Recherche vor Geschwindigkeit** - Untersuchen, vergleichen, entscheiden, dann implementieren. Niemals raten.
|
|
9
|
+
5. **Kein Modul ohne Grundlagen** - Fehlerbehandlung, Logging, Unit-Tests, JSDoc auf allen öffentlichen APIs.
|
|
10
|
+
6. **Monorepo-Disziplin** - Jedes Package eigenständig, keine zirkulären Abhängigkeiten, Barrel-Exports.
|
|
11
|
+
7. **Enterprise-Resilienz** - Retry + exponentielles Backoff, Rate-Limit-Erkennung, Token-Caching, Read-only als Standard.
|
|
12
|
+
8. **esbuild-first, webpack-kompatibel** - Standard: esbuild (schnell). webpack bleibt unterstützt. IIFE-Output für D365.
|
|
13
|
+
9. **Nur MSAL-Authentifizierung** - Ausschliesslich @azure/identity (kein Legacy-ADAL). Drei Flows: Client Credentials, Browser, Device Code.
|
|
14
|
+
10. **Review erforderlich** - Nach jedem Schritt sofortiges kritisches Review (6 Dimensionen). Nicht fragen, ob Review gewünscht ist.
|
|
15
|
+
11. **Session-State erforderlich** - session-state.md aktualisiert, Changelog geschrieben, offene Fragen erfasst.
|
|
16
|
+
12. **Keine halben Sachen** - Jeder Schritt vollständig abgeschlossen: grüner Build + Tests + Review vor dem nächsten Schritt.
|
|
17
|
+
13. **Fundierte Architekturentscheidungen** - Recherchieren, vergleichen, mit Pro/Contra empfehlen, Entscheidung einholen, persistieren.
|
|
18
|
+
14. **Abstraktion statt Vendor-Lock-in** - Externe Abhängigkeiten hinter Interfaces (Parser, Auth, Bundler).
|
|
19
|
+
15. **Zweisprachige Labels** - Primärsprache (1033/Englisch) für Bezeichner, Sekundärsprache in JSDoc. Deutsche Umlaute transliteriert.
|
|
20
|
+
16. **Review mit Recherche und Live-Verifikation** - Internetrecherche, Live-D365-Verifikation, Produktionscode-Prüfungen, Quellen zitieren.
|
|
21
|
+
17. **Aufschub hinterfragen** - "Später"-Check: Wird es schwieriger? API-Vertrag? Echter Aufwand? Technische Gründe?
|
|
22
|
+
18. **Read-only als Standard für Dataverse-Zugriff** - DataverseHttpClient ist standardmässig readOnly: true. Schreibzugriff ist ein explizites Opt-in.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xrmforge/typegen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "TypeScript declaration generator for Dynamics 365 / Dataverse",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dynamics-365",
|
|
@@ -29,15 +29,11 @@
|
|
|
29
29
|
"types": "./dist/index.d.ts",
|
|
30
30
|
"import": "./dist/index.js",
|
|
31
31
|
"default": "./dist/index.js"
|
|
32
|
-
},
|
|
33
|
-
"./helpers": {
|
|
34
|
-
"types": "./dist/helpers.d.ts",
|
|
35
|
-
"import": "./dist/helpers.js",
|
|
36
|
-
"default": "./dist/helpers.js"
|
|
37
32
|
}
|
|
38
33
|
},
|
|
39
34
|
"files": [
|
|
40
35
|
"dist",
|
|
36
|
+
"docs",
|
|
41
37
|
"MIGRATION.md"
|
|
42
38
|
],
|
|
43
39
|
"sideEffects": false,
|
|
@@ -59,12 +55,12 @@
|
|
|
59
55
|
"node": ">=20.0.0"
|
|
60
56
|
},
|
|
61
57
|
"scripts": {
|
|
62
|
-
"build": "tsup",
|
|
58
|
+
"build": "tsup && node scripts/copy-docs.mjs",
|
|
63
59
|
"dev": "tsup --watch",
|
|
64
60
|
"test": "vitest run",
|
|
65
61
|
"test:watch": "vitest",
|
|
66
62
|
"typecheck": "tsc --noEmit",
|
|
67
63
|
"lint": "eslint src/",
|
|
68
|
-
"clean": "rm -rf dist"
|
|
64
|
+
"clean": "rm -rf dist docs"
|
|
69
65
|
}
|
|
70
66
|
}
|
package/dist/helpers.d.ts
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @xrmforge/typegen - Web API Helper Functions
|
|
3
|
-
*
|
|
4
|
-
* Lightweight utility functions for building OData query strings
|
|
5
|
-
* with type-safe field names from generated Fields enums.
|
|
6
|
-
*
|
|
7
|
-
* Zero runtime overhead when used with const enums (values are inlined).
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { select } from '@xrmforge/typegen';
|
|
12
|
-
*
|
|
13
|
-
* Xrm.WebApi.retrieveRecord(ref.entityType, ref.id, select(
|
|
14
|
-
* AccountFields.Name,
|
|
15
|
-
* AccountFields.WebsiteUrl,
|
|
16
|
-
* AccountFields.Address1Line1,
|
|
17
|
-
* ));
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* Build an OData $select query string from field names.
|
|
22
|
-
*
|
|
23
|
-
* @param fields - Field names (use generated Fields enum for type safety)
|
|
24
|
-
* @returns OData query string (e.g. "?$select=name,websiteurl,address1_line1")
|
|
25
|
-
*/
|
|
26
|
-
declare function select(...fields: string[]): string;
|
|
27
|
-
/**
|
|
28
|
-
* Parse a lookup field from a Dataverse Web API response into a LookupValue.
|
|
29
|
-
*
|
|
30
|
-
* Dataverse returns lookups as `_fieldname_value` with OData annotations:
|
|
31
|
-
* - `_fieldname_value` (GUID)
|
|
32
|
-
* - `_fieldname_value@OData.Community.Display.V1.FormattedValue` (display name)
|
|
33
|
-
* - `_fieldname_value@Microsoft.Dynamics.CRM.lookuplogicalname` (entity type)
|
|
34
|
-
*
|
|
35
|
-
* This function extracts all three into an `Xrm.LookupValue` object.
|
|
36
|
-
*
|
|
37
|
-
* @param response - The raw Web API response object
|
|
38
|
-
* @param navigationProperty - Navigation property name (use NavigationProperties enum for type safety)
|
|
39
|
-
* @returns Xrm.LookupValue or null if the lookup is empty
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```typescript
|
|
43
|
-
* // Mit NavigationProperties-Enum (empfohlen, keine Raw-Strings):
|
|
44
|
-
* parseLookup(result, AccountNav.Country);
|
|
45
|
-
*
|
|
46
|
-
* // Oder mit Navigation Property Name direkt:
|
|
47
|
-
* parseLookup(result, 'markant_address1_countryid');
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
declare function parseLookup(response: Record<string, unknown>, navigationProperty: string): {
|
|
51
|
-
id: string;
|
|
52
|
-
name: string;
|
|
53
|
-
entityType: string;
|
|
54
|
-
} | null;
|
|
55
|
-
/**
|
|
56
|
-
* Parse multiple lookup fields from a Dataverse Web API response at once.
|
|
57
|
-
*
|
|
58
|
-
* @param response - The raw Web API response object
|
|
59
|
-
* @param navigationProperties - Navigation property names to parse
|
|
60
|
-
* @returns Map of navigation property name to LookupValue (null entries omitted)
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```typescript
|
|
64
|
-
* const lookups = parseLookups(result, ['markant_address1_countryid', 'parentaccountid']);
|
|
65
|
-
* formContext.getAttribute(Fields.Country).setValue(
|
|
66
|
-
* lookups.markant_address1_countryid ? [lookups.markant_address1_countryid] : null
|
|
67
|
-
* );
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
declare function parseLookups(response: Record<string, unknown>, navigationProperties: string[]): Record<string, {
|
|
71
|
-
id: string;
|
|
72
|
-
name: string;
|
|
73
|
-
entityType: string;
|
|
74
|
-
} | null>;
|
|
75
|
-
/**
|
|
76
|
-
* Get the formatted (display) value of any field from a Web API response.
|
|
77
|
-
*
|
|
78
|
-
* Works for OptionSets, Lookups, DateTimes, Money, and other formatted fields.
|
|
79
|
-
*
|
|
80
|
-
* @param response - The raw Web API response object
|
|
81
|
-
* @param fieldName - The field logical name (e.g. "statecode", "createdon")
|
|
82
|
-
* @returns The formatted string value, or null if not available
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* ```typescript
|
|
86
|
-
* const status = parseFormattedValue(result, 'statecode');
|
|
87
|
-
* // "Active" (statt 0)
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
|
-
declare function parseFormattedValue(response: Record<string, unknown>, fieldName: string): string | null;
|
|
91
|
-
/**
|
|
92
|
-
* Build an OData $select and $expand query string.
|
|
93
|
-
*
|
|
94
|
-
* @param fields - Field names to select
|
|
95
|
-
* @param expand - Navigation property to expand (optional)
|
|
96
|
-
* @returns OData query string
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```typescript
|
|
100
|
-
* Xrm.WebApi.retrieveRecord("account", id, selectExpand(
|
|
101
|
-
* [AccountFields.Name, AccountFields.WebsiteUrl],
|
|
102
|
-
* "primarycontactid($select=fullname,emailaddress1)"
|
|
103
|
-
* ));
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
declare function selectExpand(fields: string[], expand: string): string;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* @xrmforge/typegen - Xrm API Constants
|
|
110
|
-
*
|
|
111
|
-
* Const enums for all common Xrm string/number constants.
|
|
112
|
-
* Eliminates raw strings in D365 form scripts.
|
|
113
|
-
*
|
|
114
|
-
* @types/xrm defines these as string literal types for compile-time checking,
|
|
115
|
-
* but does NOT provide runtime constants (XrmEnum is not available at runtime).
|
|
116
|
-
* These const enums are erased at compile time (zero runtime overhead).
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```typescript
|
|
120
|
-
* // Statt Raw-String:
|
|
121
|
-
* if (tab.getDisplayState() === 'expanded') { ... }
|
|
122
|
-
*
|
|
123
|
-
* // Mit XrmForge-Konstante:
|
|
124
|
-
* if (tab.getDisplayState() === XrmConstants.DisplayState.Expanded) { ... }
|
|
125
|
-
* ```
|
|
126
|
-
*/
|
|
127
|
-
/** Tab/Section display state */
|
|
128
|
-
declare const enum DisplayState {
|
|
129
|
-
Expanded = "expanded",
|
|
130
|
-
Collapsed = "collapsed"
|
|
131
|
-
}
|
|
132
|
-
/** Form notification level (formContext.ui.setFormNotification) */
|
|
133
|
-
declare const enum FormNotificationLevel {
|
|
134
|
-
Error = "ERROR",
|
|
135
|
-
Warning = "WARNING",
|
|
136
|
-
Info = "INFO"
|
|
137
|
-
}
|
|
138
|
-
/** Attribute required level (attribute.setRequiredLevel) */
|
|
139
|
-
declare const enum RequiredLevel {
|
|
140
|
-
None = "none",
|
|
141
|
-
Required = "required",
|
|
142
|
-
Recommended = "recommended"
|
|
143
|
-
}
|
|
144
|
-
/** Attribute submit mode (attribute.setSubmitMode) */
|
|
145
|
-
declare const enum SubmitMode {
|
|
146
|
-
Always = "always",
|
|
147
|
-
Never = "never",
|
|
148
|
-
Dirty = "dirty"
|
|
149
|
-
}
|
|
150
|
-
/** Save mode (eventArgs.getSaveMode()) */
|
|
151
|
-
declare const enum SaveMode {
|
|
152
|
-
Save = 1,
|
|
153
|
-
SaveAndClose = 2,
|
|
154
|
-
Deactivate = 5,
|
|
155
|
-
Reactivate = 6,
|
|
156
|
-
Send = 7,
|
|
157
|
-
Disqualify = 15,
|
|
158
|
-
Qualify = 16,
|
|
159
|
-
Assign = 47,
|
|
160
|
-
SaveAsCompleted = 58,
|
|
161
|
-
SaveAndNew = 59,
|
|
162
|
-
AutoSave = 70
|
|
163
|
-
}
|
|
164
|
-
/** Client type (Xrm.Utility.getGlobalContext().client.getClient()) */
|
|
165
|
-
declare const enum ClientType {
|
|
166
|
-
Web = "Web",
|
|
167
|
-
Outlook = "Outlook",
|
|
168
|
-
Mobile = "Mobile"
|
|
169
|
-
}
|
|
170
|
-
/** Client state (Xrm.Utility.getGlobalContext().client.getClientState()) */
|
|
171
|
-
declare const enum ClientState {
|
|
172
|
-
Online = "Online",
|
|
173
|
-
Offline = "Offline"
|
|
174
|
-
}
|
|
175
|
-
/** Operation type for Xrm.WebApi.execute getMetadata().operationType */
|
|
176
|
-
declare const enum OperationType {
|
|
177
|
-
/** Custom Action or OOB Action (POST) */
|
|
178
|
-
Action = 0,
|
|
179
|
-
/** Custom Function or OOB Function (GET) */
|
|
180
|
-
Function = 1,
|
|
181
|
-
/** CRUD operation (Create, Retrieve, Update, Delete) */
|
|
182
|
-
CRUD = 2
|
|
183
|
-
}
|
|
184
|
-
/** Structural property for getMetadata().parameterTypes[].structuralProperty */
|
|
185
|
-
declare const enum StructuralProperty {
|
|
186
|
-
Unknown = 0,
|
|
187
|
-
PrimitiveType = 1,
|
|
188
|
-
ComplexType = 2,
|
|
189
|
-
EnumerationType = 3,
|
|
190
|
-
Collection = 4,
|
|
191
|
-
EntityType = 5
|
|
192
|
-
}
|
|
193
|
-
/** Binding type for Custom API definitions */
|
|
194
|
-
declare const enum BindingType {
|
|
195
|
-
/** Nicht an eine Entity gebunden (global aufrufbar) */
|
|
196
|
-
Global = 0,
|
|
197
|
-
/** An einen einzelnen Entity-Datensatz gebunden */
|
|
198
|
-
Entity = 1,
|
|
199
|
-
/** An eine Entity-Collection gebunden */
|
|
200
|
-
EntityCollection = 2
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export { BindingType, ClientState, ClientType, DisplayState, FormNotificationLevel, OperationType, RequiredLevel, SaveMode, StructuralProperty, SubmitMode, parseFormattedValue, parseLookup, parseLookups, select, selectExpand };
|
package/dist/helpers.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
// src/generators/webapi-helpers.ts
|
|
2
|
-
function select(...fields) {
|
|
3
|
-
if (fields.length === 0) return "";
|
|
4
|
-
return `?$select=${fields.join(",")}`;
|
|
5
|
-
}
|
|
6
|
-
function parseLookup(response, navigationProperty) {
|
|
7
|
-
const key = `_${navigationProperty}_value`;
|
|
8
|
-
const id = response[key];
|
|
9
|
-
if (!id) return null;
|
|
10
|
-
return {
|
|
11
|
-
id,
|
|
12
|
-
name: response[`${key}@OData.Community.Display.V1.FormattedValue`] ?? "",
|
|
13
|
-
entityType: response[`${key}@Microsoft.Dynamics.CRM.lookuplogicalname`] ?? ""
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
function parseLookups(response, navigationProperties) {
|
|
17
|
-
const result = {};
|
|
18
|
-
for (const prop of navigationProperties) {
|
|
19
|
-
result[prop] = parseLookup(response, prop);
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
function parseFormattedValue(response, fieldName) {
|
|
24
|
-
return response[`${fieldName}@OData.Community.Display.V1.FormattedValue`] ?? null;
|
|
25
|
-
}
|
|
26
|
-
function selectExpand(fields, expand) {
|
|
27
|
-
const parts = [];
|
|
28
|
-
if (fields.length > 0) parts.push(`$select=${fields.join(",")}`);
|
|
29
|
-
if (expand) parts.push(`$expand=${expand}`);
|
|
30
|
-
return parts.length > 0 ? `?${parts.join("&")}` : "";
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// src/generators/xrm-constants.ts
|
|
34
|
-
var DisplayState = /* @__PURE__ */ ((DisplayState2) => {
|
|
35
|
-
DisplayState2["Expanded"] = "expanded";
|
|
36
|
-
DisplayState2["Collapsed"] = "collapsed";
|
|
37
|
-
return DisplayState2;
|
|
38
|
-
})(DisplayState || {});
|
|
39
|
-
var FormNotificationLevel = /* @__PURE__ */ ((FormNotificationLevel2) => {
|
|
40
|
-
FormNotificationLevel2["Error"] = "ERROR";
|
|
41
|
-
FormNotificationLevel2["Warning"] = "WARNING";
|
|
42
|
-
FormNotificationLevel2["Info"] = "INFO";
|
|
43
|
-
return FormNotificationLevel2;
|
|
44
|
-
})(FormNotificationLevel || {});
|
|
45
|
-
var RequiredLevel = /* @__PURE__ */ ((RequiredLevel2) => {
|
|
46
|
-
RequiredLevel2["None"] = "none";
|
|
47
|
-
RequiredLevel2["Required"] = "required";
|
|
48
|
-
RequiredLevel2["Recommended"] = "recommended";
|
|
49
|
-
return RequiredLevel2;
|
|
50
|
-
})(RequiredLevel || {});
|
|
51
|
-
var SubmitMode = /* @__PURE__ */ ((SubmitMode2) => {
|
|
52
|
-
SubmitMode2["Always"] = "always";
|
|
53
|
-
SubmitMode2["Never"] = "never";
|
|
54
|
-
SubmitMode2["Dirty"] = "dirty";
|
|
55
|
-
return SubmitMode2;
|
|
56
|
-
})(SubmitMode || {});
|
|
57
|
-
var SaveMode = /* @__PURE__ */ ((SaveMode2) => {
|
|
58
|
-
SaveMode2[SaveMode2["Save"] = 1] = "Save";
|
|
59
|
-
SaveMode2[SaveMode2["SaveAndClose"] = 2] = "SaveAndClose";
|
|
60
|
-
SaveMode2[SaveMode2["Deactivate"] = 5] = "Deactivate";
|
|
61
|
-
SaveMode2[SaveMode2["Reactivate"] = 6] = "Reactivate";
|
|
62
|
-
SaveMode2[SaveMode2["Send"] = 7] = "Send";
|
|
63
|
-
SaveMode2[SaveMode2["Disqualify"] = 15] = "Disqualify";
|
|
64
|
-
SaveMode2[SaveMode2["Qualify"] = 16] = "Qualify";
|
|
65
|
-
SaveMode2[SaveMode2["Assign"] = 47] = "Assign";
|
|
66
|
-
SaveMode2[SaveMode2["SaveAsCompleted"] = 58] = "SaveAsCompleted";
|
|
67
|
-
SaveMode2[SaveMode2["SaveAndNew"] = 59] = "SaveAndNew";
|
|
68
|
-
SaveMode2[SaveMode2["AutoSave"] = 70] = "AutoSave";
|
|
69
|
-
return SaveMode2;
|
|
70
|
-
})(SaveMode || {});
|
|
71
|
-
var ClientType = /* @__PURE__ */ ((ClientType2) => {
|
|
72
|
-
ClientType2["Web"] = "Web";
|
|
73
|
-
ClientType2["Outlook"] = "Outlook";
|
|
74
|
-
ClientType2["Mobile"] = "Mobile";
|
|
75
|
-
return ClientType2;
|
|
76
|
-
})(ClientType || {});
|
|
77
|
-
var ClientState = /* @__PURE__ */ ((ClientState2) => {
|
|
78
|
-
ClientState2["Online"] = "Online";
|
|
79
|
-
ClientState2["Offline"] = "Offline";
|
|
80
|
-
return ClientState2;
|
|
81
|
-
})(ClientState || {});
|
|
82
|
-
var OperationType = /* @__PURE__ */ ((OperationType2) => {
|
|
83
|
-
OperationType2[OperationType2["Action"] = 0] = "Action";
|
|
84
|
-
OperationType2[OperationType2["Function"] = 1] = "Function";
|
|
85
|
-
OperationType2[OperationType2["CRUD"] = 2] = "CRUD";
|
|
86
|
-
return OperationType2;
|
|
87
|
-
})(OperationType || {});
|
|
88
|
-
var StructuralProperty = /* @__PURE__ */ ((StructuralProperty2) => {
|
|
89
|
-
StructuralProperty2[StructuralProperty2["Unknown"] = 0] = "Unknown";
|
|
90
|
-
StructuralProperty2[StructuralProperty2["PrimitiveType"] = 1] = "PrimitiveType";
|
|
91
|
-
StructuralProperty2[StructuralProperty2["ComplexType"] = 2] = "ComplexType";
|
|
92
|
-
StructuralProperty2[StructuralProperty2["EnumerationType"] = 3] = "EnumerationType";
|
|
93
|
-
StructuralProperty2[StructuralProperty2["Collection"] = 4] = "Collection";
|
|
94
|
-
StructuralProperty2[StructuralProperty2["EntityType"] = 5] = "EntityType";
|
|
95
|
-
return StructuralProperty2;
|
|
96
|
-
})(StructuralProperty || {});
|
|
97
|
-
var BindingType = /* @__PURE__ */ ((BindingType2) => {
|
|
98
|
-
BindingType2[BindingType2["Global"] = 0] = "Global";
|
|
99
|
-
BindingType2[BindingType2["Entity"] = 1] = "Entity";
|
|
100
|
-
BindingType2[BindingType2["EntityCollection"] = 2] = "EntityCollection";
|
|
101
|
-
return BindingType2;
|
|
102
|
-
})(BindingType || {});
|
|
103
|
-
export {
|
|
104
|
-
BindingType,
|
|
105
|
-
ClientState,
|
|
106
|
-
ClientType,
|
|
107
|
-
DisplayState,
|
|
108
|
-
FormNotificationLevel,
|
|
109
|
-
OperationType,
|
|
110
|
-
RequiredLevel,
|
|
111
|
-
SaveMode,
|
|
112
|
-
StructuralProperty,
|
|
113
|
-
SubmitMode,
|
|
114
|
-
parseFormattedValue,
|
|
115
|
-
parseLookup,
|
|
116
|
-
parseLookups,
|
|
117
|
-
select,
|
|
118
|
-
selectExpand
|
|
119
|
-
};
|
|
120
|
-
//# sourceMappingURL=helpers.js.map
|
package/dist/helpers.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generators/webapi-helpers.ts","../src/generators/xrm-constants.ts"],"sourcesContent":["/**\r\n * @xrmforge/typegen - Web API Helper Functions\r\n *\r\n * Lightweight utility functions for building OData query strings\r\n * with type-safe field names from generated Fields enums.\r\n *\r\n * Zero runtime overhead when used with const enums (values are inlined).\r\n *\r\n * @example\r\n * ```typescript\r\n * import { select } from '@xrmforge/typegen';\r\n *\r\n * Xrm.WebApi.retrieveRecord(ref.entityType, ref.id, select(\r\n * AccountFields.Name,\r\n * AccountFields.WebsiteUrl,\r\n * AccountFields.Address1Line1,\r\n * ));\r\n * ```\r\n */\r\n\r\n/**\r\n * Build an OData $select query string from field names.\r\n *\r\n * @param fields - Field names (use generated Fields enum for type safety)\r\n * @returns OData query string (e.g. \"?$select=name,websiteurl,address1_line1\")\r\n */\r\nexport function select(...fields: string[]): string {\r\n if (fields.length === 0) return '';\r\n return `?$select=${fields.join(',')}`;\r\n}\r\n\r\n/**\r\n * Parse a lookup field from a Dataverse Web API response into a LookupValue.\r\n *\r\n * Dataverse returns lookups as `_fieldname_value` with OData annotations:\r\n * - `_fieldname_value` (GUID)\r\n * - `_fieldname_value@OData.Community.Display.V1.FormattedValue` (display name)\r\n * - `_fieldname_value@Microsoft.Dynamics.CRM.lookuplogicalname` (entity type)\r\n *\r\n * This function extracts all three into an `Xrm.LookupValue` object.\r\n *\r\n * @param response - The raw Web API response object\r\n * @param navigationProperty - Navigation property name (use NavigationProperties enum for type safety)\r\n * @returns Xrm.LookupValue or null if the lookup is empty\r\n *\r\n * @example\r\n * ```typescript\r\n * // Mit NavigationProperties-Enum (empfohlen, keine Raw-Strings):\r\n * parseLookup(result, AccountNav.Country);\r\n *\r\n * // Oder mit Navigation Property Name direkt:\r\n * parseLookup(result, 'markant_address1_countryid');\r\n * ```\r\n */\r\nexport function parseLookup(\r\n response: Record<string, unknown>,\r\n navigationProperty: string,\r\n): { id: string; name: string; entityType: string } | null {\r\n const key = `_${navigationProperty}_value`;\r\n const id = response[key] as string | undefined;\r\n if (!id) return null;\r\n\r\n return {\r\n id,\r\n name: (response[`${key}@OData.Community.Display.V1.FormattedValue`] as string) ?? '',\r\n entityType: (response[`${key}@Microsoft.Dynamics.CRM.lookuplogicalname`] as string) ?? '',\r\n };\r\n}\r\n\r\n/**\r\n * Parse multiple lookup fields from a Dataverse Web API response at once.\r\n *\r\n * @param response - The raw Web API response object\r\n * @param navigationProperties - Navigation property names to parse\r\n * @returns Map of navigation property name to LookupValue (null entries omitted)\r\n *\r\n * @example\r\n * ```typescript\r\n * const lookups = parseLookups(result, ['markant_address1_countryid', 'parentaccountid']);\r\n * formContext.getAttribute(Fields.Country).setValue(\r\n * lookups.markant_address1_countryid ? [lookups.markant_address1_countryid] : null\r\n * );\r\n * ```\r\n */\r\nexport function parseLookups(\r\n response: Record<string, unknown>,\r\n navigationProperties: string[],\r\n): Record<string, { id: string; name: string; entityType: string } | null> {\r\n const result: Record<string, { id: string; name: string; entityType: string } | null> = {};\r\n for (const prop of navigationProperties) {\r\n result[prop] = parseLookup(response, prop);\r\n }\r\n return result;\r\n}\r\n\r\n/**\r\n * Get the formatted (display) value of any field from a Web API response.\r\n *\r\n * Works for OptionSets, Lookups, DateTimes, Money, and other formatted fields.\r\n *\r\n * @param response - The raw Web API response object\r\n * @param fieldName - The field logical name (e.g. \"statecode\", \"createdon\")\r\n * @returns The formatted string value, or null if not available\r\n *\r\n * @example\r\n * ```typescript\r\n * const status = parseFormattedValue(result, 'statecode');\r\n * // \"Active\" (statt 0)\r\n * ```\r\n */\r\nexport function parseFormattedValue(\r\n response: Record<string, unknown>,\r\n fieldName: string,\r\n): string | null {\r\n return (response[`${fieldName}@OData.Community.Display.V1.FormattedValue`] as string) ?? null;\r\n}\r\n\r\n/**\r\n * Build an OData $select and $expand query string.\r\n *\r\n * @param fields - Field names to select\r\n * @param expand - Navigation property to expand (optional)\r\n * @returns OData query string\r\n *\r\n * @example\r\n * ```typescript\r\n * Xrm.WebApi.retrieveRecord(\"account\", id, selectExpand(\r\n * [AccountFields.Name, AccountFields.WebsiteUrl],\r\n * \"primarycontactid($select=fullname,emailaddress1)\"\r\n * ));\r\n * ```\r\n */\r\nexport function selectExpand(fields: string[], expand: string): string {\r\n const parts: string[] = [];\r\n if (fields.length > 0) parts.push(`$select=${fields.join(',')}`);\r\n if (expand) parts.push(`$expand=${expand}`);\r\n return parts.length > 0 ? `?${parts.join('&')}` : '';\r\n}\r\n","/**\r\n * @xrmforge/typegen - Xrm API Constants\r\n *\r\n * Const enums for all common Xrm string/number constants.\r\n * Eliminates raw strings in D365 form scripts.\r\n *\r\n * @types/xrm defines these as string literal types for compile-time checking,\r\n * but does NOT provide runtime constants (XrmEnum is not available at runtime).\r\n * These const enums are erased at compile time (zero runtime overhead).\r\n *\r\n * @example\r\n * ```typescript\r\n * // Statt Raw-String:\r\n * if (tab.getDisplayState() === 'expanded') { ... }\r\n *\r\n * // Mit XrmForge-Konstante:\r\n * if (tab.getDisplayState() === XrmConstants.DisplayState.Expanded) { ... }\r\n * ```\r\n */\r\n\r\n/** Tab/Section display state */\r\nexport const enum DisplayState {\r\n Expanded = 'expanded',\r\n Collapsed = 'collapsed',\r\n}\r\n\r\n// FormType: verwende XrmEnum.FormType aus @types/xrm (dort bereits als const enum definiert)\r\n\r\n/** Form notification level (formContext.ui.setFormNotification) */\r\nexport const enum FormNotificationLevel {\r\n Error = 'ERROR',\r\n Warning = 'WARNING',\r\n Info = 'INFO',\r\n}\r\n\r\n/** Attribute required level (attribute.setRequiredLevel) */\r\nexport const enum RequiredLevel {\r\n None = 'none',\r\n Required = 'required',\r\n Recommended = 'recommended',\r\n}\r\n\r\n/** Attribute submit mode (attribute.setSubmitMode) */\r\nexport const enum SubmitMode {\r\n Always = 'always',\r\n Never = 'never',\r\n Dirty = 'dirty',\r\n}\r\n\r\n/** Save mode (eventArgs.getSaveMode()) */\r\nexport const enum SaveMode {\r\n Save = 1,\r\n SaveAndClose = 2,\r\n Deactivate = 5,\r\n Reactivate = 6,\r\n Send = 7,\r\n Disqualify = 15,\r\n Qualify = 16,\r\n Assign = 47,\r\n SaveAsCompleted = 58,\r\n SaveAndNew = 59,\r\n AutoSave = 70,\r\n}\r\n\r\n/** Client type (Xrm.Utility.getGlobalContext().client.getClient()) */\r\nexport const enum ClientType {\r\n Web = 'Web',\r\n Outlook = 'Outlook',\r\n Mobile = 'Mobile',\r\n}\r\n\r\n/** Client state (Xrm.Utility.getGlobalContext().client.getClientState()) */\r\nexport const enum ClientState {\r\n Online = 'Online',\r\n Offline = 'Offline',\r\n}\r\n\r\n// ─── WebApi Execute Constants ───────────────────────────────────────────────\r\n\r\n/** Operation type for Xrm.WebApi.execute getMetadata().operationType */\r\nexport const enum OperationType {\r\n /** Custom Action or OOB Action (POST) */\r\n Action = 0,\r\n /** Custom Function or OOB Function (GET) */\r\n Function = 1,\r\n /** CRUD operation (Create, Retrieve, Update, Delete) */\r\n CRUD = 2,\r\n}\r\n\r\n/** Structural property for getMetadata().parameterTypes[].structuralProperty */\r\nexport const enum StructuralProperty {\r\n Unknown = 0,\r\n PrimitiveType = 1,\r\n ComplexType = 2,\r\n EnumerationType = 3,\r\n Collection = 4,\r\n EntityType = 5,\r\n}\r\n\r\n/** Binding type for Custom API definitions */\r\nexport const enum BindingType {\r\n /** Nicht an eine Entity gebunden (global aufrufbar) */\r\n Global = 0,\r\n /** An einen einzelnen Entity-Datensatz gebunden */\r\n Entity = 1,\r\n /** An eine Entity-Collection gebunden */\r\n EntityCollection = 2,\r\n}\r\n"],"mappings":"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","names":["DisplayState","FormNotificationLevel","RequiredLevel","SubmitMode","SaveMode","ClientType","ClientState","OperationType","StructuralProperty","BindingType"]}
|