(stash) state advancer reducer

This commit is contained in:
Tao Tien 2026-02-20 03:20:29 -08:00
parent 1d9577ba42
commit c12667938e
9 changed files with 252 additions and 83 deletions

View file

@ -0,0 +1,144 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
#![allow(unused, clippy::all)]
use super::advance_state_timer_type::AdvanceStateTimer;
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
/// Table handle for the table `advance_state_timer`.
///
/// Obtain a handle from the [`AdvanceStateTimerTableAccess::advance_state_timer`] method on [`super::RemoteTables`],
/// like `ctx.db.advance_state_timer()`.
///
/// Users are encouraged not to explicitly reference this type,
/// but to directly chain method calls,
/// like `ctx.db.advance_state_timer().on_insert(...)`.
pub struct AdvanceStateTimerTableHandle<'ctx> {
imp: __sdk::TableHandle<AdvanceStateTimer>,
ctx: std::marker::PhantomData<&'ctx super::RemoteTables>,
}
#[allow(non_camel_case_types)]
/// Extension trait for access to the table `advance_state_timer`.
///
/// Implemented for [`super::RemoteTables`].
pub trait AdvanceStateTimerTableAccess {
#[allow(non_snake_case)]
/// Obtain a [`AdvanceStateTimerTableHandle`], which mediates access to the table `advance_state_timer`.
fn advance_state_timer(&self) -> AdvanceStateTimerTableHandle<'_>;
}
impl AdvanceStateTimerTableAccess for super::RemoteTables {
fn advance_state_timer(&self) -> AdvanceStateTimerTableHandle<'_> {
AdvanceStateTimerTableHandle {
imp: self
.imp
.get_table::<AdvanceStateTimer>("advance_state_timer"),
ctx: std::marker::PhantomData,
}
}
}
pub struct AdvanceStateTimerInsertCallbackId(__sdk::CallbackId);
pub struct AdvanceStateTimerDeleteCallbackId(__sdk::CallbackId);
impl<'ctx> __sdk::Table for AdvanceStateTimerTableHandle<'ctx> {
type Row = AdvanceStateTimer;
type EventContext = super::EventContext;
fn count(&self) -> u64 {
self.imp.count()
}
fn iter(&self) -> impl Iterator<Item = AdvanceStateTimer> + '_ {
self.imp.iter()
}
type InsertCallbackId = AdvanceStateTimerInsertCallbackId;
fn on_insert(
&self,
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
) -> AdvanceStateTimerInsertCallbackId {
AdvanceStateTimerInsertCallbackId(self.imp.on_insert(Box::new(callback)))
}
fn remove_on_insert(&self, callback: AdvanceStateTimerInsertCallbackId) {
self.imp.remove_on_insert(callback.0)
}
type DeleteCallbackId = AdvanceStateTimerDeleteCallbackId;
fn on_delete(
&self,
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
) -> AdvanceStateTimerDeleteCallbackId {
AdvanceStateTimerDeleteCallbackId(self.imp.on_delete(Box::new(callback)))
}
fn remove_on_delete(&self, callback: AdvanceStateTimerDeleteCallbackId) {
self.imp.remove_on_delete(callback.0)
}
}
#[doc(hidden)]
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
let _table = client_cache.get_or_make_table::<AdvanceStateTimer>("advance_state_timer");
_table.add_unique_constraint::<u64>("scheduled_id", |row| &row.scheduled_id);
}
pub struct AdvanceStateTimerUpdateCallbackId(__sdk::CallbackId);
impl<'ctx> __sdk::TableWithPrimaryKey for AdvanceStateTimerTableHandle<'ctx> {
type UpdateCallbackId = AdvanceStateTimerUpdateCallbackId;
fn on_update(
&self,
callback: impl FnMut(&Self::EventContext, &Self::Row, &Self::Row) + Send + 'static,
) -> AdvanceStateTimerUpdateCallbackId {
AdvanceStateTimerUpdateCallbackId(self.imp.on_update(Box::new(callback)))
}
fn remove_on_update(&self, callback: AdvanceStateTimerUpdateCallbackId) {
self.imp.remove_on_update(callback.0)
}
}
#[doc(hidden)]
pub(super) fn parse_table_update(
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
) -> __sdk::Result<__sdk::TableUpdate<AdvanceStateTimer>> {
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
__sdk::InternalError::failed_parse("TableUpdate<AdvanceStateTimer>", "TableUpdate")
.with_cause(e)
.into()
})
}
/// Access to the `scheduled_id` unique index on the table `advance_state_timer`,
/// which allows point queries on the field of the same name
/// via the [`AdvanceStateTimerScheduledIdUnique::find`] method.
///
/// Users are encouraged not to explicitly reference this type,
/// but to directly chain method calls,
/// like `ctx.db.advance_state_timer().scheduled_id().find(...)`.
pub struct AdvanceStateTimerScheduledIdUnique<'ctx> {
imp: __sdk::UniqueConstraintHandle<AdvanceStateTimer, u64>,
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
}
impl<'ctx> AdvanceStateTimerTableHandle<'ctx> {
/// Get a handle on the `scheduled_id` unique index on the table `advance_state_timer`.
pub fn scheduled_id(&self) -> AdvanceStateTimerScheduledIdUnique<'ctx> {
AdvanceStateTimerScheduledIdUnique {
imp: self.imp.get_unique_constraint::<u64>("scheduled_id"),
phantom: std::marker::PhantomData,
}
}
}
impl<'ctx> AdvanceStateTimerScheduledIdUnique<'ctx> {
/// Find the subscribed row whose `scheduled_id` column value is equal to `col_val`,
/// if such a row is present in the client cache.
pub fn find(&self, col_val: &u64) -> Option<AdvanceStateTimer> {
self.imp.find(col_val)
}
}

