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
//! # `ToolKit` - Declarative Gear System
//!
//! A unified crate for building modular applications with declarative gear definitions.
//!
//! ## Features
//!
//! - **Declarative**: Use `#[gear(...)]` attribute to declare gears
//! - **Auto-discovery**: Gears are automatically discovered via inventory
//! - **Type-safe**: Compile-time validation of capabilities
//! - **Phase-based lifecycle**: executed by `HostRuntime` (see `runtime/host_runtime.rs` docs)
//!
//! ## Golden Path: Stateless Handlers
//!
//! For optimal performance and readability, prefer stateless handlers that receive
//! `Extension<T>` and other extractors rather than closures that capture environment.
//!
//! ### Recommended Pattern
//!
//! ```rust,ignore
//! use axum::{Extension, Json};
//! use toolkit::api::{OperationBuilder, Problem};
//! use std::sync::Arc;
//!
//! async fn list_users(
//! Extension(svc): Extension<Arc<UserService>>,
//! ) -> Result<Json<Vec<UserDto>>, Problem> {
//! let users = svc.list_users().await.map_err(Problem::from)?;
//! Ok(Json(users))
//! }
//!
//! pub fn router(service: Arc<UserService>) -> axum::Router {
//! let op = OperationBuilder::get("/users-info/v1/users")
//! .summary("List users")
//! .handler(list_users)
//! .json_response(200, "List of users")
//! .standard_errors(®istry);
//!
//! axum::Router::new()
//! .route("/users-info/v1/users", axum::routing::get(list_users))
//! .layer(Extension(service))
//! .layer(op.to_layer())
//! }
//! ```
//!
//! ### Benefits
//!
//! - **Performance**: No closure captures or cloning on each request
//! - **Readability**: Clear function signatures show exactly what data is needed
//! - **Testability**: Easy to unit test handlers with mock state
//! - **Type Safety**: Compile-time verification of dependencies
//! - **Flexibility**: Individual service injection without coupling
//!
//! ## Basic Gear Example
//!
//! ```rust,ignore
//! use toolkit::{gear, Gear, DbGear, RestfulGear, StatefulGear};
//!
//! #[derive(Default)]
//! #[gear(name = "user", deps = ["database"], capabilities = [db, rest, stateful])]
//! pub struct UserGear;
//!
//! // Implement the declared capabilities...
//! ```
// When running tests, make ::toolkit resolve to this crate so macros work
extern crate self as toolkit;
pub use Result;
pub use async_trait;
// Re-export inventory for user convenience
pub use inventory;
// Gear system exports
pub use crate*;
pub use crate;
// Configuration gear
pub use ;
// Context gear
pub use ;
// Gear system implementations for macro code
// Re-export main types
pub use ClientHub;
pub use GearRegistry;
// Re-export the macros from the proc-macro crate
pub use ;
// Re-export var_expand gear so derive-generated impls resolve via ::toolkit::var_expand
pub use var_expand;
// Core gear contracts and traits
// Type-safe API operation builder
pub use ;
pub use ;
// HTTP utilities
pub use SseBroadcaster;
// Telemetry utilities
// Domain layer marker traits for DDD enforcement
pub use ;
// Directory API for service discovery
pub use ;
// GTS schema support
// Security context scoping wrapper (re-exported from toolkit-sdk)
pub use ;
pub use ;
pub use ;
pub use GtsPluginSelector;
pub use ;