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
// SPDX-FileCopyrightText: 2025-2026 RAprogramm <andrey.rozanov.vl@gmail.com>
// SPDX-License-Identifier: MIT
//! Entity-level attribute parsing and definition.
//!
//! This module is the heart of the entity-derive macro system. It parses
//! `#[entity(...)]` attributes and produces `EntityDef`, the central data
//! structure that drives all code generation.
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────────┐
//! │ Entity Parsing Pipeline │
//! ├─────────────────────────────────────────────────────────────────────┤
//! │ │
//! │ Input Parsing Output │
//! │ │
//! │ #[entity( EntityDef:: │
//! │ table = "users", from_derive_input() EntityDef │
//! │ soft_delete, │ │ │
//! │ events │ │ │
//! │ )] ▼ │ │
//! │ struct User { ┌─────────────┐ │ │
//! │ #[id] │ EntityAttrs │ ◄── darling │ │
//! │ id: Uuid, │ (entity-lvl)│ │ │
//! │ #[field(create)] └─────────────┘ │ │
//! │ name: String, │ │ │
//! │ } │ ▼ │
//! │ ┌─────────────┐ ┌───────────┐ │
//! │ │ FieldDef │ ◄─────────│ EntityDef │ │
//! │ │ (per field) │ │ + fields │ │
//! │ └─────────────┘ └───────────┘ │
//! │ │ │
//! │ ▼ │
//! │ Code Generation │
//! │ ├── SQL layer │
//! │ ├── DTO structs │
//! │ ├── Repository │
//! │ └── API handlers │
//! │ │
//! └─────────────────────────────────────────────────────────────────────┘
//! ```
//!
//! # Module Structure
//!
//! | File | Purpose |
//! |------|---------|
//! | `def.rs` | `EntityDef` struct definition with all fields |
//! | `constructor.rs` | `from_derive_input()` implementation |
//! | `accessors.rs` | Accessor methods for fields and metadata |
//! | `attrs.rs` | `EntityAttrs` darling parsing struct |
//! | `helpers.rs` | Helper functions for parsing relations and API |
//! | `projection.rs` | Projection definition and parsing |
//! | `tests.rs` | Comprehensive unit tests |
//!
//! # Entity Attributes
//!
//! The `#[entity(...)]` attribute supports extensive configuration:
//!
//! ## Required Attributes
//!
//! | Attribute | Description |
//! |-----------|-------------|
//! | `table` | Database table name (e.g., `"users"`) |
//!
//! ## Optional Attributes
//!
//! | Attribute | Default | Description |
//! |-----------|---------|-------------|
//! | `schema` | `"public"` | Database schema |
//! | `sql` | `Full` | SQL generation level |
//! | `dialect` | `Postgres` | Database dialect |
//! | `uuid` | `V7` | UUID version for IDs |
//! | `error` | `sqlx::Error` | Custom error type |
//! | `returning` | `Full` | RETURNING clause mode |
//!
//! ## Feature Flags
//!
//! | Flag | Effect |
//! |------|--------|
//! | `soft_delete` | Enable soft delete with `deleted_at` field |
//! | `events` | Generate `{Entity}Event` enum |
//! | `hooks` | Generate `{Entity}Hooks` trait |
//! | `commands` | Enable CQRS command pattern |
//! | `policy` | Generate authorization policy trait |
//! | `streams` | Enable real-time LISTEN/NOTIFY streaming |
//! | `transactions` | Generate transaction support |
//!
//! # Usage Example
//!
//! ```rust,ignore
//! use crate::entity::parse::EntityDef;
//!
//! // Parse from derive input
//! let entity = EntityDef::from_derive_input(&input)?;
//!
//! // Access entity metadata
//! let table = entity.full_table_name(); // "public.users"
//! let id = entity.id_field(); // FieldDef for #[id] field
//!
//! // Access field categories for DTO generation
//! let create_fields = entity.create_fields(); // #[field(create)]
//! let update_fields = entity.update_fields(); // #[field(update)]
//! let response_fields = entity.response_fields(); // #[field(response)]
//!
//! // Generate related type names
//! let row_ident = entity.ident_with("", "Row"); // UserRow
//! let repo_ident = entity.ident_with("", "Repository"); // UserRepository
//! ```
//!
//! # Field Categories
//!
//! Fields are categorized based on `#[field(...)]` attributes:
//!
//! ```text
//! ┌──────────────────────────────────────────────────────────────┐
//! │ Field Categories │
//! ├──────────────────────────────────────────────────────────────┤
//! │ │
//! │ create_fields() ──► CreateUserRequest │
//! │ ├─► #[field(create)] │
//! │ ├─► NOT #[id] │
//! │ └─► NOT #[auto] │
//! │ │
//! │ update_fields() ──► UpdateUserRequest │
//! │ ├─► #[field(update)] │
//! │ ├─► NOT #[id] │
//! │ └─► NOT #[auto] │
//! │ │
//! │ response_fields() ──► UserResponse │
//! │ └─► #[field(response)] OR #[id] │
//! │ │
//! │ all_fields() ──► UserRow, InsertableUser │
//! │ └─► All fields (database layer) │
//! │ │
//! └──────────────────────────────────────────────────────────────┘
//! ```
pub use EntityAttrs;
pub use EntityDef;
pub use CompositeIndexDef;
pub use ;