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
//! Core crate for the cinderblock framework — a declarative, resource-oriented
//! application framework for Rust.
//!
//! This crate provides the [`resource!`] macro, the [`Resource`] trait, CRUD
//! operation traits ([`Create`], [`Update`], [`Destroy`], [`ReadAction`]), the
//! runtime [`Context`], and a built-in [`InMemoryDataLayer`](data_layer::in_memory::InMemoryDataLayer)
//! for prototyping.
//!
//! # The `resource!` macro
//!
//! The [`resource!`] macro is the primary entry point for defining domain
//! models. It accepts a declarative DSL and generates:
//!
//! - A **struct** with the declared attributes (derives `Serialize`,
//! `Deserialize`, `Clone`, `Debug`).
//! - A [`Resource`] trait impl with primary key metadata and the configured
//! data layer.
//! - For each action, a **marker struct** and the corresponding CRUD trait
//! impl. Create and update actions also generate an **input struct**.
//! - Extension dispatch — each declared extension receives the full DSL
//! tokens so it can generate its own code (e.g. route handlers, SQL
//! queries).
//!
//! ## DSL reference
//!
//! ```rust,ignore
//! use cinderblock_core::resource;
//!
//! resource! {
//! // A dotted name identifying the resource. The last segment becomes the
//! // struct name; all segments are available at runtime via `Resource::NAME`.
//! name = Helpdesk.Support.Ticket;
//!
//! // Optional: override the data layer. Defaults to `InMemoryDataLayer`.
//! // data_layer = cinderblock_sqlx::sqlite::SqliteDataLayer;
//!
//! attributes {
//! // Each attribute is `name Type` followed by either `;` or an options block.
//! ticket_id Uuid {
//! primary_key true; // Marks this as the primary key (default: false).
//! writable false; // Excludes from create/update input structs (default: true).
//! generated true; // Indicates the PK is auto-generated (default: false).
//! default || Uuid::new_v4(); // Closure producing a default value.
//! }
//!
//! // Simple form — writable, not a primary key, no default.
//! subject String;
//! status TicketStatus;
//! }
//!
//! actions {
//! // ── Read actions ──
//! //
//! // A read action returns `Vec<Resource>`. It can optionally declare
//! // arguments (typed query parameters) and filters.
//!
//! // Minimal read — no filters, no arguments. Arguments type is `()`.
//! read all;
//!
//! // Read with a compile-time literal filter.
//! read open_tickets {
//! filter { status == TicketStatus::Open };
//! };
//!
//! // Read with a runtime argument bound to a filter.
//! // Generates a `ByStatusArguments` struct with a `status` field.
//! read by_status {
//! argument { status: TicketStatus };
//! filter { status == arg(status) };
//! };
//!
//! // Optional arguments use `Option<T>`. When `None`, the filter is
//! // skipped entirely at runtime.
//! read search {
//! argument { status: Option<TicketStatus> };
//! filter { status == arg(status) };
//! };
//!
//! // ── Create actions ──
//! //
//! // A create action generates an input struct from the resource's
//! // writable attributes and a `Create<A>` impl that builds a new
//! // resource instance.
//!
//! // Accepts all writable attributes. Generates `OpenInput { subject, status }`.
//! create open;
//!
//! // Restrict which fields the input struct includes.
//! // Generates `AssignInput { subject }`.
//! create assign {
//! accept [subject];
//! };
//!
//! // ── Update actions ──
//! //
//! // An update action fetches the resource by primary key, applies
//! // changes, and persists the result. It generates an input struct
//! // and an `Update<A>` impl.
//!
//! // Accepts all writable attributes.
//! update edit;
//!
//! // Accept no fields from the caller, but apply a programmatic
//! // mutation via `change_ref`. Multiple `change_ref` blocks are
//! // applied in order.
//! update close {
//! accept [];
//! change_ref |ticket| {
//! ticket.status = TicketStatus::Closed;
//! };
//! };
//!
//! // ── Destroy actions ──
//! //
//! // A destroy action deletes the resource by primary key.
//! destroy remove;
//! }
//!
//! // Optional: declare extensions. Each extension module receives the
//! // full resource DSL and its own configuration block, then generates
//! // additional code (e.g. route handlers, SQL queries).
//! extensions {
//! cinderblock_json_api {
//! route = { method = GET; path = "/"; action = all; };
//! route = { method = POST; path = "/"; action = open; };
//! };
//!
//! cinderblock_sqlx {
//! table = "tickets";
//! };
//! }
//! }
//! ```
//!
//! ## Generated items
//!
//! For a resource named `Helpdesk.Support.Ticket` with actions `open`
//! (create), `close` (update), `open_tickets` (read), and `remove` (destroy),
//! the macro generates:
//!
//! | Generated item | Kind | Description |
//! |---|---|---|
//! | `Ticket` | struct | The resource struct with all declared attributes |
//! | `Open` | struct (marker) | Create action marker |
//! | `OpenInput` | struct | Input fields for the `open` create action |
//! | `Close` | struct (marker) | Update action marker |
//! | `CloseInput` | struct | Input fields for the `close` update action |
//! | `OpenTickets` | struct (marker) | Read action marker |
//! | `Remove` | struct (marker) | Destroy action marker |
//!
//! Action names are converted to `PascalCase` for the marker and input struct
//! names (e.g. `open_tickets` becomes `OpenTickets`, and its input struct
//! would be `OpenTicketsInput`).
//!
//! ## Using the generated types
//!
//! ```rust,ignore
//! use cinderblock_core::Context;
//!
//! let ctx = Context::new();
//!
//! // Create
//! let ticket = cinderblock_core::create::<Ticket, Open>(
//! OpenInput { subject: "Printer is broken".into(), status: TicketStatus::Open },
//! &ctx,
//! ).await?;
//!
//! // Read (with arguments)
//! let open = cinderblock_core::read::<Ticket, ByStatus>(
//! &ctx,
//! &ByStatusArguments { status: TicketStatus::Open },
//! ).await?;
//!
//! // Read (no arguments — pass `&()`)
//! let all_open = cinderblock_core::read::<Ticket, OpenTickets>(&ctx, &()).await?;
//!
//! // Update
//! let closed = cinderblock_core::update::<Ticket, Close>(
//! &ticket.ticket_id,
//! CloseInput {},
//! &ctx,
//! ).await?;
//!
//! // Destroy
//! let removed = cinderblock_core::destroy::<Ticket, Remove>(
//! &ticket.ticket_id,
//! &ctx,
//! ).await?;
//! ```
use ;
pub use resource;
pub use serde;
use crateDataLayer;
pub type Result<T, E = > = Result;
/// Marker trait for a resource.
/// Marker trait showing indicating that a struct is a read action.
/// Trait indicating that a [`DataLayer`] can perform [`ReadAction`] `A`.
/// Trait placed on a [`Resource`] specifying how to create the resource using action `A`.
/// Trait placed on a [`Resource`] specifying how to update a resource using action `A`.
/// Marker trait for destroy actions.
/// Create resource `R` using action `A`.
pub async
/// Update resource `R` using action `A`. First
/// fetches an instance of `R` using the primary key.
pub async
/// Read resource `R` using action `A`.
pub async
/// Destroy resource `R` using action `A`.
pub async