synwire_checkpoint/base.rs
1//! Core checkpoint saver trait.
2
3use synwire_core::BoxFuture;
4
5use crate::types::{
6 Checkpoint, CheckpointConfig, CheckpointError, CheckpointMetadata, CheckpointTuple,
7};
8
9/// Trait for persisting and retrieving graph checkpoints.
10///
11/// Implementations must be thread-safe (`Send + Sync`) and return
12/// boxed futures for async compatibility without the `async-trait` macro.
13pub trait BaseCheckpointSaver: Send + Sync {
14 /// Retrieve a single checkpoint tuple matching the given configuration.
15 ///
16 /// If `config.checkpoint_id` is `None`, returns the latest checkpoint
17 /// for the given thread. Returns `Ok(None)` if no matching checkpoint exists.
18 fn get_tuple<'a>(
19 &'a self,
20 config: &'a CheckpointConfig,
21 ) -> BoxFuture<'a, Result<Option<CheckpointTuple>, CheckpointError>>;
22
23 /// List checkpoint tuples for the given configuration.
24 ///
25 /// Returns checkpoints in reverse chronological order (newest first).
26 /// If `limit` is `Some(n)`, returns at most `n` results.
27 fn list<'a>(
28 &'a self,
29 config: &'a CheckpointConfig,
30 limit: Option<usize>,
31 ) -> BoxFuture<'a, Result<Vec<CheckpointTuple>, CheckpointError>>;
32
33 /// Persist a checkpoint with its metadata.
34 ///
35 /// Returns the updated `CheckpointConfig` with the assigned checkpoint ID.
36 fn put<'a>(
37 &'a self,
38 config: &'a CheckpointConfig,
39 checkpoint: Checkpoint,
40 metadata: CheckpointMetadata,
41 ) -> BoxFuture<'a, Result<CheckpointConfig, CheckpointError>>;
42}