1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//! Typed field-shape metadata for request inputs and resource outputs.
//!
//! The `#[request]` macro generates [`FieldShape`] values and exposes them
//! through [`RequestMetadata`]; the `#[resource]` macro exposes them through
//! [`ResourceMetadata`]. Both are plain `&'static` data -- no allocation, no
//! runtime reflection, no `TypeId`/`Any` container. The `routes!` macro
//! resolves `<T as RequestMetadata>::FIELDS` / `<T as ResourceMetadata>::FIELDS`
//! at compile time when a route declares `action: T` / `query: T`, baking
//! the full field shape into the [`super::route_metadata::RouteDescriptor`]
//! const. The UAG then carries the field shapes so `arc typegen` can emit
//! `forms.ts` (an action's field names, types and `#[validate(...)]` rules)
//! and `routes.ts` into `resources/js/generated/`. Files on disk, not
//! virtual modules: emitting a virtual module would need a Vite plugin, and
//! a Vite plugin would need an npm package. See `docs/decisions/`.
//!
//! # Layering
//!
//! The macro captures the Rust type of each field *faithfully* as a
//! `&'static str` (e.g. `"String"`, `"Option<String>"`, `"Vec<i64>"`).
//! The Rust->TypeScript type mapping lives in `crate::uag::codegen::type_map`
//! -- the single code generator. `FieldShape` carries no pre-rendered
//! TypeScript: deriving the TS type (and the `optional` flag) from the Rust
//! type string is the codegen's responsibility, so one source of truth owns
//! the cross-stack type mapping.
//!
//! The role split into two traits is deliberate compile-time enforcement:
//! `action: T` requires `T: RequestMetadata` (a `#[request]` type -- a
//! mutation input), and `query: T` requires `T: ResourceMetadata` (a
//! `#[resource]` type -- a read output). A route that accidentally wires a
//! resource as an action input, or a request as a query output, fails to
//! compile -- the mistake is caught at the `routes!` invocation site.
/// The shape of one field of a `#[request]` input or `#[resource]` output.
///
/// Every field is `&'static str` or `&'static [&'static str]` -- no `Vec`,
/// no `String`, no allocation. A `const` slice of `FieldShape` is the
/// inspection artifact consumed by the application graph, the UAG, and the
/// `arc typegen` codegen.
///
/// `ty` is the field's Rust type rendered as a clean string (e.g.
/// `"String"`, `"Option<String>"`, `"Vec<i64>"`). The codegen derives the
/// TypeScript type and the `optional` flag from `ty`; `FieldShape` does not
/// pre-render TypeScript. `validates` carries the `#[validate(...)]` rule
/// strings (e.g. `["url"]`, `["length(min=1,max=120)"]`) for dev-time
/// introspection -- empty for resource fields, which carry no validation
/// attributes.
/// The per-request-type metadata trait: the `#[request]` macro emits
/// `impl RequestMetadata for Type` carrying the input's field descriptors as
/// a `&'static [FieldShape]` associated const. The `routes!` macro resolves
/// `<T as RequestMetadata>::FIELDS` when a route declares `action: T`,
/// baking the action's typed input shape into the `RouteDescriptor` const --
/// so the UAG carries it without a runtime type registry, global mutable
/// state, or `TypeId`/`Any` container.
///
/// This is the join point the action codegen uses: a route's `action_fields`
/// -> the entry for that route in the generated `forms.ts`.
/// The per-resource-type metadata trait: the `#[resource]` macro emits
/// `impl ResourceMetadata for Type` carrying the output's field descriptors
/// as a `&'static [FieldShape]` associated const. The `routes!` macro
/// resolves `<T as ResourceMetadata>::FIELDS` when a route declares
/// `query: T` (or `query: Vec<T>`), baking the query's typed response shape
/// into the `RouteDescriptor` const -- so the UAG carries it without a
/// runtime type registry.
///
/// This is the join point the query codegen uses: a route's `query_fields`
/// -> the response type the generated TypeScript gives that route.
///
/// `#[resource]` continues to emit `Serialize` + `ClientData` (the
/// browser-exposure firewall); `ResourceMetadata` is an *additive* static
/// view of the same fields for typed query codegen. A type annotated
/// `#[resource]` gains this impl automatically.