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
use ;
// ---------------------------------------------------------------------------
// Lifecycle hooks
// ---------------------------------------------------------------------------
/// A lifecycle hook contract — a named callback slot registered on the service owner.
///
/// The host-language surface generated from this entry is an `app.on_<name>(fn)` style
/// registration method (or its language-idiomatic equivalent) that binds a user-supplied
/// callback into the request-processing pipeline.
///
/// Backends emit the hook registration method alongside the service entrypoints; the
/// generated wrapper stores the callback and the native layer invokes it at the
/// appropriate pipeline phase.
///
/// # alef.toml example
///
/// ```toml
/// [[crates.lifecycle_hooks]]
/// name = "on_request"
/// callback_contract = "RequestHook"
/// doc = "Called before any other processing for each inbound request."
///
/// [[crates.lifecycle_hooks]]
/// name = "on_error"
/// callback_contract = "ErrorHook"
/// doc = "Called when a handler returns an error."
/// ```
// ---------------------------------------------------------------------------
// WebSocket / SSE first-class contracts
// ---------------------------------------------------------------------------
/// A WebSocket route registration contract.
///
/// Backends generate an `app.websocket(path, handler_fn)` method (or its idiomatic
/// equivalent) from this entry. Because `WebSocketHandler` uses `impl Future` return
/// types that are not object-safe, the IR uses a concrete wrapper struct name
/// (`handler_wrapper_type`) instead of a trait object so backends can emit a concrete
/// monomorphisation rather than an `Arc<dyn Trait>` bridge.
///
/// # alef.toml example
///
/// ```toml
/// [[crates.websocket_routes]]
/// handler_wrapper_type = "WebSocketHandlerWrapper"
/// socket_type = "WebSocketConnection"
/// doc = "Register a WebSocket upgrade handler at the given path."
/// ```
/// An SSE (Server-Sent Events) route registration contract.
///
/// Backends generate an `app.sse(path, producer_fn)` method (or its idiomatic
/// equivalent) from this entry. Like WebSocket handlers, SSE producers use RPITIT
/// return types (`impl AsyncIterator`) that are not object-safe; the IR names the
/// concrete wrapper type so backends emit a concrete monomorphisation.
///
/// # alef.toml example
///
/// ```toml
/// [[crates.sse_routes]]
/// producer_wrapper_type = "SseProducerWrapper"
/// event_type = "SseEvent"
/// doc = "Register an SSE event producer at the given path."
/// ```
// ---------------------------------------------------------------------------
// Cross-binding error types
// ---------------------------------------------------------------------------
/// HTTP status code classification for a [`ErrorTypeDef`].
///
/// Each variant maps to one of the most common HTTP error codes and carries the
/// corresponding numeric code for backends that need to emit a `status_code()` method.
/// A cross-binding error type emitted as a native exception class in every language.
///
/// Each entry describes one member of the exception hierarchy that every backend must
/// emit. Backends produce native exception/error classes whose `status_code()` method
/// returns [`ErrorTypeDef::http_status`] and whose serialization produces an RFC 9457
/// ProblemDetails JSON body.
///
/// # alef.toml example
///
/// ```toml
/// [[crates.error_types]]
/// name = "NotFoundError"
/// http_status = "not_found"
/// doc = "Raised when the requested resource does not exist."
///
/// [[crates.error_types]]
/// name = "ValidationError"
/// http_status = "unprocessable_entity"
/// problem_details_type = "https://example.com/problems/validation"
/// doc = "Raised when input validation fails. Carries a list of field errors."
/// ```