use super::*;
#[derive(
Clone,
Copy,
Data,
Debug,
Default,
Deserialize,
Eq,
Hash,
New,
Ord,
PartialEq,
PartialOrd,
Serialize,
)]
pub struct OperationId {
#[get(type(copy))]
pub(crate) raw: u64,
}
#[derive(Clone, Data, Debug, Deserialize, New, PartialEq, Serialize)]
pub struct BusinessCommand {
pub(crate) entity_id: String,
pub(crate) command_name: String,
#[new(skip)]
#[serde(default)]
#[get(skip)]
pub(crate) expected_revision: Option<u64>,
#[new(skip)]
#[serde(default)]
pub(crate) idempotency_key: String,
#[new(skip)]
#[serde(default)]
#[get(type(copy))]
pub(crate) origin_generation: u64,
pub(crate) payload: Value,
}
#[derive(Clone, Data, Debug, Deserialize, New, PartialEq, Serialize)]
pub struct BusinessStateDelta {
pub(crate) entity_id: String,
#[get(type(copy))]
pub(crate) revision: u64,
#[get(type(copy))]
pub(crate) operation_id: OperationId,
pub(crate) changed_fields: Vec<String>,
pub(crate) state_patch: Value,
}
#[derive(Clone, Data, Debug, Deserialize, New, PartialEq, Serialize)]
pub struct InFlightOperation {
#[get(type(copy))]
pub(crate) operation_id: OperationId,
pub(crate) entity_id: String,
pub(crate) command_name: String,
pub(crate) idempotency_key: String,
#[get(type(copy))]
pub(crate) origin_generation: u64,
#[get(skip)]
pub(crate) expected_revision: Option<u64>,
#[get(type(copy))]
pub(crate) completed: bool,
}
#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
pub struct StateSubscription {
#[get(type(copy))]
pub(crate) subscription_id: u64,
pub(crate) entity_id: String,
#[get(type(copy))]
pub(crate) generation_id: u64,
pub(crate) watched_fields: Vec<String>,
#[new(skip)]
#[get(type(copy))]
pub(crate) active: bool,
#[new(skip)]
pub(crate) delivered_revisions: Vec<u64>,
}
#[derive(Clone, Debug)]
pub(crate) struct EntityStateRecord {
pub(crate) revision: u64,
pub(crate) state: Value,
pub(crate) deltas: VecDeque<BusinessStateDelta>,
}
#[derive(Debug)]
pub(crate) struct BusinessStateStoreInner {
pub(crate) delta_cap: usize,
pub(crate) next_op_id: u64,
pub(crate) next_sub_id: u64,
pub(crate) global_revision: u64,
pub(crate) entities: BTreeMap<String, EntityStateRecord>,
pub(crate) idempotency_cache: HashMap<(String, String), CommandOutcome>,
pub(crate) in_flight: BTreeMap<OperationId, InFlightOperation>,
pub(crate) subscriptions: BTreeMap<u64, StateSubscription>,
}
#[derive(Clone, Debug)]
pub struct BusinessStateStore {
pub(crate) inner: Arc<Mutex<BusinessStateStoreInner>>,
}
#[derive(
Clone, Data, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
)]
pub struct StableAddress {
pub(crate) route_instance: String,
pub(crate) ancestor_keys: Vec<String>,
pub(crate) slot_key: String,
#[get(skip)]
#[serde(default)]
pub(crate) child_key: Option<String>,
}
#[derive(Clone, Data, Debug, Default, Deserialize, New, PartialEq, Serialize)]
pub struct ComponentUiStateSnapshot {
pub(crate) address: StableAddress,
#[get(type(copy))]
pub(crate) schema_version: u32,
#[new(skip)]
#[serde(default)]
#[get(skip)]
pub(crate) scroll_anchor_key: Option<String>,
#[new(skip)]
#[serde(default)]
#[get(type(copy))]
pub(crate) scroll_offset_y: f32,
#[new(skip)]
#[serde(default)]
#[get(skip)]
pub(crate) focused_node_key: Option<String>,
#[new(skip)]
#[serde(default)]
pub(crate) form_draft: BTreeMap<String, String>,
#[new(skip)]
#[serde(default)]
pub(crate) local_data: Value,
}
#[derive(Clone, Data, Debug, Default, Deserialize, New, PartialEq, Serialize)]
pub struct NestedStateSnapshot {
pub(crate) route: String,
#[get(type(copy))]
pub(crate) base_generation: u64,
#[get(type(copy))]
pub(crate) business_revision: u64,
#[new(skip)]
#[serde(default)]
pub(crate) entity_snapshots: BTreeMap<String, (u64, Value)>,
#[new(skip)]
#[serde(default)]
pub(crate) ui_states: BTreeMap<String, ComponentUiStateSnapshot>,
}
#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
pub struct DefaultStateMigrator {
pub(crate) field_renames: BTreeMap<(u32, u32), BTreeMap<String, String>>,
pub(crate) default_additions: BTreeMap<(u32, u32), BTreeMap<String, String>>,
}
#[derive(Clone, Copy, Data, Debug, Eq, Hash, PartialEq)]
pub struct InteractionSafePoint {
#[get(type(copy))]
pub(crate) active_gesture: bool,
#[get(type(copy))]
pub(crate) ime_composing: bool,
#[get(type(copy))]
pub(crate) active_transition: bool,
#[get(type(copy))]
pub(crate) blocking_in_flight_tx: usize,
#[get(type(copy))]
pub(crate) frame_budget_remaining_us: u64,
}