greentic_session/
store.rs

1use greentic_types::{GResult, SessionData, SessionKey, TenantCtx, UserId};
2
3/// Persistent session storage interface used by Greentic runtimes.
4///
5/// `SessionData` captures the tenant context, flow identifier, cursor, and serialized execution
6/// state snapshot for an in-flight flow. Implementations store that payload so runners can pause
7/// execution, persist the snapshot, and resume the flow consistently after new input arrives.
8pub trait SessionStore: Send + Sync + 'static {
9    /// Creates a new session associated with the supplied tenant context and returns its key.
10    fn create_session(&self, ctx: &TenantCtx, data: SessionData) -> GResult<SessionKey>;
11
12    /// Fetches the session payload for the provided key, if it exists.
13    fn get_session(&self, key: &SessionKey) -> GResult<Option<SessionData>>;
14
15    /// Replaces the session payload for the provided key.
16    fn update_session(&self, key: &SessionKey, data: SessionData) -> GResult<()>;
17
18    /// Removes the session entry and clears any lookup indices.
19    fn remove_session(&self, key: &SessionKey) -> GResult<()>;
20
21    /// Finds the active session bound to the specified tenant + user combination.
22    fn find_by_user(
23        &self,
24        ctx: &TenantCtx,
25        user: &UserId,
26    ) -> GResult<Option<(SessionKey, SessionData)>>;
27}