vantage_live/live_stream/mod.rs
1//! Event source abstraction.
2//!
3//! `LiveTable` consumes [`LiveEvent`]s from anything that implements
4//! [`LiveStream`]. The most useful real-world implementor is SurrealDB's
5//! LIVE query (see `vantage-surrealdb`), but the trait is deliberately
6//! generic — Kafka, Postgres LISTEN/NOTIFY, Mongo change streams, or any
7//! ad-hoc event bus can drive a LiveTable.
8//!
9//! In v1 every event invalidates the entire `cache_key`, so the variant
10//! distinction is informational; we keep the per-id variants for forward
11//! compatibility with surgical invalidation.
12
13use futures_util::Stream;
14use std::pin::Pin;
15
16mod manual;
17
18pub use manual::ManualLiveStream;
19
20/// A single change event observed at the master. Variants are forward-
21/// compatible with future surgical invalidation.
22#[derive(Clone, Debug, PartialEq, Eq)]
23pub enum LiveEvent {
24 /// "Something moved." Use this when the source can't tell us which row
25 /// changed. v1 LiveTable behaves the same regardless of the variant.
26 Changed,
27 Inserted {
28 id: String,
29 },
30 Updated {
31 id: String,
32 },
33 Deleted {
34 id: String,
35 },
36}
37
38/// Source of [`LiveEvent`]s. Subscribers each get an independent stream.
39pub trait LiveStream: Send + Sync {
40 fn subscribe(&self) -> Pin<Box<dyn Stream<Item = LiveEvent> + Send>>;
41}