Commit e5cc3a0
refactor(capabilities): inline datamodel structs into parent packages (#21)
Each capability exposed its wire structs through a parent-package alias
to a `<cap>/datamodel/` subpackage:
// capabilities/blob/add.go
type AddArguments = bdm.AddArgumentsModel
The split solved a real problem: `bindcap.Arguments` requires CBOR codec
methods, those methods are what `cbor-gen` produces, and the parent
package couldn't compile against itself before codegen ran. Putting the
wire structs in a separate package broke that bootstrap cleanly.
The indirection has accumulated costs worth addressing now:
- The aliases are pure renames (Foo = otherpkg.FooModel), which we've
been trying to avoid elsewhere in the codebase.
- The `Model` suffix leaks back through struct field declarations.
`args.Metadata` reads as `Metadata` at the call site, but hover-types
and error messages still surface `MetadataModel` because the field is
declared with the suffixed name. A recent piri refactor surfaced a
confusing type mismatch where the alias chain took a while to untangle.
- Each capability duplicates the same `datamodel/` boilerplate (a `gen/`
subfolder, generator entry point, generated codecs).
This change inlines each `<cap>/datamodel/` into its parent and drops
the rename aliases. The codegen bootstrap is preserved with a build tag:
binding files carry `//go:build !codegen` and the generator runs with
`-tags codegen`, so during codegen only the wire types compile (no
bindcap dependency). The generator post-processes its output to
re-inject the tag, keeping subsequent runs stale-safe.
The top-level `capabilities/datamodel.UnitModel` becomes
`capabilities.Unit`. Per-op `OK` aliases that resolved to `UnitModel`
are kept as within-package aliases (e.g. `type AddOK =
capabilities.Unit`) to preserve operation-named labels at type-parameter
call sites like `bindexec.Response[*blob.AddOK]`.
Additionally, `capabilities.MustNew` wraps `bindcap.New` and panics on
construction error. The previous `var Foo, _ = bindcap.New(...)` pattern
silently dropped errors that, for hardcoded commands and options, can
only ever be programmer bugs — failing at package init is strictly safer
than discovering it later via nil dereference.
External impact: only the sprue repo imports an inner datamodel package
directly (two test files using
`access/datamodel.CapabilityRequestModel`). Those need to update
alongside the libforge bump — change the import path and drop the
`Model` suffix.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 935195a commit e5cc3a0
136 files changed
Lines changed: 3074 additions & 1798 deletions
File tree
- capabilities
- access
- datamodel
- gen
- gen
- assert
- datamodel
- gen
- gen
- blob
- datamodel
- gen
- gen
- replica
- datamodel
- gen
- gen
- claim
- datamodel
- gen
- gen
- content
- datamodel
- gen
- gen
- datamodel
- gen
- debug
- datamodel/gen
- gen
- gen
- http
- datamodel/gen
- gen
- index
- datamodel/gen
- gen
- provider
- datamodel/gen
- gen
- space
- datamodel/gen
- egress
- gen
- gen
- ucan
- attest
- datamodel/gen
- gen
- datamodel/gen
- gen
- upload
- datamodel
- gen
- gen
- shard
- datamodel/gen
- gen
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 33 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
| 3 | + | |
8 | 4 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
| 5 | + | |
13 | 6 | | |
14 | 7 | | |
15 | 8 | | |
| 9 | + | |
| 10 | + | |
16 | 11 | | |
17 | 12 | | |
18 | | - | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
4 | | - | |
| 6 | + | |
5 | 7 | | |
6 | | - | |
7 | 8 | | |
8 | 9 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
0 commit comments