Persist auth store into formal tables

This commit is contained in:
2026-05-13 23:24:32 +08:00
parent e8648e45fc
commit 166544fae6
14 changed files with 452 additions and 32 deletions

View File

@@ -57,6 +57,29 @@ impl SpacetimeClient {
.await
}
pub async fn import_auth_store_snapshot_json(
&self,
snapshot_json: String,
updated_at_micros: i64,
) -> Result<AuthStoreSnapshotImportRecord, SpacetimeClientError> {
let procedure_input = AuthStoreSnapshotUpsertInput {
snapshot_json,
updated_at_micros,
};
self.call_after_connect(move |connection, sender| {
connection
.procedures()
.import_auth_store_snapshot_json_then(procedure_input, move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(map_auth_store_snapshot_import_procedure_result);
send_once(&sender, mapped);
});
})
.await
}
pub async fn import_auth_store_snapshot(
&self,
) -> Result<AuthStoreSnapshotImportRecord, SpacetimeClientError> {

View File

@@ -0,0 +1,162 @@
// 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::auth_store_projection_meta_type::AuthStoreProjectionMeta;
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
/// Table handle for the table `auth_store_projection_meta`.
///
/// Obtain a handle from the [`AuthStoreProjectionMetaTableAccess::auth_store_projection_meta`] method on [`super::RemoteTables`],
/// like `ctx.db.auth_store_projection_meta()`.
///
/// Users are encouraged not to explicitly reference this type,
/// but to directly chain method calls,
/// like `ctx.db.auth_store_projection_meta().on_insert(...)`.
pub struct AuthStoreProjectionMetaTableHandle<'ctx> {
imp: __sdk::TableHandle<AuthStoreProjectionMeta>,
ctx: std::marker::PhantomData<&'ctx super::RemoteTables>,
}
#[allow(non_camel_case_types)]
/// Extension trait for access to the table `auth_store_projection_meta`.
///
/// Implemented for [`super::RemoteTables`].
pub trait AuthStoreProjectionMetaTableAccess {
#[allow(non_snake_case)]
/// Obtain a [`AuthStoreProjectionMetaTableHandle`], which mediates access to the table `auth_store_projection_meta`.
fn auth_store_projection_meta(&self) -> AuthStoreProjectionMetaTableHandle<'_>;
}
impl AuthStoreProjectionMetaTableAccess for super::RemoteTables {
fn auth_store_projection_meta(&self) -> AuthStoreProjectionMetaTableHandle<'_> {
AuthStoreProjectionMetaTableHandle {
imp: self
.imp
.get_table::<AuthStoreProjectionMeta>("auth_store_projection_meta"),
ctx: std::marker::PhantomData,
}
}
}
pub struct AuthStoreProjectionMetaInsertCallbackId(__sdk::CallbackId);
pub struct AuthStoreProjectionMetaDeleteCallbackId(__sdk::CallbackId);
impl<'ctx> __sdk::Table for AuthStoreProjectionMetaTableHandle<'ctx> {
type Row = AuthStoreProjectionMeta;
type EventContext = super::EventContext;
fn count(&self) -> u64 {
self.imp.count()
}
fn iter(&self) -> impl Iterator<Item = AuthStoreProjectionMeta> + '_ {
self.imp.iter()
}
type InsertCallbackId = AuthStoreProjectionMetaInsertCallbackId;
fn on_insert(
&self,
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
) -> AuthStoreProjectionMetaInsertCallbackId {
AuthStoreProjectionMetaInsertCallbackId(self.imp.on_insert(Box::new(callback)))
}
fn remove_on_insert(&self, callback: AuthStoreProjectionMetaInsertCallbackId) {
self.imp.remove_on_insert(callback.0)
}
type DeleteCallbackId = AuthStoreProjectionMetaDeleteCallbackId;
fn on_delete(
&self,
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
) -> AuthStoreProjectionMetaDeleteCallbackId {
AuthStoreProjectionMetaDeleteCallbackId(self.imp.on_delete(Box::new(callback)))
}
fn remove_on_delete(&self, callback: AuthStoreProjectionMetaDeleteCallbackId) {
self.imp.remove_on_delete(callback.0)
}
}
pub struct AuthStoreProjectionMetaUpdateCallbackId(__sdk::CallbackId);
impl<'ctx> __sdk::TableWithPrimaryKey for AuthStoreProjectionMetaTableHandle<'ctx> {
type UpdateCallbackId = AuthStoreProjectionMetaUpdateCallbackId;
fn on_update(
&self,
callback: impl FnMut(&Self::EventContext, &Self::Row, &Self::Row) + Send + 'static,
) -> AuthStoreProjectionMetaUpdateCallbackId {
AuthStoreProjectionMetaUpdateCallbackId(self.imp.on_update(Box::new(callback)))
}
fn remove_on_update(&self, callback: AuthStoreProjectionMetaUpdateCallbackId) {
self.imp.remove_on_update(callback.0)
}
}
/// Access to the `meta_id` unique index on the table `auth_store_projection_meta`,
/// which allows point queries on the field of the same name
/// via the [`AuthStoreProjectionMetaMetaIdUnique::find`] method.
///
/// Users are encouraged not to explicitly reference this type,
/// but to directly chain method calls,
/// like `ctx.db.auth_store_projection_meta().meta_id().find(...)`.
pub struct AuthStoreProjectionMetaMetaIdUnique<'ctx> {
imp: __sdk::UniqueConstraintHandle<AuthStoreProjectionMeta, String>,
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
}
impl<'ctx> AuthStoreProjectionMetaTableHandle<'ctx> {
/// Get a handle on the `meta_id` unique index on the table `auth_store_projection_meta`.
pub fn meta_id(&self) -> AuthStoreProjectionMetaMetaIdUnique<'ctx> {
AuthStoreProjectionMetaMetaIdUnique {
imp: self.imp.get_unique_constraint::<String>("meta_id"),
phantom: std::marker::PhantomData,
}
}
}
impl<'ctx> AuthStoreProjectionMetaMetaIdUnique<'ctx> {
/// Find the subscribed row whose `meta_id` column value is equal to `col_val`,
/// if such a row is present in the client cache.
pub fn find(&self, col_val: &String) -> Option<AuthStoreProjectionMeta> {
self.imp.find(col_val)
}
}
#[doc(hidden)]
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
let _table =
client_cache.get_or_make_table::<AuthStoreProjectionMeta>("auth_store_projection_meta");
_table.add_unique_constraint::<String>("meta_id", |row| &row.meta_id);
}
#[doc(hidden)]
pub(super) fn parse_table_update(
raw_updates: __ws::v2::TableUpdate,
) -> __sdk::Result<__sdk::TableUpdate<AuthStoreProjectionMeta>> {
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
__sdk::InternalError::failed_parse("TableUpdate<AuthStoreProjectionMeta>", "TableUpdate")
.with_cause(e)
.into()
})
}
#[allow(non_camel_case_types)]
/// Extension trait for query builder access to the table `AuthStoreProjectionMeta`.
///
/// Implemented for [`__sdk::QueryTableAccessor`].
pub trait auth_store_projection_metaQueryTableAccess {
#[allow(non_snake_case)]
/// Get a query builder for the table `AuthStoreProjectionMeta`.
fn auth_store_projection_meta(&self) -> __sdk::__query_builder::Table<AuthStoreProjectionMeta>;
}
impl auth_store_projection_metaQueryTableAccess for __sdk::QueryTableAccessor {
fn auth_store_projection_meta(&self) -> __sdk::__query_builder::Table<AuthStoreProjectionMeta> {
__sdk::__query_builder::Table::new("auth_store_projection_meta")
}
}

