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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
use TokenStream;
extern crate proc_macro;
/// Derives the Validate trait for data validation.
///
/// Generates validation logic based on `#[validate(...)]` attributes.
///
/// # Attributes
///
/// ## `#[validate(...)]`
/// - `delegate` - Delegate validation to the field's type (must implement `Validate`)
/// - `custom = "path"` - Call a custom validation function: `fn(&T) -> Result<(), ValidationReport>`
/// - String: `min_length`, `max_length`, `exact_length`, `pattern`
/// - String formats: `email`, `url`, `uuid`, `phone_e164`, `ipv4`, `ipv6`
/// - Numeric: `min`, `max`, `exclusive_min`, `exclusive_max`, `multiple_of`
/// - Array: `min_items`, `max_items`, `unique_items`
/// Defines a route handler with metadata for routing and OpenAPI documentation.
///
/// Can be applied to free functions or methods in impl blocks.
///
/// # Required Attributes
///
/// - `method` - HTTP method: `"get"`, `"post"`, `"put"`, `"patch"`, `"delete"`, `"head"`, `"options"`, or `"trace"`
/// - `url` - Path pattern with optional parameters in braces: `"/users/{id}"`
///
/// # Optional Attributes
///
/// - `tags` - Array of OpenAPI tags: `tags = ["users", "api"]`
/// - `name` - Route name for reverse routing (defaults to function name)
/// - `summary` - Short description for OpenAPI (defaults to first doc comment line)
/// - `description` - Detailed description for OpenAPI (defaults to remaining doc comments)
///
/// # Examples
///
/// ```ignore
/// // Free function
/// #[route(method = "get", url = "/users/{id}", tags = ["users"])]
/// async fn get_user(Path(id): Path<i32>) -> Json<User> {
/// // ...
/// }
///
/// // Method in impl block
/// impl UserApi {
/// #[route(method = "post", url = "/users", tags = ["users"])]
/// async fn create_user(Json(data): Json<CreateUser>) -> Json<User> {
/// // ...
/// }
/// }
/// ```
/// Collects bundle parts (routes, tasks, signals) into a Bundle for composition and registration.
///
/// Bundles are the primary unit for organizing and composing application components.
/// Each handler must be annotated with appropriate macros (`#[route]`, `#[cron]`, `#[periodic]`, etc.).
///
/// # Syntax
///
/// ```ignore
/// bundle! {
/// handler1,
/// handler2,
/// ...,
/// tags = ["tag1", "tag2"] // optional, applies only to routes
/// }
/// ```
///
/// # Options
///
/// - `tags` - Optional array of tags to apply to all routes in the bundle.
/// These tags extend (not replace) any tags defined on individual routes.
/// Note: tags only apply to route parts, not other bundle parts.
///
/// # Examples
///
/// ```ignore
/// // Bundle without tags
/// let user_bundle = bundle! {
/// get_user, // #[route]
/// create_user, // #[route]
/// sync_users, // #[cron]
/// };
///
/// // Bundle with tags - extends individual route tags
/// let api_bundle = bundle! {
/// tags = ["api", "v1"],
/// get_user,
/// create_user,
/// };
///
/// // Compose bundles
/// let all_bundles = bundle! {
/// user_bundle,
/// api_bundle,
/// };
/// ```
///
/// # Notes
///
/// - Handlers must be annotated with `#[route]`, `#[cron]`, `#[periodic]`, `#[pgnotify]`, or `#[signal]`
/// - Handlers can be free functions or references to IntoBundle types
/// - Tags are additive and only apply to route parts
/// - Returns a `Bundle` that implements `IntoBundle`
/// Derives the BitRole trait for role-based access control.
///
/// Automatically implements BitRole for enums with unit variants only.
/// Each variant is assigned a bit position (0, 1, 2, ...) for role masking.
///
/// # Requirements
/// - Only unit variants allowed (no tuple or struct variants)
/// - Explicit discriminants must be > 0
/// - Enum must derive Copy, Debug, and implement IntoEnumIterator (from strum)
///
/// # Example
/// ```ignore
/// #[derive(Debug, Copy, Clone, BitRole, EnumIter)]
/// enum UserRole {
/// Viewer = 1,
/// Editor = 2,
/// Admin = 3,
/// }
/// ```
/// Schedules a function to run periodically based on a cron expression.
///
/// Annotated functions will be registered as cron jobs in the bundle.
/// The function must accept a `Site` parameter and return a type that can be
/// wrapped in `SignalPayload`.
///
/// # Attributes
///
/// - `expr` - Cron expression (required): `"0 0 * * *"` (daily at midnight)
///
/// # Examples
///
/// ```ignore
/// // Free function
/// #[cron(expr = "0 0 * * *")]
/// fn sync_daily(site: Site) -> SyncResult {
/// // runs daily at midnight
/// }
///
/// // Method in impl block
/// impl SyncTasks {
/// #[cron(expr = "*/5 * * * *")]
/// fn sync_frequent(site: Site) -> SyncResult {
/// // runs every 5 minutes
/// }
/// }
/// ```
/// Schedules a function to run periodically at fixed intervals.
///
/// Annotated functions will be registered as periodic tasks in the bundle.
/// The function must accept a `Site` parameter and return a type that can be
/// wrapped in `SignalPayload`.
///
/// # Attributes
///
/// - `secs` - Interval in seconds (optional)
/// - `millis` - Interval in milliseconds (optional)
///
/// At least one of `secs` or `millis` must be specified. Both can be used together.
///
/// # Examples
///
/// ```ignore
/// // Free function - runs every 30 seconds
/// #[periodic(secs = 30)]
/// fn health_check(site: Site) -> CheckResult {
/// // ...
/// }
///
/// // Method - runs every 500ms
/// impl Monitor {
/// #[periodic(millis = 500)]
/// fn monitor_metrics(site: Site) -> Metrics {
/// // ...
/// }
/// }
///
/// // Combined - runs every 1.5 seconds
/// #[periodic(secs = 1, millis = 500)]
/// fn poll_queue(site: Site) -> QueueStatus {
/// // ...
/// }
/// ```
/// Registers a function as a PostgreSQL NOTIFY/LISTEN handler.
///
/// Annotated functions will listen for notifications on a PostgreSQL channel.
/// The function must accept a `&str` payload and return `Result<T, SignalError>`
/// where T can be wrapped in `SignalPayload`.
///
/// # Attributes
///
/// - `channel` - PostgreSQL channel name (required): `"user_updates"`
///
/// # Examples
///
/// ```ignore
/// // Free function
/// #[pgnotify(channel = "user_updates")]
/// fn handle_user_update(payload: &str) -> Result<UserUpdate, SignalError> {
/// serde_json::from_str(payload)
/// .map_err(|_| SignalError::PayloadTypeMismatch)
/// }
///
/// // Method in impl block
/// impl UserHandlers {
/// #[pgnotify(channel = "notifications")]
/// fn handle_notification(payload: &str) -> Result<Notification, SignalError> {
/// // parse and return notification
/// }
/// }
/// ```
/// Registers a function as a generic signal handler.
///
/// Annotated functions will be registered to handle any signal events.
/// The function must accept `Site` and `Arc<dyn Any + Send + Sync>` parameters
/// and return a Future.
///
/// # Examples
///
/// ```ignore
/// // Free function
/// #[signal]
/// async fn handle_signal(site: Site, payload: Arc<dyn Any + Send + Sync>) {
/// // handle generic signal
/// }
///
/// // Method in impl block
/// impl SignalHandlers {
/// #[signal]
/// async fn process_event(site: Site, payload: Arc<dyn Any + Send + Sync>) {
/// // process event
/// }
/// }
/// ```
/// Registers a function as a unit task handler.
///
/// Unit tasks are async operations that execute once and complete. The function
/// must accept `Site` and a deserializable input type, returning a TaskUnitOutput.
///
/// # Attributes
///
/// - `name` - Optional task name (defaults to function name)
///
/// # Examples
///
/// ```ignore
/// // Free function with default name
/// #[task]
/// async fn send_email(site: Site, input: EmailData) -> Result<TaskUnitOutput, TaskError> {
/// // send email
/// }
///
/// // Method with custom name
/// impl TaskHandlers {
/// #[task(name = "custom_task_name")]
/// async fn process_order(site: Site, order: Order) -> Result<TaskUnitOutput, TaskError> {
/// // process order
/// }
/// }
/// ```
/// Registers a function as a flow task handler.
///
/// Flow tasks are synchronous operations that can spawn child tasks. The function
/// accepts a deserializable input type and returns TaskFlowOutput.
///
/// # Attributes
///
/// - `name` - Optional task name (defaults to function name)
///
/// # Examples
///
/// ```ignore
/// // Free function with default name
/// #[flow]
/// fn process_batch(input: BatchData) -> Result<TaskFlowOutput, TaskError> {
/// // process and potentially spawn child tasks
/// }
///
/// // Method with custom name
/// impl FlowHandlers {
/// #[flow(name = "workflow_step")]
/// fn execute_workflow(data: WorkflowData) -> Result<TaskFlowOutput, TaskError> {
/// // execute workflow step
/// }
/// }
/// ```
// #[proc_macro_attribute]
// pub fn fnspec(attr: TokenStream, item: TokenStream) -> TokenStream {
// fnspec::parse_fnspec_input(attr, item, "fnspec")
// }