durable_streams_server/transfer/format.rs
1//! Serialisable types for the durable-streams export/import JSON format.
2//!
3//! The top-level [`ExportDocument`] wraps a versioned envelope around a list
4//! of [`ExportedStream`] entries, each containing stream metadata and the
5//! full message payload (base64-encoded for binary safety).
6
7use crate::storage::StreamConfig;
8use chrono::{DateTime, Utc};
9use serde::{Deserialize, Serialize};
10
11/// Current format version written by [`super::export::export_streams`].
12pub const FORMAT_VERSION: u32 = 1;
13
14/// Top-level envelope for an export/import JSON file.
15///
16/// The `format_version` field enables forward-compatible schema evolution:
17/// readers reject versions they do not understand.
18#[derive(Debug, Serialize, Deserialize)]
19pub struct ExportDocument {
20 /// Schema version (currently [`FORMAT_VERSION`]).
21 pub format_version: u32,
22 /// Timestamp when the export was created.
23 pub exported_at: DateTime<Utc>,
24 /// Server crate version that produced the export.
25 pub server_version: String,
26 /// Exported streams with their messages.
27 pub streams: Vec<ExportedStream>,
28}
29
30/// A single stream and all its messages within an [`ExportDocument`].
31#[derive(Debug, Serialize, Deserialize)]
32pub struct ExportedStream {
33 /// Stream name (path-style, e.g. `"events/clicks"`).
34 pub name: String,
35 /// Immutable configuration captured at create time.
36 pub config: StreamConfig,
37 /// Whether the stream was closed at export time.
38 pub closed: bool,
39 /// When the stream was originally created.
40 pub created_at: DateTime<Utc>,
41 /// When the stream was last modified (`None` for legacy data).
42 #[serde(default)]
43 pub updated_at: Option<DateTime<Utc>>,
44 /// Total payload bytes across all messages.
45 pub total_bytes: u64,
46 /// Number of messages in the stream.
47 pub message_count: u64,
48 /// Canonical next-offset string for reference; import generates fresh
49 /// offsets so this is informational only.
50 pub next_offset: String,
51 /// Ordered list of messages with base64-encoded payloads.
52 pub messages: Vec<ExportedMessage>,
53}
54
55/// A single message within an [`ExportedStream`].
56#[derive(Debug, Serialize, Deserialize)]
57pub struct ExportedMessage {
58 /// Original offset at export time (informational; import assigns new offsets).
59 pub offset: String,
60 /// Standard base64-encoded message payload.
61 pub data_base64: String,
62}