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
//! Procedural macros for `taut-rpc`.
//!
//! This crate is an implementation detail of `taut-rpc`; users should depend on
//! `taut-rpc` and import the macros via its re-exports rather than depending on
//! this crate directly.
//!
//! Four macros are provided through Phase 4:
//!
//! - `#[rpc]` — attribute macro applied to a free `async fn` (queries and
//! mutations only in Phase 1; `#[rpc(stream)]` lands in Phase 3). Supports
//! `#[rpc]` and `#[rpc(method = "GET")]`. See SPEC §2 (architecture) and §4
//! (wire format).
//! - `#[derive(Type)]` — derive macro that records a Rust type in the IR so
//! the codegen step can emit a corresponding TypeScript definition. Works on
//! structs (named, tuple, unit) and enums (unit, tuple, struct variants).
//! See SPEC §3 (type mapping).
//! - `#[derive(TautError)]` — derive macro that supplies the `TautError`
//! trait impl (per-variant `code()` and `http_status()`) for an enum. See
//! SPEC §3.3 (errors).
//! - `#[derive(Validate)]` — derive macro that emits the `Validate` trait impl
//! from per-field `#[taut(...)]` constraint attributes (`min`, `max`,
//! `length`, `pattern`, `email`, `url`, `custom`). See SPEC §7 (validation
//! bridge).
//!
//! All macros report errors via `syn::Error::into_compile_error` so failures
//! surface as compiler diagnostics rather than panics.
use TokenStream;
/// Marks an `async fn` as a `taut-rpc` procedure.
///
/// Forms:
/// - `#[rpc]` — query (default).
/// - `#[rpc(stream)]` — server-streaming subscription.
/// - `#[rpc(method = "GET")]` — opt-in cacheable GET query.
/// Derives `taut-rpc`'s type-registration trait for a struct or enum so the
/// type appears in the IR and gets a TypeScript definition emitted.
/// Derives `taut-rpc`'s `TautError` trait for an enum, supplying `code()`
/// (default: variant name in `snake_case`) and `http_status()` (default: 400)
/// per variant. Both can be overridden via `#[taut(code = "...", status =
/// 401)]`. See SPEC §3.3.
/// Derives `taut-rpc`'s `Validate` trait for a struct or enum, walking each
/// field's `#[taut(...)]` constraints (`min`, `max`, `length`, `pattern`,
/// `email`, `url`, `custom`) and dispatching to the corresponding
/// `validate::check::*` runtime helpers. Foreign `#[taut(...)]` keys owned by
/// other derives (`rename`, `tag`, `optional`, `undefined`, `code`, `status`)
/// are silently ignored. See SPEC §7.