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
//! Zod schema registration — collects TypeScript schema strings at link time.
//!
//! The `#[orpc]` macro emits `inventory::submit! { SchemaRegistration { ... } }`
//! for each input/output type it sees. `generate_contract()` then collects all
//! registered schemas and embeds them in the generated TypeScript file.
//!
//! ## How it works without manual `#[derive(ZodTs)]`
//!
//! Users annotate their types with `#[derive(ZodTs)]` from `zod-rs-ts`.
//! The `#[orpc]` macro emits a `SchemaRegistration` that captures:
//! - The Rust type name (for deduplication)
//! - A factory `fn() -> String` that calls `T::zod_ts()` at runtime
//!
//! This means the schema string is generated lazily at `generate_contract()` time,
//! not at macro expansion time.
// ---------------------------------------------------------------------------
// Structured schema definition — the data-oriented replacement for zod_ts()
// ---------------------------------------------------------------------------
/// A single field in a struct schema.
///
/// Exactly one of `zod_expr` or `type_ref` is non-empty:
/// - `zod_expr` — complete primitive expression, e.g. `"z.string().min(1)"`.
/// - `type_ref` — bare Rust type name of a custom type, e.g. `"Session"`.
/// The resolution pass maps this to the correct TS schema name.
/// Serde enum representation strategy.
///
/// Corresponds to `#[serde(tag = "...", content = "...")]` and `#[serde(untagged)]`
/// container attributes.
/// A single variant in an enum schema.
/// Structured description of a schema's shape.
///
/// Replaces the `zod_ts: fn() -> String` closure. The runtime resolution pass
/// converts this into a `ResolvedSchema` (in `codegen/ir.rs`) before emission.
// ---------------------------------------------------------------------------
// SchemaRegistration
// ---------------------------------------------------------------------------
/// A registered Zod schema for a single Rust type.
///
/// Registered globally by the `#[orpc]` macro via `inventory::submit!`.
collect!;