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
// SPDX-FileCopyrightText: 2025-2026 RAprogramm <andrey.rozanov.vl@gmail.com>
// SPDX-License-Identifier: MIT
//! Attribute parsing for the Entity derive macro.
//!
//! This module handles extraction of entity metadata from Rust attributes.
//! It uses [`darling`] for entity-level attributes and manual parsing for
//! field-level attributes (which use marker-style syntax).
//!
//! # Architecture
//!
//! ```text
//! parse.rs (coordinator)
//! ├── entity.rs - Entity-level parsing (EntityDef)
//! ├── field.rs - Field-level parsing (FieldDef)
//! │ ├── expose.rs - DTO exposure config (create, update, response, skip)
//! │ └── storage.rs - DB storage config (id, auto)
//! ├── command.rs - Command pattern parsing (CommandDef, CommandSource)
//! ├── dialect.rs - Database dialect (Postgres, ClickHouse, MongoDB)
//! ├── sql_level.rs - SQL generation level (Full, Trait, None)
//! └── uuid_version.rs - UUID version for IDs (V7, V4)
//! ```
//!
//! # Parsing Strategy
//!
//! Entity-level attributes like `#[entity(table = "users", schema = "core")]`
//! are parsed using darling's `FromDeriveInput` derive macro, which provides:
//!
//! - Automatic validation of required fields
//! - Default values for optional fields
//! - Clear error messages for invalid input
//!
//! Field-level attributes like `#[id]`, `#[auto]`, and `#[field(create,
//! update)]` use manual parsing because they're marker attributes that don't
//! fit darling's key-value model well.
//!
//! # Data Structures
//!
//! ```text
//! EntityDef
//! ├── ident: Ident (struct name, e.g., "User")
//! ├── vis: Visibility (pub, pub(crate), etc.)
//! ├── table: String (database table name)
//! ├── schema: String (database schema)
//! ├── sql: SqlLevel (generation level)
//! ├── dialect: DatabaseDialect (Postgres, ClickHouse, MongoDB)
//! ├── uuid: UuidVersion (V7 or V4)
//! ├── commands: bool (generate command pattern)
//! ├── command_defs: Vec<CommandDef> (parsed #[command(...)])
//! │ └── CommandDef
//! │ ├── name: Ident (command name, e.g., "Register")
//! │ ├── source: CommandSource (where fields come from)
//! │ ├── requires_id: bool (needs entity ID)
//! │ ├── result_type: Option (custom result type)
//! │ └── kind: CommandKindHint (create/update/delete/custom)
//! └── fields: Vec<FieldDef>
//! └── FieldDef
//! ├── ident: Ident (field name)
//! ├── ty: Type (field type)
//! ├── vis: Visibility (field visibility)
//! ├── expose: ExposeConfig (DTO exposure)
//! │ ├── create: bool (in CreateRequest)
//! │ ├── update: bool (in UpdateRequest)
//! │ ├── response: bool (in Response)
//! │ └── skip: bool (excluded from DTOs)
//! └── storage: StorageConfig (DB storage)
//! ├── is_id: bool (#[id] present)
//! └── is_auto: bool (#[auto] present)
//! ```
//!
//! # Examples
//!
//! ## Basic Parsing
//!
//! ```rust,ignore
//! #[derive(Entity)]
//! #[entity(table = "users")]
//! pub struct User {
//! #[id]
//! pub id: Uuid,
//!
//! #[field(create, response)]
//! pub name: String,
//! }
//!
//! // Parses to:
//! // EntityDef {
//! // ident: "User",
//! // table: "users",
//! // schema: "public", // default
//! // sql: SqlLevel::Full, // default
//! // dialect: DatabaseDialect::Postgres, // default
//! // uuid: UuidVersion::V7, // default
//! // fields: [
//! // FieldDef { ident: "id", storage.is_id: true, ... },
//! // FieldDef { ident: "name", expose.create: true, expose.response: true, ... },
//! // ]
//! // }
//! ```
//!
//! ## Custom Schema and Dialect
//!
//! ```rust,ignore
//! #[derive(Entity)]
//! #[entity(table = "products", schema = "inventory", dialect = "postgres", uuid = "v4")]
//! pub struct Product { /* ... */ }
//! ```
// Re-exported for handler generation (#77)
pub use ApiConfig;
pub use ;
pub use DatabaseDialect;
pub use ;
// Will be used for OpenAPI schema examples (#80)
pub use ExampleValue;
// Re-exported for migration generation tests
pub use ;
pub use ReturningMode;
pub use SqlLevel;
pub use UuidVersion;