@khester/dataverse-codegen 0.1.0
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 +133 -0
- package/dist/cli.cjs +5481 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.mjs +5488 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index.cjs +1428 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +241 -0
- package/dist/index.d.ts +241 -0
- package/dist/index.mjs +1406 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +59 -0
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# @khester/dataverse-codegen (`dvgen`)
|
|
2
|
+
|
|
3
|
+
Terminal CLI that scaffolds the TypeScript a Dynamics 365 client project needs — a **CRUD API layer,
|
|
4
|
+
field constants, typed models, and test data** — straight from a live Dataverse org. Independent,
|
|
5
|
+
composable subcommands you run *inside* a client project (Web Resource / PCF / Grid Customizer).
|
|
6
|
+
|
|
7
|
+
Built on the shared [`@dynamics-ui-kit/entity-gen`](../entity-gen) engine. The published binary is
|
|
8
|
+
**bundled and self-contained** (zero runtime dependencies), so it runs in a bare client project with
|
|
9
|
+
no workspace install.
|
|
10
|
+
|
|
11
|
+
> Requires **Node ≥ 18** (uses the global `fetch`).
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
Pick whichever fits your workflow:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# 1. One-off, no install
|
|
21
|
+
npx @khester/dataverse-codegen <command> [options]
|
|
22
|
+
|
|
23
|
+
# 2. Global
|
|
24
|
+
npm i -g @khester/dataverse-codegen
|
|
25
|
+
dvgen <command> [options]
|
|
26
|
+
|
|
27
|
+
# 3. Per-project devDependency (recommended — mirrors your dev:token setup)
|
|
28
|
+
npm i -D @khester/dataverse-codegen
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
With option 3, add scripts to the client project's `package.json`:
|
|
32
|
+
|
|
33
|
+
```jsonc
|
|
34
|
+
{
|
|
35
|
+
"scripts": {
|
|
36
|
+
"gen:api": "dvgen api",
|
|
37
|
+
"gen:constants": "dvgen constants --entity stn_order",
|
|
38
|
+
"gen:models": "dvgen models --entity stn_order --with-retrieve",
|
|
39
|
+
"seed:pull": "dvgen seed:pull --entity stn_order",
|
|
40
|
+
"seed:push": "dvgen seed:push --entity stn_order --dry-run"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Authentication
|
|
48
|
+
|
|
49
|
+
Every command that hits the org resolves the URL + token in this order (tolerant of the env-var
|
|
50
|
+
prefixes client projects use):
|
|
51
|
+
|
|
52
|
+
1. `--url` / `--token` flags
|
|
53
|
+
2. `--env-file <path>` or process env: `DYNAMICS_*`, then `VITE_DYNAMICS_*`, then `REACT_APP_DYNAMICS_*`
|
|
54
|
+
(`_URL` and `_TOKEN`)
|
|
55
|
+
3. **Azure CLI** fallback — `az account get-access-token` for the resolved org URL
|
|
56
|
+
|
|
57
|
+
For a **cross-tenant client org** where you don't have `az login` to the client's tenant, pass a token
|
|
58
|
+
explicitly: `--token "$(...)"` or set `DYNAMICS_TOKEN`.
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Examples
|
|
62
|
+
dvgen constants --entity account --url https://org.crm.dynamics.com # token via az
|
|
63
|
+
dvgen models --entity account --env-file .env.local # url+token from .env.local
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## The pipeline
|
|
69
|
+
|
|
70
|
+
Mirrors the client build workflow (`CRUD API → constants → models → test data → test`):
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
dvgen api # → src/services/* (self-contained IApiService layer)
|
|
74
|
+
dvgen constants --entity stn_order # → src/constants/StnOrderConstants.ts
|
|
75
|
+
dvgen models --entity stn_order # → src/models/StnOrder.ts (first pass)
|
|
76
|
+
dvgen models --entity stn_order --with-retrieve # + retrieveWithRelated() link-entity scaffolds
|
|
77
|
+
dvgen seed:pull --entity stn_order --top 25 # → src/sampleData/stn_order.json (OData fixture)
|
|
78
|
+
dvgen test-retrieve --entity stn_order # read fixture (CI-safe) — or --live to query the org
|
|
79
|
+
dvgen seed:push --entity stn_order --dry-run # create records from the fixture (preview first!)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Commands
|
|
85
|
+
|
|
86
|
+
| Command | What it writes | Live org? |
|
|
87
|
+
|---------|----------------|-----------|
|
|
88
|
+
| `api` | `src/services/{IApiService,FetchApiService,XrmApiService,MockApiService,ServiceFactory}.ts` | No |
|
|
89
|
+
| `constants --entity <e>` | `src/constants/<Entity>Constants.ts` (field constants + option-set enums) | Yes |
|
|
90
|
+
| `models --entity <e> [--with-retrieve]` | `src/models/<Entity>.ts` (interface + class + `fromRaw` + `validate` + CRUD/retrieve) | Yes |
|
|
91
|
+
| `seed:pull --entity <e>` | `src/sampleData/<entity>.json` (OData `{ value: [...] }`) | Yes |
|
|
92
|
+
| `seed:push --entity <e>` | creates records in Dataverse from the fixture | Yes |
|
|
93
|
+
| `test-retrieve --entity <e> [--live]` | nothing (reports row counts/fields) | only with `--live` |
|
|
94
|
+
|
|
95
|
+
### Common options
|
|
96
|
+
|
|
97
|
+
- `--out <dir>` — output **base** dir (default `src`); each command appends its own subdir
|
|
98
|
+
(`services/`, `constants/`, `models/`, `sampleData/`). Pass `--out ./src`, **not** `--out ./src/services`.
|
|
99
|
+
- `--url` / `--token` / `--env-file` — connection (see Authentication).
|
|
100
|
+
- Write safety (constants / models / seed:pull): `--dry-run`, `--diff`, `--force`.
|
|
101
|
+
**Existing files are skipped unless `--force`** — hand-customized files are never clobbered.
|
|
102
|
+
|
|
103
|
+
### Notable flags
|
|
104
|
+
|
|
105
|
+
- `constants --no-augment` — skip the typed-cast metadata pass (MaxLength/Precision/… JSDoc detail).
|
|
106
|
+
- `models --with-retrieve` — emit `retrieveWithRelated()` with commented parent-lookup `<link-entity>`
|
|
107
|
+
scaffolds (uncomment the joins you need); `--api-service <import>` overrides the IApiService import.
|
|
108
|
+
- `seed:pull --top <n> --select <cols> --filter <odata>`.
|
|
109
|
+
- `seed:push --dry-run` (preview, **no writes**), `--top <n>`, `--file <path>`. Annotations, the
|
|
110
|
+
primary id, and `_x_value` lookups are stripped on push (lookups need `@odata.bind`, reported as
|
|
111
|
+
skipped).
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Design notes
|
|
116
|
+
|
|
117
|
+
- **Independent but composable** — run `constants` without `models`; `models` references the constants
|
|
118
|
+
file (extension-agnostic import) without regenerating it.
|
|
119
|
+
- **Self-contained output** — generated `src/services/*` and models carry **no** package imports, so a
|
|
120
|
+
generated project compiles standalone (verified: `tsc` with `isolatedModules`, ES2017, no
|
|
121
|
+
`@types/node`).
|
|
122
|
+
- **Shared engine** — constants/model generation is the same `entity-gen` engine the form-builder
|
|
123
|
+
export uses, so output stays consistent across tools.
|
|
124
|
+
|
|
125
|
+
## Develop / build
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
nvm use 20
|
|
129
|
+
npm install # at the dynamics-toolkit root (workspaces)
|
|
130
|
+
npm run build # tsup → dist (bundles all deps; dist/cli.cjs is the bin)
|
|
131
|
+
npm run typecheck
|
|
132
|
+
npm run test
|
|
133
|
+
```
|