View file

@ -0,0 +1,17 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
#![allow(unused, clippy::all)]
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
pub struct AdvanceStateTimer {
pub scheduled_id: u64,
pub scheduled_at: __sdk::ScheduleAt,
pub lobby_id: u32,
}
impl __sdk::InModule for AdvanceStateTimer {
type Module = super::RemoteModule;
}

View file

@ -7,6 +7,8 @@
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
pub mod add_bot_reducer;
pub mod advance_state_timer_table;
pub mod advance_state_timer_type;
pub mod bot_table;
pub mod bot_type;
pub mod clear_all_reducer;
@ -36,6 +38,8 @@ pub mod wall_table;
pub mod wind_type;
pub use add_bot_reducer::{add_bot, set_flags_for_add_bot, AddBotCallbackId};
pub use advance_state_timer_table::*;
pub use advance_state_timer_type::AdvanceStateTimer;
pub use bot_table::*;
pub use bot_type::Bot;
pub use clear_all_reducer::{clear_all, set_flags_for_clear_all, ClearAllCallbackId};
@ -189,6 +193,7 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer {
#[allow(non_snake_case)]
#[doc(hidden)]
pub struct DbUpdate {
advance_state_timer: __sdk::TableUpdate<AdvanceStateTimer>,
bot: __sdk::TableUpdate<Bot>,
lobby: __sdk::TableUpdate<Lobby>,
player: __sdk::TableUpdate<Player>,
@ -202,6 +207,9 @@ impl TryFrom<__ws::DatabaseUpdate<__ws::BsatnFormat>> for DbUpdate {
let mut db_update = DbUpdate::default();
for table_update in raw.tables {
match &table_update.table_name[..] {
"advance_state_timer" => db_update
.advance_state_timer
.append(advance_state_timer_table::parse_table_update(table_update)?),
"bot" => db_update
.bot
.append(bot_table::parse_table_update(table_update)?),
@ -243,6 +251,12 @@ impl __sdk::DbUpdate for DbUpdate {
) -> AppliedDiff<'_> {
let mut diff = AppliedDiff::default();
diff.advance_state_timer = cache
.apply_diff_to_table::<AdvanceStateTimer>(
"advance_state_timer",
&self.advance_state_timer,
)
.with_updates_by_pk(|row| &row.scheduled_id);
diff.bot = cache
.apply_diff_to_table::<Bot>("bot", &self.bot)
.with_updates_by_pk(|row| &row.id);
@ -267,6 +281,7 @@ impl __sdk::DbUpdate for DbUpdate {
#[allow(non_snake_case)]
#[doc(hidden)]
pub struct AppliedDiff<'r> {
advance_state_timer: __sdk::TableAppliedDiff<'r, AdvanceStateTimer>,
bot: __sdk::TableAppliedDiff<'r, Bot>,
lobby: __sdk::TableAppliedDiff<'r, Lobby>,
player: __sdk::TableAppliedDiff<'r, Player>,
@ -285,6 +300,11 @@ impl<'r> __sdk::AppliedDiff<'r> for AppliedDiff<'r> {
event: &EventContext,
callbacks: &mut __sdk::DbCallbacks<RemoteModule>,
) {
callbacks.invoke_table_row_callbacks::<AdvanceStateTimer>(
"advance_state_timer",
&self.advance_state_timer,
event,
);
callbacks.invoke_table_row_callbacks::<Bot>("bot", &self.bot, event);
callbacks.invoke_table_row_callbacks::<Lobby>("lobby", &self.lobby, event);
callbacks.invoke_table_row_callbacks::<Player>("player", &self.player, event);
@ -1009,6 +1029,7 @@ impl __sdk::SpacetimeModule for RemoteModule {
type SubscriptionHandle = SubscriptionHandle;
fn register_tables(client_cache: &mut __sdk::ClientCache<Self>) {
advance_state_timer_table::register_table(client_cache);
bot_table::register_table(client_cache);
lobby_table::register_table(client_cache);
player_table::register_table(client_cache);