Skip to main content

gonzalo_proto/
http.rs

1//! JSON DTOs shared by the HTTP/JSON transport (server handlers and the
2//! reqwest client). The gRPC transport carries the same `gonzalo-core` types
3//! as JSON bytes, so both transports agree on serialization.
4
5use gonzalo_core::{Conflict, Identity, Record, Revision};
6use serde::{Deserialize, Serialize};
7
8/// Body of `PUT /v1/records/{ns}/{col}/{id}`.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct PutBody {
11    pub record: Record,
12    pub expected: Option<Revision>,
13}
14
15/// Response of a PUT: mirrors `gonzalo_core::PutResult` on the wire.
16#[derive(Debug, Clone, Serialize, Deserialize)]
17#[serde(tag = "outcome", rename_all = "snake_case")]
18pub enum PutOutcome {
19    Committed { revision: Revision },
20    Conflict { conflict: Box<Conflict> },
21}
22
23/// Body of `DELETE /v1/records/{ns}/{col}/{id}`. The key is addressed by the
24/// URL path; the body carries the OCC precondition and, optionally, a claimed
25/// deleter identity.
26#[derive(Debug, Clone, Default, Serialize, Deserialize)]
27pub struct DeleteBody {
28    pub expected: Option<Revision>,
29    /// The deleter a replicating or admin client names (gonzalo#203). The daemon
30    /// honours it only for an admin or open mode; a non-admin is always stamped
31    /// as itself (`Principal::delete_author`).
32    #[serde(default, skip_serializing_if = "Option::is_none")]
33    pub author: Option<Identity>,
34}
35
36/// Response of a DELETE: mirrors `gonzalo_core::DeleteResult` on the wire.
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(tag = "outcome", rename_all = "snake_case")]
39pub enum DeleteOutcome {
40    Deleted,
41    Conflict { conflict: Box<Conflict> },
42}
43
44/// Response of `GET /v1/raw/records/{ns}/{col}/{id}` (gonzalo#203). Absence is
45/// `200 {"record": null}`, never `404`: a `404` from this route means the
46/// daemon predates replication reads, and the client must tell the two apart
47/// without guessing. `PUT` on the same path takes a [`PutBody`] and answers a
48/// [`PutOutcome`].
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct RawRecordBody {
51    pub record: Option<Record>,
52}
53
54/// Body of `POST /v1/purge/{ns}/{col}/{id}` (gonzalo#203). The key is addressed
55/// by the URL path. `expected` is required, because purge is always conditional
56/// on the current revision. The response is a [`DeleteOutcome`].
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct PurgeBody {
59    pub expected: Revision,
60}