Skip to main content

wire/answer/
history.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! The two answers that read the Ledger back: a slice of the one
7//! history, and one slice of a named range of it.
8
9use kernel::{EventRecord, Seq};
10use serde::{Deserialize, Serialize};
11
12/// A slice of the one history, oldest first - the order the ledger
13/// wrote them and the order a fold expects. A reader that wants the
14/// newest first reverses a list it already has, and a server that
15/// reversed it would make the fold the caller's problem.
16// No `Eq`: an `EventRecord` carries a payload whose numbers may be
17// floats, and the wire's other answers derive it only because none of
18// them holds one.
19#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
20#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
21pub struct HistoryAnswer {
22    pub records: Vec<EventRecord>,
23    /// Where to ask next to go further back. `None` means this slice
24    /// reaches the first record the city ever wrote.
25    pub earlier: Option<Seq>,
26}
27
28/// One slice of a named range of ledger records, and where the slice
29/// continues.
30///
31/// **The endpoints come back with the records.** The question that asked
32/// for them carried no cursor a caller holds on to - not a `before` to
33/// walk back from, but two seq numbers that may have arrived in a frame
34/// the caller has already dropped - so an answer that did not name its
35/// own slice could not be told from one for a different range, and a page
36/// filling a gap while its record view is open would file the wrong
37/// answer.
38// No `Eq`, for the reason `HistoryAnswer` gives: a record's payload is
39// arbitrary JSON.
40#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
41#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
42pub struct HistoryRangeAnswer {
43    /// The first sequence this slice could have held, echoed from the
44    /// question.
45    pub from: Seq,
46    /// The last sequence the question asked for, echoed. A `next` of
47    /// `None` says these records are everything the Ledger holds between
48    /// the two.
49    pub to: Seq,
50    pub records: Vec<EventRecord>,
51    /// The sequence to ask from to finish the range, or `None` when the
52    /// range is answered and there is nothing more to ask for.
53    pub next: Option<Seq>,
54}