domaintrail 0.2.0 → 0.4.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 +61 -21
- package/dist/dt.js +6205 -2005
- package/dist/web/chunk-cgxb04qn.css +1 -0
- package/dist/web/{chunk-13zkn5c3.js → chunk-g3azafq4.js} +113 -113
- package/dist/web/index.html +1 -1
- package/package.json +7 -4
- package/schema/diagnostics.schema.json +59 -0
- package/schema/domaintrail.schema.json +10 -0
- package/dist/web/chunk-s7gt31ry.css +0 -1
package/README.md
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
A type-checkable domain modeling DSL shared by humans and AI.
|
|
4
4
|
AI agents edit `.dt` files; humans watch the model update live in the browser and give feedback.
|
|
5
|
-
The DSL is the single source of truth for domain **structure and contracts** — it generates TypeScript types
|
|
6
|
-
contracts,
|
|
5
|
+
The DSL is the single source of truth for domain **structure and contracts** — it generates TypeScript types, command
|
|
6
|
+
contracts, checks of the invariants and requirements it states, and contract tests for your implementation, never
|
|
7
|
+
business logic.
|
|
7
8
|
|
|
8
9
|
## Setup
|
|
9
10
|
|
|
@@ -17,10 +18,13 @@ npx domaintrail <command> # or run it without installing
|
|
|
17
18
|
## CLI
|
|
18
19
|
|
|
19
20
|
```bash
|
|
20
|
-
dt guide
|
|
21
|
+
dt guide [topic] # quick reference and topics; one topic (dt guide requires); --all for everything
|
|
22
|
+
dt -r <root> fmt # format .dt files in place in the canonical layout (--check for CI)
|
|
21
23
|
dt -r <root> check # validate syntax, references, types and DDD rules
|
|
22
24
|
dt -r <root> generate ts # generate TypeScript into <root>/generated/domain (--out to change)
|
|
23
25
|
dt -r <root> view # Live View at http://127.0.0.1:4321 (--port, --host); runs until Ctrl+C
|
|
26
|
+
dt lsp # language server over stdio: dt check's diagnostics, definitions, references, hover
|
|
27
|
+
dt -r <root> show <name> # one element resolved: field sets, labels, commands' contracts, who uses it
|
|
24
28
|
```
|
|
25
29
|
|
|
26
30
|
The package installs the same command under two names: `dt` for everyday use and `domaintrail`, its full name, for
|
|
@@ -29,7 +33,8 @@ when `dt` clashes with another command or a script should spell it out (CI, for
|
|
|
29
33
|
`<root>` defaults to the current directory; every `*.dt` file below it (except `node_modules`, `.git`, `.domaintrail`)
|
|
30
34
|
belongs to the workspace. `dt --help` and `dt <command> --help` show the options with examples.
|
|
31
35
|
|
|
32
|
-
`check` prints diagnostics as `file:line:col - error M00X: message`
|
|
36
|
+
`check` prints diagnostics as `file:line:col - error M00X: message` (with a `hint:` line on what to change, when there is
|
|
37
|
+
one) and exits non-zero on errors; `check --format json` prints them as one JSON document (`schema/diagnostics.schema.json`).
|
|
33
38
|
`generate ts` runs `check` first and generates nothing if there are errors.
|
|
34
39
|
|
|
35
40
|
Try it with the example in this repository (see [Development](#development)):
|
|
@@ -37,30 +42,51 @@ Try it with the example in this repository (see [Development](#development)):
|
|
|
37
42
|
```bash
|
|
38
43
|
bun run dt -r examples/shop check
|
|
39
44
|
bun run dt -r examples/shop generate ts # then examples/shop/src/order-commands.ts type-checks against it
|
|
45
|
+
(cd examples/shop && bun test) # and passes the generated contract tests
|
|
40
46
|
bun run build && bun run dt -r examples/shop view
|
|
41
47
|
```
|
|
42
48
|
|
|
43
49
|
## Guide
|
|
44
50
|
|
|
45
|
-
**[docs/guide.md](docs/guide.md)** is the reference for writing models and using the CLI
|
|
46
|
-
|
|
51
|
+
**[docs/guide.md](docs/guide.md)** is the reference for writing models and using the CLI. It starts with a
|
|
52
|
+
[quick reference](docs/guide.md#quick-reference) (the workflow, the DSL at a glance, the commands), and its sections are
|
|
53
|
+
**topics** that the CLI prints one at a time, so people and AI agents read only what they need without leaving the
|
|
54
|
+
terminal:
|
|
47
55
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
```bash
|
|
57
|
+
dt guide # the quick reference and the list of topics (about one screen)
|
|
58
|
+
dt guide requires # one topic: a ## section with its ### sections, or one ### section
|
|
59
|
+
dt guide M010 # one rule and the topics that explain it
|
|
60
|
+
dt guide --all # the whole guide, the same text as docs/guide.md
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The sections, in the guide's order:
|
|
64
|
+
|
|
65
|
+
- [Workflow](docs/guide.md#workflow): `fmt` → `check` → `generate ts` → implement with `decide` → type-check your own
|
|
66
|
+
code (`tsc --noEmit`) → run the generated contract tests
|
|
52
67
|
- [File layout (recommended)](docs/guide.md#file-layout-recommended): `<context>/<aggregate>.dt` and
|
|
53
68
|
`<context>/context.dt` (see [ADR 0009](docs/adr/0009-file-layout.md))
|
|
54
69
|
- [DSL](docs/guide.md#dsl): contexts, aggregates, entities, values, states, commands, events, errors,
|
|
55
70
|
[domain primitives](docs/guide.md#domain-primitives), [unions](docs/guide.md#unions),
|
|
56
71
|
[shared contexts](docs/guide.md#shared-contexts), [field sets](docs/guide.md#field-sets),
|
|
57
72
|
[domain and technical fields](docs/guide.md#domain-fields-and-technical-fields),
|
|
58
|
-
[names (表示名)](docs/guide.md#names-labels-and-descriptions)
|
|
59
|
-
|
|
60
|
-
|
|
73
|
+
[names (表示名)](docs/guide.md#names-labels-and-descriptions),
|
|
74
|
+
[invariant expressions](docs/guide.md#invariant-expressions), [command requirements](docs/guide.md#command-requirements),
|
|
75
|
+
[command changes](docs/guide.md#command-changes), [command events](docs/guide.md#command-events) and
|
|
76
|
+
[pure commands](docs/guide.md#pure-commands)
|
|
77
|
+
- [Generated TypeScript](docs/guide.md#generated-typescript): [decisions and `decide`](docs/guide.md#decisions-and-decide),
|
|
61
78
|
[what is generated and what you write](docs/guide.md#generated-code-and-your-code) (see
|
|
62
|
-
[ADR 0011](docs/adr/0011-generated-code-boundary.md)), [
|
|
79
|
+
[ADR 0011](docs/adr/0011-generated-code-boundary.md)), [generated checks](docs/guide.md#generated-checks) and
|
|
80
|
+
[generated tests](docs/guide.md#generated-tests) (see [ADR 0020](docs/adr/0020-generated-checks-and-contract-tests.md)),
|
|
63
81
|
[technical metadata](docs/guide.md#technical-metadata) (see [ADR 0013](docs/adr/0013-field-sets-and-technical-metadata.md))
|
|
82
|
+
and [output directories](docs/guide.md#output-directories)
|
|
83
|
+
- [Rules](docs/guide.md#rules): M001–M021, L001–L003
|
|
84
|
+
- [Looking up one element](docs/guide.md#looking-up-one-element): `dt show`, as text or JSON
|
|
85
|
+
- [Formatting](docs/guide.md#formatting): `dt fmt`, the one canonical layout of `.dt` files
|
|
86
|
+
- [Output and exit codes](docs/guide.md#output-and-exit-codes): text, or JSON with `--format json`
|
|
87
|
+
- [Configuration](docs/guide.md#configuration): `domaintrail.jsonc` (`sources`, `generate.ts.out` /
|
|
88
|
+
`generate.ts.contexts` / `generate.ts.tests`, `view.port` / `view.host`; JSON Schema in `schema/domaintrail.schema.json`)
|
|
89
|
+
- [Language server](docs/guide.md#language-server): `dt lsp`, and how to use it from an editor or Claude Code
|
|
64
90
|
|
|
65
91
|
A taste of the DSL:
|
|
66
92
|
|
|
@@ -70,16 +96,30 @@ context Sales "販売" {
|
|
|
70
96
|
aggregate Order "注文" {
|
|
71
97
|
id: OrderId
|
|
72
98
|
state Draft
|
|
73
|
-
state Confirmed {
|
|
74
|
-
|
|
75
|
-
|
|
99
|
+
state Confirmed {
|
|
100
|
+
confirmedAt: Timestamp
|
|
101
|
+
}
|
|
102
|
+
create command place(id: OrderId) -> Draft
|
|
103
|
+
command confirm(at: Timestamp)
|
|
104
|
+
Draft -> Confirmed
|
|
105
|
+
emits OrderConfirmed
|
|
106
|
+
}
|
|
107
|
+
persistent event OrderConfirmed {
|
|
108
|
+
orderId: OrderId
|
|
109
|
+
confirmedAt: Timestamp
|
|
76
110
|
}
|
|
77
|
-
persistent event OrderConfirmed { orderId: OrderId confirmedAt: Timestamp }
|
|
78
111
|
}
|
|
79
112
|
```
|
|
80
113
|
|
|
81
114
|
The design decisions behind the DSL are in [docs/adr](docs/adr): shared contexts ([0004](docs/adr/0004-shared-contexts.md)),
|
|
82
|
-
unions ([0005](docs/adr/0005-unions.md)), persistent events ([0008](docs/adr/0008-persistent-events.md))
|
|
115
|
+
unions ([0005](docs/adr/0005-unions.md)), persistent events ([0008](docs/adr/0008-persistent-events.md)),
|
|
116
|
+
command transitions ([0014](docs/adr/0014-command-transitions.md)), handlers per state
|
|
117
|
+
([0015](docs/adr/0015-handlers-per-state.md), superseded), collection constraints and declared invariants
|
|
118
|
+
([0016](docs/adr/0016-collection-constraints-and-declared-invariants.md)), command requirements
|
|
119
|
+
([0017](docs/adr/0017-command-requirements.md)), command events as an exact contract
|
|
120
|
+
([0018](docs/adr/0018-command-events-contract.md)), the fields a command changes and decisions
|
|
121
|
+
([0019](docs/adr/0019-command-changes-and-decisions.md)), generated checks and contract tests
|
|
122
|
+
([0020](docs/adr/0020-generated-checks-and-contract-tests.md)) and more.
|
|
83
123
|
|
|
84
124
|
## Live View
|
|
85
125
|
|
|
@@ -135,7 +175,7 @@ Requires [Bun](https://bun.sh) (version pinned in `mise.toml`). `bun run dt` run
|
|
|
135
175
|
bun install
|
|
136
176
|
bun run langium:generate # after editing src/language/domain.langium
|
|
137
177
|
bun run typecheck
|
|
138
|
-
bun test
|
|
178
|
+
bun test # the repository's tests (bunfig.toml: test/ only)
|
|
139
179
|
bun run build # dist/: the CLI bundled for Node and the Live View page (needed by `view` and the tests)
|
|
140
180
|
```
|
|
141
181
|
|
|
@@ -150,7 +190,7 @@ See [docs/releasing.md](docs/releasing.md).
|
|
|
150
190
|
| `src/language` | Langium grammar, generated parser/AST, scoping |
|
|
151
191
|
| `src/core` | analyzer, diagnostics, validation rules (`checker/`) |
|
|
152
192
|
| `src/model` | Typed Model (serializable, resolved) |
|
|
153
|
-
| `src/generator` | TypeScript generator and naming |
|
|
193
|
+
| `src/generator` | TypeScript generator and naming, generated checks (`checks.ts`) and contract tests (`tests.ts`, `testing/`) |
|
|
154
194
|
| `src/graph`, `src/layout` | Graph IR, diff, ELK layout |
|
|
155
195
|
| `src/server`, `web` | Live View server and React + tldraw client |
|
|
156
196
|
|