View File

@@ -0,0 +1,52 @@
// 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 AuthStoreProjectionMeta {
pub meta_id: String,
pub updated_at: __sdk::Timestamp,
}
impl __sdk::InModule for AuthStoreProjectionMeta {
type Module = super::RemoteModule;
}
/// Column accessor struct for the table `AuthStoreProjectionMeta`.
///
/// Provides typed access to columns for query building.
pub struct AuthStoreProjectionMetaCols {
pub meta_id: __sdk::__query_builder::Col<AuthStoreProjectionMeta, String>,
pub updated_at: __sdk::__query_builder::Col<AuthStoreProjectionMeta, __sdk::Timestamp>,
}
impl __sdk::__query_builder::HasCols for AuthStoreProjectionMeta {
type Cols = AuthStoreProjectionMetaCols;
fn cols(table_name: &'static str) -> Self::Cols {
AuthStoreProjectionMetaCols {
meta_id: __sdk::__query_builder::Col::new(table_name, "meta_id"),
updated_at: __sdk::__query_builder::Col::new(table_name, "updated_at"),
}
}
}
/// Indexed column accessor struct for the table `AuthStoreProjectionMeta`.
///
/// Provides typed access to indexed columns for query building.
pub struct AuthStoreProjectionMetaIxCols {
pub meta_id: __sdk::__query_builder::IxCol<AuthStoreProjectionMeta, String>,
}
impl __sdk::__query_builder::HasIxCols for AuthStoreProjectionMeta {
type IxCols = AuthStoreProjectionMetaIxCols;
fn ix_cols(table_name: &'static str) -> Self::IxCols {
AuthStoreProjectionMetaIxCols {
meta_id: __sdk::__query_builder::IxCol::new(table_name, "meta_id"),
}
}
}
impl __sdk::__query_builder::CanBeLookupTable for AuthStoreProjectionMeta {}

