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
use TokenStream;
/// Marks a struct as a FORGE model, generating schema metadata for TypeScript codegen.
///
/// # Example
/// ```ignore
/// #[forgex::model]
/// pub struct User {
/// pub id: Uuid,
/// pub email: String,
/// pub name: String,
/// pub created_at: DateTime<Utc>,
/// }
/// ```
/// Marks an enum for database storage as a PostgreSQL ENUM type.
///
/// # Example
/// ```ignore
/// #[forgex::forge_enum]
/// pub enum ProjectStatus {
/// Draft,
/// Active,
/// Paused,
/// Completed,
/// }
/// ```
/// Marks a function as a query (read-only, cacheable, subscribable).
///
/// # Attributes
/// - `cache = "5m"` - Cache TTL (duration like "30s", "5m", "1h")
/// - `public` - No authentication required
/// - `require_auth` - Require authentication
/// - `timeout = 30` - Timeout in seconds
///
/// # Example
/// ```ignore
/// #[forgex::query]
/// pub async fn get_user(ctx: &QueryContext, user_id: Uuid) -> Result<User> {
/// // ...
/// }
///
/// #[forgex::query(cache = "5m", require_auth)]
/// pub async fn get_profile(ctx: &QueryContext) -> Result<Profile> {
/// let user_id = ctx.require_user_id()?;
/// // ...
/// }
/// ```
/// Marks a function as a mutation (transactional write).
///
/// Mutations run within a database transaction. All changes commit together or roll back on error.
///
/// # Attributes
/// - `require_auth` - Require authentication
/// - `require_role("admin")` - Require specific role
/// - `timeout = 30` - Timeout in seconds
///
/// # Example
/// ```ignore
/// #[forgex::mutation]
/// pub async fn create_project(ctx: &MutationContext, input: CreateProjectInput) -> Result<Project> {
/// let user_id = ctx.require_user_id()?;
/// // ...
/// }
/// ```
/// Marks a function as an action (side effects, external APIs).
///
/// Actions can call external APIs and perform side effects. NOT transactional.
///
/// # Attributes
/// - `require_auth` - Require authentication
/// - `require_role("admin")` - Require specific role
/// - `timeout = 60` - Timeout in seconds
///
/// # Example
/// ```ignore
/// #[forgex::action(timeout = 60)]
/// pub async fn sync_with_stripe(ctx: &ActionContext, user_id: Uuid) -> Result<SyncResult> {
/// let customer = ctx.http().get("https://api.stripe.com/...").await?;
/// // ...
/// }
/// ```
/// Marks a function as a background job.
///
/// Jobs are durable background tasks that survive server restarts and automatically retry on failure.
///
/// # Attributes
/// - `timeout = "30m"` - Job timeout
/// - `priority = "normal"` - background, low, normal, high, critical
/// - `max_attempts = 3` - Maximum retry attempts
/// - `worker_capability = "general"` - Required worker capability
///
/// # Example
/// ```ignore
/// #[forgex::job]
/// #[timeout = "30m"]
/// #[priority = "high"]
/// pub async fn send_welcome_email(ctx: &JobContext, input: SendEmailInput) -> Result<()> {
/// // ...
/// }
/// ```
/// Marks a function as a scheduled cron task.
///
/// Cron jobs run on a schedule, exactly once per scheduled time across the cluster.
///
/// # Attributes
/// - `timezone = "UTC"` - Timezone for the schedule
/// - `catch_up` - Run missed executions after downtime
/// - `timeout = "1h"` - Execution timeout
///
/// # Example
/// ```ignore
/// #[forgex::cron("0 0 * * *")]
/// #[timezone = "UTC"]
/// #[catch_up]
/// pub async fn daily_cleanup(ctx: &CronContext) -> Result<()> {
/// // ...
/// }
/// ```
/// Marks a function as a durable workflow.
///
/// Workflows are multi-step processes that survive restarts and handle failures with compensation.
///
/// # Attributes
/// - `version = 1` - Workflow version (increment for breaking changes)
/// - `timeout = "24h"` - Maximum execution time
///
/// # Example
/// ```ignore
/// #[forgex::workflow]
/// #[version = 1]
/// pub async fn user_onboarding(ctx: &WorkflowContext, input: OnboardingInput) -> Result<OnboardingResult> {
/// let user = ctx.step("create_user", || async { /* ... */ }).await?;
/// ctx.step("send_welcome", || async { /* ... */ }).await;
/// Ok(OnboardingResult { user })
/// }
/// ```