Skip to main content

onlyne_store/
lib.rs

1//! SQLite persistence for Onlyne.
2//!
3//! ## Schema versus plan
4//!
5//! Every timestamp column in both databases is written by this crate's conversion helpers, `unix_to_rfc3339` and `rfc3339`, and no caller supplies a raw stored value: the kernel's `i64` seconds (`SessionWrite`, `ServerFaultRow`, `VersionedSession`, `FaultRecord`) convert at the write, and the one text input, `RoleRow::updated_at` from the server's `upsert_role` call sites, is re-encoded through the same helpers before the insert.
6//! The server `ledger.body_json` column is nullable because retention pruning clears acknowledged bodies after the cutoff.
7//! Extra indexes support ledger pulls, fault deduplication, due-intent ordering, and event-cursor scans.
8//! `schema_marker` records the v1.0.0 schema and protocol gate for each database.
9
10mod client;
11mod error;
12mod liveness;
13mod server;
14pub mod session;
15pub use client::{CLIENT_DDL, ClientStore, INTENT_FLUSH_BATCH_SIZE, IntentRow, TaskRow};
16pub use error::{StoreError, StoreResult};
17pub use server::{
18    Append, CursorRow, EventRecord, FaultQuery, GhostSweepRow, LedgerRow, RoleRow, SERVER_DDL,
19    ServerFaultRow, ServerLedger, ServerSessionRow, SessionBindingRow, SessionWrite, rfc3339,
20};
21pub use session::{FaultRecord, SessionLedger, SessionRecord, VersionedSession};
22
23pub use onlyne_proto::LedgerState;
24
25pub fn transition_allowed(from: LedgerState, to: LedgerState) -> bool {
26    matches!(
27        (from, to),
28        (LedgerState::Queued, LedgerState::InFlight)
29            | (LedgerState::Queued, LedgerState::Rejected)
30            | (LedgerState::Queued, LedgerState::Expired)
31            | (LedgerState::InFlight, LedgerState::Acked)
32            | (LedgerState::InFlight, LedgerState::Queued)
33            | (LedgerState::InFlight, LedgerState::Rejected)
34    )
35}