View File

@@ -0,0 +1,59 @@
// 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};
use super::auth_store_snapshot_import_procedure_result_type::AuthStoreSnapshotImportProcedureResult;
use super::auth_store_snapshot_upsert_input_type::AuthStoreSnapshotUpsertInput;
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
struct ImportAuthStoreSnapshotJsonArgs {
pub input: AuthStoreSnapshotUpsertInput,
}
impl __sdk::InModule for ImportAuthStoreSnapshotJsonArgs {
type Module = super::RemoteModule;
}
#[allow(non_camel_case_types)]
/// Extension trait for access to the procedure `import_auth_store_snapshot_json`.
///
/// Implemented for [`super::RemoteProcedures`].
pub trait import_auth_store_snapshot_json {
fn import_auth_store_snapshot_json(&self, input: AuthStoreSnapshotUpsertInput) {
self.import_auth_store_snapshot_json_then(input, |_, _| {});
}
fn import_auth_store_snapshot_json_then(
&self,
input: AuthStoreSnapshotUpsertInput,
__callback: impl FnOnce(
&super::ProcedureEventContext,
Result<AuthStoreSnapshotImportProcedureResult, __sdk::InternalError>,
) + Send
+ 'static,
);
}
impl import_auth_store_snapshot_json for super::RemoteProcedures {
fn import_auth_store_snapshot_json_then(
&self,
input: AuthStoreSnapshotUpsertInput,
__callback: impl FnOnce(
&super::ProcedureEventContext,
Result<AuthStoreSnapshotImportProcedureResult, __sdk::InternalError>,
) + Send
+ 'static,
) {
self.imp
.invoke_procedure_with_callback::<_, AuthStoreSnapshotImportProcedureResult>(
"import_auth_store_snapshot_json",
ImportAuthStoreSnapshotJsonArgs { input },
__callback,
);
}
}

View File

