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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
//! Reject schema names that collide with a *generated* `{Name}Builder`
//! typestate-builder symbol (see `cratestack-macros/src/builder.rs`).
//!
//! Every struct-shaped generated type now emits `impl {Name} {
//! fn builder() }` plus a `{Name}Builder` struct into the *same module* the
//! `{Name}` struct itself lives in (`types`/`models` — see the module docs on
//! [`super::snake_case_collisions::validate_type_declaration_collisions`]
//! for why `type`/`enum`/`model` already share one generated namespace, and
//! `view` structs are emitted straight into the `models` module alongside
//! model structs). If a schema *also* declares an entity literally named
//! `{Name}Builder`, the generated builder and the user's own declaration
//! land on the same identifier:
//!
//! - Same-module case (`type Foo` + `type FooBuilder`, or `model Foo` +
//! `model FooBuilder`): `error[E0428]: the name `FooBuilder` is defined
//! multiple times`, reported only at the `include_*_schema!` call site.
//! - Cross-module case (`type Order` + `model OrderBuilder`): both
//! `types::OrderBuilder` (the generated builder for `type Order`) and
//! `models::OrderBuilder` (the struct for `model OrderBuilder`) reach the
//! parent module through `pub use types::*; pub use models::*;` —
//! `error[E0659]: `OrderBuilder` is ambiguous`, silent until something
//! actually names the type.
//!
//! Both are opaque, hard-to-diagnose failures at macro-expansion time, so —
//! same rationale as [`super::reserved_idents`] — reject the collision at
//! schema-parse time with a message that names the two conflicting
//! declarations directly.
//!
//! A `model` generates *seven* struct-shaped names across the two
//! generators that currently emit builders (Rust and Dart — see
//! `cratestack-macros/src/builder.rs`'s module doc for the full list of
//! call sites): `{M}`, `Create{M}Input`, `Update{M}Input`, `{M}Where`,
//! `{M}OrderByClause`, `{M}FindManyInput` (the Rust struct name,
//! `cratestack-macros/src/model/find_many_input.rs`), and `{M}FindMany`
//! (the *Dart* class name for that same generated shape,
//! `cratestack-client-dart/src/find_many_views.rs`'s
//! `build_find_many_data_class` — Dart drops the `Input` suffix). Each
//! claims a `{...}Builder` name, so all seven are reserved. (`{M}SortField`
//! is an enum and generates no builder.) The builder's own value holder is
//! an anonymous tuple, deliberately, so it claims no name here at all —
//! see `cratestack-macros/src/builder.rs`.
//!
//! A `procedure` generates one more: its Dart-side argument wrapper class,
//! `{PascalCase(name)}Args` (`cratestack-client-dart/src/naming.rs`'s
//! `procedure_wrapper_name`), together with the two names that function
//! falls back to when the default is taken — all three are reserved; see
//! the `Kind::Procedure` doc. Note a procedure is a collision *source*
//! only, never a target: it generates `{P}Args`, but nothing named `{P}`
//! itself, so `procedure WidgetBuilder(..)` alongside `model Widget` is
//! valid and must not be rejected. The equivalent Rust struct is scoped inside
//! `pub mod <procedure>` on both the server and the Rust client
//! (`cratestack-macros/src/procedure/types.rs`), so it never collides with
//! anything at the shared `types`/`models` namespace this validator
//! covers and needs no reservation.
//!
//! Comparison is exact raw-name equality, not [`to_snake_case`] normalized:
//! `format_ident!("{}Builder", target)` is a literal string concatenation
//! on the already-validated (schema-representable) declared name, with no
//! case folding involved. The one exception is the procedure-name ->
//! PascalCase step itself, which uses the single shared
//! [`cratestack_core::pascal_case::to_pascal_case`] — the same function
//! `cratestack-client-dart` calls to build the real symbol — rather than a
//! second copy here that could drift from it.
//!
//! [`to_snake_case`]: cratestack_core::route_naming::to_snake_case
use to_pascal_case;
use ;
use crate;
/// One declared name that participates in the shared `types`/`models`
/// generated-symbol namespace, with enough metadata to report a collision.
/// Reject any declared `type`/`model`/`view`/`enum` name that exactly
/// matches the generated `{Name}Builder` symbol of another `type`/`model`/
/// `view` declaration in the same schema.
pub