extract types

This commit is contained in:
Tao Tien 2026-02-07 17:46:03 -08:00
parent d7d567b0e6
commit c86f8d93f1
30 changed files with 986 additions and 474 deletions

View file

@ -6,23 +6,37 @@
#![allow(unused, clippy::all)]
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
pub mod add_reducer;
pub mod identity_connected_reducer;
pub mod identity_disconnected_reducer;
pub mod person_table;
pub mod person_type;
pub mod say_hello_reducer;
pub mod add_player_reducer;
pub mod dragon_type;
pub mod hand_table;
pub mod hand_type;
pub mod player_table;
pub mod player_type;
pub mod rank_type;
pub mod set_name_reducer;
pub mod shuffle_wall_reducer;
pub mod sort_hand_reducer;
pub mod suit_type;
pub mod tile_type;
pub mod wall_table;
pub mod wall_type;
pub mod wind_type;
pub use add_reducer::{add, set_flags_for_add, AddCallbackId};
pub use identity_connected_reducer::{
identity_connected, set_flags_for_identity_connected, IdentityConnectedCallbackId,
};
pub use identity_disconnected_reducer::{
identity_disconnected, set_flags_for_identity_disconnected, IdentityDisconnectedCallbackId,
};
pub use person_table::*;
pub use person_type::Person;
pub use say_hello_reducer::{say_hello, set_flags_for_say_hello, SayHelloCallbackId};
pub use add_player_reducer::{add_player, set_flags_for_add_player, AddPlayerCallbackId};
pub use dragon_type::Dragon;
pub use hand_table::*;
pub use hand_type::Hand;
pub use player_table::*;
pub use player_type::Player;
pub use rank_type::Rank;
pub use set_name_reducer::{set_flags_for_set_name, set_name, SetNameCallbackId};
pub use shuffle_wall_reducer::{set_flags_for_shuffle_wall, shuffle_wall, ShuffleWallCallbackId};
pub use sort_hand_reducer::{set_flags_for_sort_hand, sort_hand, SortHandCallbackId};
pub use suit_type::Suit;
pub use tile_type::Tile;
pub use wall_table::*;
pub use wall_type::Wall;
pub use wind_type::Wind;
#[derive(Clone, PartialEq, Debug)]
@ -32,10 +46,10 @@ pub use say_hello_reducer::{say_hello, set_flags_for_say_hello, SayHelloCallback
/// to indicate which reducer caused the event.
pub enum Reducer {
Add { name: String },
IdentityConnected,
IdentityDisconnected,
SayHello,
AddPlayer { name: Option<String> },
SetName { name: String },
ShuffleWall,
SortHand,
}
impl __sdk::InModule for Reducer {
@ -45,10 +59,10 @@ impl __sdk::InModule for Reducer {
impl __sdk::Reducer for Reducer {
fn reducer_name(&self) -> &'static str {
match self {
Reducer::Add { .. } => "add",
Reducer::IdentityConnected => "identity_connected",
Reducer::IdentityDisconnected => "identity_disconnected",
Reducer::SayHello => "say_hello",
Reducer::AddPlayer { .. } => "add_player",
Reducer::SetName { .. } => "set_name",
Reducer::ShuffleWall => "shuffle_wall",
Reducer::SortHand => "sort_hand",
_ => unreachable!(),
}
}
@ -57,20 +71,28 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer {
type Error = __sdk::Error;
fn try_from(value: __ws::ReducerCallInfo<__ws::BsatnFormat>) -> __sdk::Result<Self> {
match &value.reducer_name[..] {
"add" => {
Ok(__sdk::parse_reducer_args::<add_reducer::AddArgs>("add", &value.args)?.into())
}
"identity_connected" => Ok(__sdk::parse_reducer_args::<
identity_connected_reducer::IdentityConnectedArgs,
>("identity_connected", &value.args)?
"add_player" => Ok(
__sdk::parse_reducer_args::<add_player_reducer::AddPlayerArgs>(
"add_player",
&value.args,
)?
.into(),
),
"set_name" => Ok(__sdk::parse_reducer_args::<set_name_reducer::SetNameArgs>(
"set_name",
&value.args,
)?
.into()),
"identity_disconnected" => Ok(__sdk::parse_reducer_args::<
identity_disconnected_reducer::IdentityDisconnectedArgs,
>("identity_disconnected", &value.args)?
.into()),
"say_hello" => Ok(
__sdk::parse_reducer_args::<say_hello_reducer::SayHelloArgs>(
"say_hello",
"shuffle_wall" => Ok(
__sdk::parse_reducer_args::<shuffle_wall_reducer::ShuffleWallArgs>(
"shuffle_wall",
&value.args,
)?
.into(),
),
"sort_hand" => Ok(
__sdk::parse_reducer_args::<sort_hand_reducer::SortHandArgs>(
"sort_hand",
&value.args,
)?
.into(),
@ -89,7 +111,9 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer {
#[allow(non_snake_case)]
#[doc(hidden)]
pub struct DbUpdate {
person: __sdk::TableUpdate<Person>,
hand: __sdk::TableUpdate<Hand>,
player: __sdk::TableUpdate<Player>,
wall: __sdk::TableUpdate<Wall>,
}
impl TryFrom<__ws::DatabaseUpdate<__ws::BsatnFormat>> for DbUpdate {
@ -98,9 +122,15 @@ 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[..] {
"person" => db_update
.person
.append(person_table::parse_table_update(table_update)?),
"hand" => db_update
.hand
.append(hand_table::parse_table_update(table_update)?),
"player" => db_update
.player
.append(player_table::parse_table_update(table_update)?),
"wall" => db_update
.wall
.append(wall_table::parse_table_update(table_update)?),
unknown => {
return Err(__sdk::InternalError::unknown_name(
@ -127,7 +157,11 @@ impl __sdk::DbUpdate for DbUpdate {
) -> AppliedDiff<'_> {
let mut diff = AppliedDiff::default();
diff.person = cache.apply_diff_to_table::<Person>("person", &self.person);
diff.hand = cache.apply_diff_to_table::<Hand>("hand", &self.hand);
diff.player = cache
.apply_diff_to_table::<Player>("player", &self.player)
.with_updates_by_pk(|row| &row.identity);
diff.wall = cache.apply_diff_to_table::<Wall>("wall", &self.wall);
diff
}
@ -137,7 +171,9 @@ impl __sdk::DbUpdate for DbUpdate {
#[allow(non_snake_case)]
#[doc(hidden)]
pub struct AppliedDiff<'r> {
person: __sdk::TableAppliedDiff<'r, Person>,
hand: __sdk::TableAppliedDiff<'r, Hand>,
player: __sdk::TableAppliedDiff<'r, Player>,
wall: __sdk::TableAppliedDiff<'r, Wall>,
__unused: std::marker::PhantomData<&'r ()>,
}
@ -151,7 +187,9 @@ impl<'r> __sdk::AppliedDiff<'r> for AppliedDiff<'r> {
event: &EventContext,
callbacks: &mut __sdk::DbCallbacks<RemoteModule>,
) {
callbacks.invoke_table_row_callbacks::<Person>("person", &self.person, event);
callbacks.invoke_table_row_callbacks::<Hand>("hand", &self.hand, event);
callbacks.invoke_table_row_callbacks::<Player>("player", &self.player, event);
callbacks.invoke_table_row_callbacks::<Wall>("wall", &self.wall, event);
}
}
@ -871,6 +909,8 @@ impl __sdk::SpacetimeModule for RemoteModule {
type SubscriptionHandle = SubscriptionHandle;
fn register_tables(client_cache: &mut __sdk::ClientCache<Self>) {
person_table::register_table(client_cache);
hand_table::register_table(client_cache);
player_table::register_table(client_cache);
wall_table::register_table(client_cache);
}
}