@@ -1,7 +1,7 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
// This was generated using spacetimedb cli version 2.1.0 (commit 6981f48b4bc1a71c8dd9bdfe5a2c343f6370243d).
// This was generated using spacetimedb cli version 2.2.0 (commit eb11e2f5c41dce6979715ad407996270d61329f6).
#![allow(unused, clippy::all)]
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
@@ -82,6 +82,8 @@ pub mod asset_object_upsert_snapshot_type;
pub mod attach_ai_result_reference_and_return_procedure;
pub mod auth_identity_table;
pub mod auth_identity_type;
pub mod auth_store_projection_meta_table;
pub mod auth_store_projection_meta_type;
pub mod auth_store_snapshot_import_procedure_result_type;
pub mod auth_store_snapshot_import_record_type;
pub mod auth_store_snapshot_procedure_result_type;
@@ -338,6 +340,7 @@ pub mod grant_inventory_item_input_type;
pub mod grant_new_user_registration_wallet_reward_procedure;
pub mod grant_player_progression_experience_and_return_procedure;
pub mod grant_player_progression_experience_reducer;
pub mod import_auth_store_snapshot_json_procedure;
pub mod import_auth_store_snapshot_procedure;
pub mod import_database_migration_from_chunks_procedure;
pub mod import_database_migration_from_file_procedure;
@@ -894,6 +897,8 @@ pub use asset_object_upsert_snapshot_type::AssetObjectUpsertSnapshot;
pub use attach_ai_result_reference_and_return_procedure::attach_ai_result_reference_and_return;
pub use auth_identity_table::*;
pub use auth_identity_type::AuthIdentity;
pub use auth_store_projection_meta_table::*;
pub use auth_store_projection_meta_type::AuthStoreProjectionMeta;
pub use auth_store_snapshot_import_procedure_result_type::AuthStoreSnapshotImportProcedureResult;
pub use auth_store_snapshot_import_record_type::AuthStoreSnapshotImportRecord;
pub use auth_store_snapshot_procedure_result_type::AuthStoreSnapshotProcedureResult;
@@ -1150,6 +1155,7 @@ pub use grant_inventory_item_input_type::GrantInventoryItemInput;
pub use grant_new_user_registration_wallet_reward_procedure::grant_new_user_registration_wallet_reward;
pub use grant_player_progression_experience_and_return_procedure::grant_player_progression_experience_and_return;
pub use grant_player_progression_experience_reducer::grant_player_progression_experience;
pub use import_auth_store_snapshot_json_procedure::import_auth_store_snapshot_json;
pub use import_auth_store_snapshot_procedure::import_auth_store_snapshot;
pub use import_database_migration_from_chunks_procedure::import_database_migration_from_chunks;
pub use import_database_migration_from_file_procedure::import_database_migration_from_file;
@@ -1912,6 +1918,7 @@ pub struct DbUpdate {
asset_event: __sdk::TableUpdate<AssetEvent>,
asset_object: __sdk::TableUpdate<AssetObject>,
auth_identity: __sdk::TableUpdate<AuthIdentity>,
auth_store_projection_meta: __sdk::TableUpdate<AuthStoreProjectionMeta>,
auth_store_snapshot: __sdk::TableUpdate<AuthStoreSnapshot>,
battle_state: __sdk::TableUpdate<BattleState>,
big_fish_agent_message: __sdk::TableUpdate<BigFishAgentMessage>,
@@ -2020,6 +2027,9 @@ impl TryFrom<__ws::v2::TransactionUpdate> for DbUpdate {
"auth_identity" => db_update
.auth_identity
.append(auth_identity_table::parse_table_update(table_update)?),
"auth_store_projection_meta" => db_update.auth_store_projection_meta.append(
auth_store_projection_meta_table::parse_table_update(table_update)?,
),
"auth_store_snapshot" => db_update
.auth_store_snapshot
.append(auth_store_snapshot_table::parse_table_update(table_update)?),
@@ -2295,6 +2305,12 @@ impl __sdk::DbUpdate for DbUpdate {
diff.auth_identity = cache
.apply_diff_to_table::<AuthIdentity>("auth_identity", &self.auth_identity)
.with_updates_by_pk(|row| &row.identity_id);
diff.auth_store_projection_meta = cache
.apply_diff_to_table::<AuthStoreProjectionMeta>(
"auth_store_projection_meta",
&self.auth_store_projection_meta,
)
.with_updates_by_pk(|row| &row.meta_id);
diff.auth_store_snapshot = cache
.apply_diff_to_table::<AuthStoreSnapshot>(
"auth_store_snapshot",
@@ -2695,6 +2711,9 @@ impl __sdk::DbUpdate for DbUpdate {
"auth_identity" => db_update
.auth_identity
.append(__sdk::parse_row_list_as_inserts(table_rows.rows)?),
"auth_store_projection_meta" => db_update
.auth_store_projection_meta
.append(__sdk::parse_row_list_as_inserts(table_rows.rows)?),
"auth_store_snapshot" => db_update
.auth_store_snapshot
.append(__sdk::parse_row_list_as_inserts(table_rows.rows)?),
@@ -2948,6 +2967,9 @@ impl __sdk::DbUpdate for DbUpdate {
"auth_identity" => db_update
.auth_identity
.append(__sdk::parse_row_list_as_deletes(table_rows.rows)?),
"auth_store_projection_meta" => db_update
.auth_store_projection_meta
.append(__sdk::parse_row_list_as_deletes(table_rows.rows)?),
"auth_store_snapshot" => db_update
.auth_store_snapshot
.append(__sdk::parse_row_list_as_deletes(table_rows.rows)?),
@@ -3183,6 +3205,7 @@ pub struct AppliedDiff<'r> {
asset_event: __sdk::TableAppliedDiff<'r, AssetEvent>,
asset_object: __sdk::TableAppliedDiff<'r, AssetObject>,
auth_identity: __sdk::TableAppliedDiff<'r, AuthIdentity>,
auth_store_projection_meta: __sdk::TableAppliedDiff<'r, AuthStoreProjectionMeta>,
auth_store_snapshot: __sdk::TableAppliedDiff<'r, AuthStoreSnapshot>,
battle_state: __sdk::TableAppliedDiff<'r, BattleState>,
big_fish_agent_message: __sdk::TableAppliedDiff<'r, BigFishAgentMessage>,
@@ -3309,6 +3332,11 @@ impl<'r> __sdk::AppliedDiff<'r> for AppliedDiff<'r> {
&self.auth_identity,
event,
);
callbacks.invoke_table_row_callbacks::<AuthStoreProjectionMeta>(
"auth_store_projection_meta",
&self.auth_store_projection_meta,
event,
);
callbacks.invoke_table_row_callbacks::<AuthStoreSnapshot>(
"auth_store_snapshot",
&self.auth_store_snapshot,
@@ -4317,6 +4345,7 @@ impl __sdk::SpacetimeModule for RemoteModule {
asset_event_table::register_table(client_cache);
asset_object_table::register_table(client_cache);
auth_identity_table::register_table(client_cache);
auth_store_projection_meta_table::register_table(client_cache);
auth_store_snapshot_table::register_table(client_cache);
battle_state_table::register_table(client_cache);
big_fish_agent_message_table::register_table(client_cache);
@@ -4399,6 +4428,7 @@ impl __sdk::SpacetimeModule for RemoteModule {
"asset_event",
"asset_object",
"auth_identity",
"auth_store_projection_meta",
"auth_store_snapshot",
"battle_state",
"big_fish_agent_message",