This commit is contained in:
2026-04-21 19:17:31 +08:00
parent d234d27cc0
commit 89129ef1f4
83 changed files with 13329 additions and 176 deletions

View File

@@ -0,0 +1,10 @@
[package]
name = "spacetime-client"
edition.workspace = true
version.workspace = true
license.workspace = true
[dependencies]
module-assets = { path = "../module-assets" }
spacetimedb-sdk = "2.1.0"
tokio = { version = "1", features = ["rt", "sync", "time"] }

View File

@@ -12,12 +12,20 @@
## 2. 当前阶段说明
当前提交仅完成目录占位,不提前进入 bindings 生成、调用封装与订阅实现。
当前目录已不再只是占位,当前阶段已经落下:
1. 通过 `spacetime generate --lang rust --include-private` 生成的最小 Rust bindings
2. `DbConnection` 连接封装
3. `confirm_asset_object_and_return` procedure 的最小调用适配
4. `bind_asset_object_to_entity_and_return` procedure 的最小调用适配
5. `api-server` 所需的 `asset_object` 确认与 `asset_entity_binding` 绑定返回值转换
`confirm_asset_object_and_return``bind_asset_object_to_entity_and_return` 的调用必须等到 SDK `on_connect` 回调后再发起。`DbConnection::build()` 只代表 WebSocket 已经初始化,不代表 SpacetimeDB 身份握手完成;如果过早调用 procedure本地联调会表现为连接建立但请求长期没有回调最终等到 idle timeout。
后续与本 package 直接相关的任务包括:
1. 设计 bindings 生成与更新流程
2. 设计 reducer、view、订阅的统一调用接口
1. 固化 bindings 生成与更新脚本
2. 设计 reducer、procedure、view、订阅的统一调用接口
3. 设计身份透传与连接配置策略
4. 设计 Axum / worker / 测试环境下的客户端复用方式

View File

@@ -0,0 +1,306 @@
pub mod module_bindings;
use std::{
error::Error,
fmt,
sync::{Arc, Mutex},
time::Duration,
};
use module_assets::{
AssetEntityBindingRecord, AssetObjectAccessPolicy, AssetObjectRecord,
build_asset_entity_binding_record, build_asset_object_record,
};
use spacetimedb_sdk::DbContext;
use tokio::{sync::oneshot, time::timeout};
use crate::module_bindings::{
AssetEntityBindingInput as BindingAssetEntityBindingInput,
AssetEntityBindingProcedureResult as BindingAssetEntityBindingProcedureResult,
AssetEntityBindingSnapshot as BindingAssetEntityBindingSnapshot,
AssetObjectProcedureResult as BindingAssetObjectProcedureResult,
AssetObjectUpsertInput as BindingAssetObjectUpsertInput,
AssetObjectUpsertSnapshot as BindingAssetObjectUpsertSnapshot, DbConnection,
bind_asset_object_to_entity_and_return_procedure::bind_asset_object_to_entity_and_return as _,
confirm_asset_object_and_return_procedure::confirm_asset_object_and_return as _,
};
#[derive(Clone, Debug)]
pub struct SpacetimeClientConfig {
pub server_url: String,
pub database: String,
pub token: Option<String>,
}
#[derive(Clone, Debug)]
pub struct SpacetimeClient {
config: SpacetimeClientConfig,
}
#[derive(Debug)]
pub enum SpacetimeClientError {
Build(String),
ConnectDropped,
Procedure(String),
Runtime(String),
Timeout,
}
const CONFIRM_ASSET_OBJECT_TIMEOUT: Duration = Duration::from_secs(10);
type ProcedureResultSender<T> =
Arc<Mutex<Option<oneshot::Sender<Result<T, SpacetimeClientError>>>>>;
impl SpacetimeClient {
pub fn new(config: SpacetimeClientConfig) -> Self {
Self { config }
}
pub async fn confirm_asset_object(
&self,
input: module_assets::AssetObjectUpsertInput,
) -> Result<AssetObjectRecord, SpacetimeClientError> {
let procedure_input = map_upsert_input(input);
self.call_after_connect(move |connection, sender| {
connection
.procedures()
.confirm_asset_object_and_return_then(procedure_input, move |_, result| {
let mapped = result
.map_err(|error| SpacetimeClientError::Procedure(error.to_string()))
.and_then(map_procedure_result);
send_once(&sender, mapped);
});
})
.await
}
pub async fn bind_asset_object_to_entity(
&self,
input: module_assets::AssetEntityBindingInput,
) -> Result<AssetEntityBindingRecord, SpacetimeClientError> {
let procedure_input = map_entity_binding_input(input);
self.call_after_connect(move |connection, sender| {
connection
.procedures()
.bind_asset_object_to_entity_and_return_then(procedure_input, move |_, result| {
let mapped = result
.map_err(|error| SpacetimeClientError::Procedure(error.to_string()))
.and_then(map_entity_binding_procedure_result);
send_once(&sender, mapped);
});
})
.await
}
async fn call_after_connect<T>(
&self,
call: impl FnOnce(&DbConnection, ProcedureResultSender<T>) + Send + 'static,
) -> Result<T, SpacetimeClientError>
where
T: Send + 'static,
{
let config = self.config.clone();
let (sender, receiver) = oneshot::channel();
let result_sender = Arc::new(Mutex::new(Some(sender)));
let connect_sender = result_sender.clone();
let disconnect_sender = result_sender.clone();
let connection = tokio::task::spawn_blocking(move || {
DbConnection::builder()
.with_uri(config.server_url)
.with_database_name(config.database)
.with_token(config.token)
.on_connect(move |connection, _, _| {
// SDK 收到 IdentityToken 后才调用 procedure避免 WebSocket 已建好但身份握手未完成时丢请求。
call(connection, connect_sender);
})
.on_disconnect(move |_, error| {
let message = error
.map(|error| error.to_string())
.unwrap_or_else(|| "SpacetimeDB 连接在 procedure 返回前断开".to_string());
send_once(
&disconnect_sender,
Err(SpacetimeClientError::Procedure(message)),
);
})
.build()
.map_err(|error| SpacetimeClientError::Build(error.to_string()))
})
.await
.map_err(|error| SpacetimeClientError::Runtime(error.to_string()))??;
let runner = connection.run_threaded();
let result = timeout(CONFIRM_ASSET_OBJECT_TIMEOUT, receiver).await;
let _ = connection.disconnect();
// SDK 线程会在断开消息被处理后自行退出HTTP 请求不能同步等待该线程,否则 Windows 本地联调可能卡在收尾阶段。
drop(runner);
result
.map_err(|_| SpacetimeClientError::Timeout)?
.map_err(|_| SpacetimeClientError::ConnectDropped)?
}
}
fn send_once<T>(sender: &ProcedureResultSender<T>, result: Result<T, SpacetimeClientError>) {
if let Some(sender) = sender
.lock()
.expect("spacetime result sender should not poison")
.take()
{
let _ = sender.send(result);
}
}
fn map_entity_binding_input(
input: module_assets::AssetEntityBindingInput,
) -> BindingAssetEntityBindingInput {
BindingAssetEntityBindingInput {
binding_id: input.binding_id,
asset_object_id: input.asset_object_id,
entity_kind: input.entity_kind,
entity_id: input.entity_id,
slot: input.slot,
asset_kind: input.asset_kind,
owner_user_id: input.owner_user_id,
profile_id: input.profile_id,
updated_at_micros: input.updated_at_micros,
}
}
fn map_upsert_input(input: module_assets::AssetObjectUpsertInput) -> BindingAssetObjectUpsertInput {
BindingAssetObjectUpsertInput {
asset_object_id: input.asset_object_id,
bucket: input.bucket,
object_key: input.object_key,
access_policy: map_access_policy(input.access_policy),
content_type: input.content_type,
content_length: input.content_length,
content_hash: input.content_hash,
version: input.version,
source_job_id: input.source_job_id,
owner_user_id: input.owner_user_id,
profile_id: input.profile_id,
entity_id: input.entity_id,
asset_kind: input.asset_kind,
updated_at_micros: input.updated_at_micros,
}
}
fn map_procedure_result(
result: BindingAssetObjectProcedureResult,
) -> Result<AssetObjectRecord, SpacetimeClientError> {
if !result.ok {
return Err(SpacetimeClientError::Procedure(
result
.error_message
.unwrap_or_else(|| "SpacetimeDB procedure 返回未知错误".to_string()),
));
}
let snapshot = result.record.ok_or_else(|| {
SpacetimeClientError::Procedure("SpacetimeDB procedure 未返回对象快照".to_string())
})?;
Ok(build_asset_object_record(map_snapshot(snapshot)))
}
fn map_entity_binding_procedure_result(
result: BindingAssetEntityBindingProcedureResult,
) -> Result<AssetEntityBindingRecord, SpacetimeClientError> {
if !result.ok {
return Err(SpacetimeClientError::Procedure(
result
.error_message
.unwrap_or_else(|| "SpacetimeDB procedure 返回未知错误".to_string()),
));
}
let snapshot = result.record.ok_or_else(|| {
SpacetimeClientError::Procedure("SpacetimeDB procedure 未返回绑定快照".to_string())
})?;
Ok(build_asset_entity_binding_record(
map_entity_binding_snapshot(snapshot),
))
}
fn map_entity_binding_snapshot(
snapshot: BindingAssetEntityBindingSnapshot,
) -> module_assets::AssetEntityBindingSnapshot {
module_assets::AssetEntityBindingSnapshot {
binding_id: snapshot.binding_id,
asset_object_id: snapshot.asset_object_id,
entity_kind: snapshot.entity_kind,
entity_id: snapshot.entity_id,
slot: snapshot.slot,
asset_kind: snapshot.asset_kind,
owner_user_id: snapshot.owner_user_id,
profile_id: snapshot.profile_id,
created_at_micros: snapshot.created_at_micros,
updated_at_micros: snapshot.updated_at_micros,
}
}
fn map_snapshot(
snapshot: BindingAssetObjectUpsertSnapshot,
) -> module_assets::AssetObjectUpsertSnapshot {
module_assets::AssetObjectUpsertSnapshot {
asset_object_id: snapshot.asset_object_id,
bucket: snapshot.bucket,
object_key: snapshot.object_key,
access_policy: map_access_policy_back(snapshot.access_policy),
content_type: snapshot.content_type,
content_length: snapshot.content_length,
content_hash: snapshot.content_hash,
version: snapshot.version,
source_job_id: snapshot.source_job_id,
owner_user_id: snapshot.owner_user_id,
profile_id: snapshot.profile_id,
entity_id: snapshot.entity_id,
asset_kind: snapshot.asset_kind,
created_at_micros: snapshot.created_at_micros,
updated_at_micros: snapshot.updated_at_micros,
}
}
fn map_access_policy(
value: AssetObjectAccessPolicy,
) -> crate::module_bindings::AssetObjectAccessPolicy {
match value {
AssetObjectAccessPolicy::Private => {
crate::module_bindings::AssetObjectAccessPolicy::Private
}
AssetObjectAccessPolicy::PublicRead => {
crate::module_bindings::AssetObjectAccessPolicy::PublicRead
}
}
}
fn map_access_policy_back(
value: crate::module_bindings::AssetObjectAccessPolicy,
) -> AssetObjectAccessPolicy {
match value {
crate::module_bindings::AssetObjectAccessPolicy::Private => {
AssetObjectAccessPolicy::Private
}
crate::module_bindings::AssetObjectAccessPolicy::PublicRead => {
AssetObjectAccessPolicy::PublicRead
}
}
}
impl fmt::Display for SpacetimeClientError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Build(message) | Self::Procedure(message) | Self::Runtime(message) => {
f.write_str(message)
}
Self::ConnectDropped => f.write_str("SpacetimeDB 连接在返回结果前已断开"),
Self::Timeout => f.write_str("SpacetimeDB procedure 调用超时"),
}
}
}
impl Error for SpacetimeClientError {}

View File

@@ -0,0 +1,23 @@
// 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 AssetEntityBindingInput {
pub binding_id: String,
pub asset_object_id: String,
pub entity_kind: String,
pub entity_id: String,
pub slot: String,
pub asset_kind: String,
pub owner_user_id: Option<String>,
pub profile_id: Option<String>,
pub updated_at_micros: i64,
}
impl __sdk::InModule for AssetEntityBindingInput {
type Module = super::RemoteModule;
}

View File

@@ -0,0 +1,19 @@
// 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::asset_entity_binding_snapshot_type::AssetEntityBindingSnapshot;
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
pub struct AssetEntityBindingProcedureResult {
pub ok: bool,
pub record: Option<AssetEntityBindingSnapshot>,
pub error_message: Option<String>,
}
impl __sdk::InModule for AssetEntityBindingProcedureResult {
type Module = super::RemoteModule;
}

View File

@@ -0,0 +1,24 @@
// 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 AssetEntityBindingSnapshot {
pub binding_id: String,
pub asset_object_id: String,
pub entity_kind: String,
pub entity_id: String,
pub slot: String,
pub asset_kind: String,
pub owner_user_id: Option<String>,
pub profile_id: Option<String>,
pub created_at_micros: i64,
pub updated_at_micros: i64,
}
impl __sdk::InModule for AssetEntityBindingSnapshot {
type Module = super::RemoteModule;
}

View File

@@ -0,0 +1,78 @@
// 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 AssetEntityBinding {
pub binding_id: String,
pub asset_object_id: String,
pub entity_kind: String,
pub entity_id: String,
pub slot: String,
pub asset_kind: String,
pub owner_user_id: Option<String>,
pub profile_id: Option<String>,
pub created_at: __sdk::Timestamp,
pub updated_at: __sdk::Timestamp,
}
impl __sdk::InModule for AssetEntityBinding {
type Module = super::RemoteModule;
}
/// Column accessor struct for the table `AssetEntityBinding`.
///
/// Provides typed access to columns for query building.
pub struct AssetEntityBindingCols {
pub binding_id: __sdk::__query_builder::Col<AssetEntityBinding, String>,
pub asset_object_id: __sdk::__query_builder::Col<AssetEntityBinding, String>,
pub entity_kind: __sdk::__query_builder::Col<AssetEntityBinding, String>,
pub entity_id: __sdk::__query_builder::Col<AssetEntityBinding, String>,
pub slot: __sdk::__query_builder::Col<AssetEntityBinding, String>,
pub asset_kind: __sdk::__query_builder::Col<AssetEntityBinding, String>,
pub owner_user_id: __sdk::__query_builder::Col<AssetEntityBinding, Option<String>>,
pub profile_id: __sdk::__query_builder::Col<AssetEntityBinding, Option<String>>,
pub created_at: __sdk::__query_builder::Col<AssetEntityBinding, __sdk::Timestamp>,
pub updated_at: __sdk::__query_builder::Col<AssetEntityBinding, __sdk::Timestamp>,
}
impl __sdk::__query_builder::HasCols for AssetEntityBinding {
type Cols = AssetEntityBindingCols;
fn cols(table_name: &'static str) -> Self::Cols {
AssetEntityBindingCols {
binding_id: __sdk::__query_builder::Col::new(table_name, "binding_id"),
asset_object_id: __sdk::__query_builder::Col::new(table_name, "asset_object_id"),
entity_kind: __sdk::__query_builder::Col::new(table_name, "entity_kind"),
entity_id: __sdk::__query_builder::Col::new(table_name, "entity_id"),
slot: __sdk::__query_builder::Col::new(table_name, "slot"),
asset_kind: __sdk::__query_builder::Col::new(table_name, "asset_kind"),
owner_user_id: __sdk::__query_builder::Col::new(table_name, "owner_user_id"),
profile_id: __sdk::__query_builder::Col::new(table_name, "profile_id"),
created_at: __sdk::__query_builder::Col::new(table_name, "created_at"),
updated_at: __sdk::__query_builder::Col::new(table_name, "updated_at"),
}
}
}
/// Indexed column accessor struct for the table `AssetEntityBinding`.
///
/// Provides typed access to indexed columns for query building.
pub struct AssetEntityBindingIxCols {
pub asset_object_id: __sdk::__query_builder::IxCol<AssetEntityBinding, String>,
pub binding_id: __sdk::__query_builder::IxCol<AssetEntityBinding, String>,
}
impl __sdk::__query_builder::HasIxCols for AssetEntityBinding {
type IxCols = AssetEntityBindingIxCols;
fn ix_cols(table_name: &'static str) -> Self::IxCols {
AssetEntityBindingIxCols {
asset_object_id: __sdk::__query_builder::IxCol::new(table_name, "asset_object_id"),
binding_id: __sdk::__query_builder::IxCol::new(table_name, "binding_id"),
}
}
}
impl __sdk::__query_builder::CanBeLookupTable for AssetEntityBinding {}

View File

@@ -0,0 +1,18 @@
// 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)]
#[derive(Copy, Eq, Hash)]
pub enum AssetObjectAccessPolicy {
Private,
PublicRead,
}
impl __sdk::InModule for AssetObjectAccessPolicy {
type Module = super::RemoteModule;
}

View File

@@ -0,0 +1,19 @@
// 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::asset_object_upsert_snapshot_type::AssetObjectUpsertSnapshot;
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
pub struct AssetObjectProcedureResult {
pub ok: bool,
pub record: Option<AssetObjectUpsertSnapshot>,
pub error_message: Option<String>,
}
impl __sdk::InModule for AssetObjectProcedureResult {
type Module = super::RemoteModule;
}

View File

@@ -0,0 +1,95 @@
// 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::asset_object_access_policy_type::AssetObjectAccessPolicy;
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
pub struct AssetObject {
pub asset_object_id: String,
pub bucket: String,
pub object_key: String,
pub access_policy: AssetObjectAccessPolicy,
pub content_type: Option<String>,
pub content_length: u64,
pub content_hash: Option<String>,
pub version: u32,
pub source_job_id: Option<String>,
pub owner_user_id: Option<String>,
pub profile_id: Option<String>,
pub entity_id: Option<String>,
pub asset_kind: String,
pub created_at: __sdk::Timestamp,
pub updated_at: __sdk::Timestamp,
}
impl __sdk::InModule for AssetObject {
type Module = super::RemoteModule;
}
/// Column accessor struct for the table `AssetObject`.
///
/// Provides typed access to columns for query building.
pub struct AssetObjectCols {
pub asset_object_id: __sdk::__query_builder::Col<AssetObject, String>,
pub bucket: __sdk::__query_builder::Col<AssetObject, String>,
pub object_key: __sdk::__query_builder::Col<AssetObject, String>,
pub access_policy: __sdk::__query_builder::Col<AssetObject, AssetObjectAccessPolicy>,
pub content_type: __sdk::__query_builder::Col<AssetObject, Option<String>>,
pub content_length: __sdk::__query_builder::Col<AssetObject, u64>,
pub content_hash: __sdk::__query_builder::Col<AssetObject, Option<String>>,
pub version: __sdk::__query_builder::Col<AssetObject, u32>,
pub source_job_id: __sdk::__query_builder::Col<AssetObject, Option<String>>,
pub owner_user_id: __sdk::__query_builder::Col<AssetObject, Option<String>>,
pub profile_id: __sdk::__query_builder::Col<AssetObject, Option<String>>,
pub entity_id: __sdk::__query_builder::Col<AssetObject, Option<String>>,
pub asset_kind: __sdk::__query_builder::Col<AssetObject, String>,
pub created_at: __sdk::__query_builder::Col<AssetObject, __sdk::Timestamp>,
pub updated_at: __sdk::__query_builder::Col<AssetObject, __sdk::Timestamp>,
}
impl __sdk::__query_builder::HasCols for AssetObject {
type Cols = AssetObjectCols;
fn cols(table_name: &'static str) -> Self::Cols {
AssetObjectCols {
asset_object_id: __sdk::__query_builder::Col::new(table_name, "asset_object_id"),
bucket: __sdk::__query_builder::Col::new(table_name, "bucket"),
object_key: __sdk::__query_builder::Col::new(table_name, "object_key"),
access_policy: __sdk::__query_builder::Col::new(table_name, "access_policy"),
content_type: __sdk::__query_builder::Col::new(table_name, "content_type"),
content_length: __sdk::__query_builder::Col::new(table_name, "content_length"),
content_hash: __sdk::__query_builder::Col::new(table_name, "content_hash"),
version: __sdk::__query_builder::Col::new(table_name, "version"),
source_job_id: __sdk::__query_builder::Col::new(table_name, "source_job_id"),
owner_user_id: __sdk::__query_builder::Col::new(table_name, "owner_user_id"),
profile_id: __sdk::__query_builder::Col::new(table_name, "profile_id"),
entity_id: __sdk::__query_builder::Col::new(table_name, "entity_id"),
asset_kind: __sdk::__query_builder::Col::new(table_name, "asset_kind"),
created_at: __sdk::__query_builder::Col::new(table_name, "created_at"),
updated_at: __sdk::__query_builder::Col::new(table_name, "updated_at"),
}
}
}
/// Indexed column accessor struct for the table `AssetObject`.
///
/// Provides typed access to indexed columns for query building.
pub struct AssetObjectIxCols {
pub asset_kind: __sdk::__query_builder::IxCol<AssetObject, String>,
pub asset_object_id: __sdk::__query_builder::IxCol<AssetObject, String>,
}
impl __sdk::__query_builder::HasIxCols for AssetObject {
type IxCols = AssetObjectIxCols;
fn ix_cols(table_name: &'static str) -> Self::IxCols {
AssetObjectIxCols {
asset_kind: __sdk::__query_builder::IxCol::new(table_name, "asset_kind"),
asset_object_id: __sdk::__query_builder::IxCol::new(table_name, "asset_object_id"),
}
}
}
impl __sdk::__query_builder::CanBeLookupTable for AssetObject {}

View File

@@ -0,0 +1,30 @@
// 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::asset_object_access_policy_type::AssetObjectAccessPolicy;
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
pub struct AssetObjectUpsertInput {
pub asset_object_id: String,
pub bucket: String,
pub object_key: String,
pub access_policy: AssetObjectAccessPolicy,
pub content_type: Option<String>,
pub content_length: u64,
pub content_hash: Option<String>,
pub version: u32,
pub source_job_id: Option<String>,
pub owner_user_id: Option<String>,
pub profile_id: Option<String>,
pub entity_id: Option<String>,
pub asset_kind: String,
pub updated_at_micros: i64,
}
impl __sdk::InModule for AssetObjectUpsertInput {
type Module = super::RemoteModule;
}

View File

@@ -0,0 +1,31 @@
// 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::asset_object_access_policy_type::AssetObjectAccessPolicy;
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
pub struct AssetObjectUpsertSnapshot {
pub asset_object_id: String,
pub bucket: String,
pub object_key: String,
pub access_policy: AssetObjectAccessPolicy,
pub content_type: Option<String>,
pub content_length: u64,
pub content_hash: Option<String>,
pub version: u32,
pub source_job_id: Option<String>,
pub owner_user_id: Option<String>,
pub profile_id: Option<String>,
pub entity_id: Option<String>,
pub asset_kind: String,
pub created_at_micros: i64,
pub updated_at_micros: i64,
}
impl __sdk::InModule for AssetObjectUpsertSnapshot {
type Module = super::RemoteModule;
}

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::asset_entity_binding_input_type::AssetEntityBindingInput;
use super::asset_entity_binding_procedure_result_type::AssetEntityBindingProcedureResult;
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
struct BindAssetObjectToEntityAndReturnArgs {
pub input: AssetEntityBindingInput,
}
impl __sdk::InModule for BindAssetObjectToEntityAndReturnArgs {
type Module = super::RemoteModule;
}
#[allow(non_camel_case_types)]
/// Extension trait for access to the procedure `bind_asset_object_to_entity_and_return`.
///
/// Implemented for [`super::RemoteProcedures`].
pub trait bind_asset_object_to_entity_and_return {
fn bind_asset_object_to_entity_and_return(&self, input: AssetEntityBindingInput) {
self.bind_asset_object_to_entity_and_return_then(input, |_, _| {});
}
fn bind_asset_object_to_entity_and_return_then(
&self,
input: AssetEntityBindingInput,
__callback: impl FnOnce(
&super::ProcedureEventContext,
Result<AssetEntityBindingProcedureResult, __sdk::InternalError>,
) + Send
+ 'static,
);
}
impl bind_asset_object_to_entity_and_return for super::RemoteProcedures {
fn bind_asset_object_to_entity_and_return_then(
&self,
input: AssetEntityBindingInput,
__callback: impl FnOnce(
&super::ProcedureEventContext,
Result<AssetEntityBindingProcedureResult, __sdk::InternalError>,
) + Send
+ 'static,
) {
self.imp
.invoke_procedure_with_callback::<_, AssetEntityBindingProcedureResult>(
"bind_asset_object_to_entity_and_return",
BindAssetObjectToEntityAndReturnArgs { input },
__callback,
);
}
}

View File

@@ -0,0 +1,68 @@
// 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::asset_entity_binding_input_type::AssetEntityBindingInput;
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
pub(super) struct BindAssetObjectToEntityArgs {
pub input: AssetEntityBindingInput,
}
impl From<BindAssetObjectToEntityArgs> for super::Reducer {
fn from(args: BindAssetObjectToEntityArgs) -> Self {
Self::BindAssetObjectToEntity { input: args.input }
}
}
impl __sdk::InModule for BindAssetObjectToEntityArgs {
type Module = super::RemoteModule;
}
#[allow(non_camel_case_types)]
/// Extension trait for access to the reducer `bind_asset_object_to_entity`.
///
/// Implemented for [`super::RemoteReducers`].
pub trait bind_asset_object_to_entity {
/// Request that the remote module invoke the reducer `bind_asset_object_to_entity` to run as soon as possible.
///
/// This method returns immediately, and errors only if we are unable to send the request.
/// The reducer will run asynchronously in the future,
/// and this method provides no way to listen for its completion status.
/// /// Use [`bind_asset_object_to_entity:bind_asset_object_to_entity_then`] to run a callback after the reducer completes.
fn bind_asset_object_to_entity(&self, input: AssetEntityBindingInput) -> __sdk::Result<()> {
self.bind_asset_object_to_entity_then(input, |_, _| {})
}
/// Request that the remote module invoke the reducer `bind_asset_object_to_entity` to run as soon as possible,
/// registering `callback` to run when we are notified that the reducer completed.
///
/// This method returns immediately, and errors only if we are unable to send the request.
/// The reducer will run asynchronously in the future,
/// and its status can be observed with the `callback`.
fn bind_asset_object_to_entity_then(
&self,
input: AssetEntityBindingInput,
callback: impl FnOnce(&super::ReducerEventContext, Result<Result<(), String>, __sdk::InternalError>)
+ Send
+ 'static,
) -> __sdk::Result<()>;
}
impl bind_asset_object_to_entity for super::RemoteReducers {
fn bind_asset_object_to_entity_then(
&self,
input: AssetEntityBindingInput,
callback: impl FnOnce(&super::ReducerEventContext, Result<Result<(), String>, __sdk::InternalError>)
+ Send
+ 'static,
) -> __sdk::Result<()> {
self.imp
.invoke_reducer_with_callback(BindAssetObjectToEntityArgs { input }, callback)
}
}

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::asset_object_procedure_result_type::AssetObjectProcedureResult;
use super::asset_object_upsert_input_type::AssetObjectUpsertInput;
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
struct ConfirmAssetObjectAndReturnArgs {
pub input: AssetObjectUpsertInput,
}
impl __sdk::InModule for ConfirmAssetObjectAndReturnArgs {
type Module = super::RemoteModule;
}
#[allow(non_camel_case_types)]
/// Extension trait for access to the procedure `confirm_asset_object_and_return`.
///
/// Implemented for [`super::RemoteProcedures`].
pub trait confirm_asset_object_and_return {
fn confirm_asset_object_and_return(&self, input: AssetObjectUpsertInput) {
self.confirm_asset_object_and_return_then(input, |_, _| {});
}
fn confirm_asset_object_and_return_then(
&self,
input: AssetObjectUpsertInput,
__callback: impl FnOnce(
&super::ProcedureEventContext,
Result<AssetObjectProcedureResult, __sdk::InternalError>,
) + Send
+ 'static,
);
}
impl confirm_asset_object_and_return for super::RemoteProcedures {
fn confirm_asset_object_and_return_then(
&self,
input: AssetObjectUpsertInput,
__callback: impl FnOnce(
&super::ProcedureEventContext,
Result<AssetObjectProcedureResult, __sdk::InternalError>,
) + Send
+ 'static,
) {
self.imp
.invoke_procedure_with_callback::<_, AssetObjectProcedureResult>(
"confirm_asset_object_and_return",
ConfirmAssetObjectAndReturnArgs { input },
__callback,
);
}
}

View File

@@ -0,0 +1,68 @@
// 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::asset_object_upsert_input_type::AssetObjectUpsertInput;
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
pub(super) struct ConfirmAssetObjectArgs {
pub input: AssetObjectUpsertInput,
}
impl From<ConfirmAssetObjectArgs> for super::Reducer {
fn from(args: ConfirmAssetObjectArgs) -> Self {
Self::ConfirmAssetObject { input: args.input }
}
}
impl __sdk::InModule for ConfirmAssetObjectArgs {
type Module = super::RemoteModule;
}
#[allow(non_camel_case_types)]
/// Extension trait for access to the reducer `confirm_asset_object`.
///
/// Implemented for [`super::RemoteReducers`].
pub trait confirm_asset_object {
/// Request that the remote module invoke the reducer `confirm_asset_object` to run as soon as possible.
///
/// This method returns immediately, and errors only if we are unable to send the request.
/// The reducer will run asynchronously in the future,
/// and this method provides no way to listen for its completion status.
/// /// Use [`confirm_asset_object:confirm_asset_object_then`] to run a callback after the reducer completes.
fn confirm_asset_object(&self, input: AssetObjectUpsertInput) -> __sdk::Result<()> {
self.confirm_asset_object_then(input, |_, _| {})
}
/// Request that the remote module invoke the reducer `confirm_asset_object` to run as soon as possible,
/// registering `callback` to run when we are notified that the reducer completed.
///
/// This method returns immediately, and errors only if we are unable to send the request.
/// The reducer will run asynchronously in the future,
/// and its status can be observed with the `callback`.
fn confirm_asset_object_then(
&self,
input: AssetObjectUpsertInput,
callback: impl FnOnce(&super::ReducerEventContext, Result<Result<(), String>, __sdk::InternalError>)
+ Send
+ 'static,
) -> __sdk::Result<()>;
}
impl confirm_asset_object for super::RemoteReducers {
fn confirm_asset_object_then(
&self,
input: AssetObjectUpsertInput,
callback: impl FnOnce(&super::ReducerEventContext, Result<Result<(), String>, __sdk::InternalError>)
+ Send
+ 'static,
) -> __sdk::Result<()> {
self.imp
.invoke_reducer_with_callback(ConfirmAssetObjectArgs { input }, callback)
}
}

View File

@@ -0,0 +1,823 @@
// 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).
#![allow(unused, clippy::all)]
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
pub mod asset_entity_binding_input_type;
pub mod asset_entity_binding_procedure_result_type;
pub mod asset_entity_binding_snapshot_type;
pub mod asset_entity_binding_type;
pub mod asset_object_access_policy_type;
pub mod asset_object_procedure_result_type;
pub mod asset_object_type;
pub mod asset_object_upsert_input_type;
pub mod asset_object_upsert_snapshot_type;
pub mod bind_asset_object_to_entity_and_return_procedure;
pub mod bind_asset_object_to_entity_reducer;
pub mod confirm_asset_object_and_return_procedure;
pub mod confirm_asset_object_reducer;
pub use asset_entity_binding_input_type::AssetEntityBindingInput;
pub use asset_entity_binding_procedure_result_type::AssetEntityBindingProcedureResult;
pub use asset_entity_binding_snapshot_type::AssetEntityBindingSnapshot;
pub use asset_entity_binding_type::AssetEntityBinding;
pub use asset_object_access_policy_type::AssetObjectAccessPolicy;
pub use asset_object_procedure_result_type::AssetObjectProcedureResult;
pub use asset_object_type::AssetObject;
pub use asset_object_upsert_input_type::AssetObjectUpsertInput;
pub use asset_object_upsert_snapshot_type::AssetObjectUpsertSnapshot;
pub use bind_asset_object_to_entity_and_return_procedure::bind_asset_object_to_entity_and_return;
pub use bind_asset_object_to_entity_reducer::bind_asset_object_to_entity;
pub use confirm_asset_object_and_return_procedure::confirm_asset_object_and_return;
pub use confirm_asset_object_reducer::confirm_asset_object;
#[derive(Clone, PartialEq, Debug)]
/// One of the reducers defined by this module.
///
/// Contained within a [`__sdk::ReducerEvent`] in [`EventContext`]s for reducer events
/// to indicate which reducer caused the event.
pub enum Reducer {
BindAssetObjectToEntity { input: AssetEntityBindingInput },
ConfirmAssetObject { input: AssetObjectUpsertInput },
}
impl __sdk::InModule for Reducer {
type Module = RemoteModule;
}
impl __sdk::Reducer for Reducer {
fn reducer_name(&self) -> &'static str {
match self {
Reducer::BindAssetObjectToEntity { .. } => "bind_asset_object_to_entity",
Reducer::ConfirmAssetObject { .. } => "confirm_asset_object",
_ => unreachable!(),
}
}
#[allow(clippy::clone_on_copy)]
fn args_bsatn(&self) -> Result<Vec<u8>, __sats::bsatn::EncodeError> {
match self {
Reducer::BindAssetObjectToEntity { input } => __sats::bsatn::to_vec(
&bind_asset_object_to_entity_reducer::BindAssetObjectToEntityArgs {
input: input.clone(),
},
),
Reducer::ConfirmAssetObject { input } => {
__sats::bsatn::to_vec(&confirm_asset_object_reducer::ConfirmAssetObjectArgs {
input: input.clone(),
})
}
_ => unreachable!(),
}
}
}
#[derive(Default, Debug)]
#[allow(non_snake_case)]
#[doc(hidden)]
pub struct DbUpdate {}
impl TryFrom<__ws::v2::TransactionUpdate> for DbUpdate {
type Error = __sdk::Error;
fn try_from(raw: __ws::v2::TransactionUpdate) -> Result<Self, Self::Error> {
let mut db_update = DbUpdate::default();
for table_update in __sdk::transaction_update_iter_table_updates(raw) {
match &table_update.table_name[..] {
unknown => {
return Err(__sdk::InternalError::unknown_name(
"table",
unknown,
"DatabaseUpdate",
)
.into());
}
}
}
Ok(db_update)
}
}
impl __sdk::InModule for DbUpdate {
type Module = RemoteModule;
}
impl __sdk::DbUpdate for DbUpdate {
fn apply_to_client_cache(
&self,
cache: &mut __sdk::ClientCache<RemoteModule>,
) -> AppliedDiff<'_> {
let mut diff = AppliedDiff::default();
diff
}
fn parse_initial_rows(raw: __ws::v2::QueryRows) -> __sdk::Result<Self> {
let mut db_update = DbUpdate::default();
for table_rows in raw.tables {
match &table_rows.table[..] {
unknown => {
return Err(
__sdk::InternalError::unknown_name("table", unknown, "QueryRows").into(),
);
}
}
}
Ok(db_update)
}
fn parse_unsubscribe_rows(raw: __ws::v2::QueryRows) -> __sdk::Result<Self> {
let mut db_update = DbUpdate::default();
for table_rows in raw.tables {
match &table_rows.table[..] {
unknown => {
return Err(
__sdk::InternalError::unknown_name("table", unknown, "QueryRows").into(),
);
}
}
}
Ok(db_update)
}
}
#[derive(Default)]
#[allow(non_snake_case)]
#[doc(hidden)]
pub struct AppliedDiff<'r> {
__unused: std::marker::PhantomData<&'r ()>,
}
impl __sdk::InModule for AppliedDiff<'_> {
type Module = RemoteModule;
}
impl<'r> __sdk::AppliedDiff<'r> for AppliedDiff<'r> {
fn invoke_row_callbacks(
&self,
event: &EventContext,
callbacks: &mut __sdk::DbCallbacks<RemoteModule>,
) {
}
}
#[doc(hidden)]
#[derive(Debug)]
pub struct RemoteModule;
impl __sdk::InModule for RemoteModule {
type Module = Self;
}
/// The `reducers` field of [`EventContext`] and [`DbConnection`],
/// with methods provided by extension traits for each reducer defined by the module.
pub struct RemoteReducers {
imp: __sdk::DbContextImpl<RemoteModule>,
}
impl __sdk::InModule for RemoteReducers {
type Module = RemoteModule;
}
/// The `procedures` field of [`DbConnection`] and other [`DbContext`] types,
/// with methods provided by extension traits for each procedure defined by the module.
pub struct RemoteProcedures {
imp: __sdk::DbContextImpl<RemoteModule>,
}
impl __sdk::InModule for RemoteProcedures {
type Module = RemoteModule;
}
/// The `db` field of [`EventContext`] and [`DbConnection`],
/// with methods provided by extension traits for each table defined by the module.
pub struct RemoteTables {
imp: __sdk::DbContextImpl<RemoteModule>,
}
impl __sdk::InModule for RemoteTables {
type Module = RemoteModule;
}
/// A connection to a remote module, including a materialized view of a subset of the database.
///
/// Connect to a remote module by calling [`DbConnection::builder`]
/// and using the [`__sdk::DbConnectionBuilder`] builder-pattern constructor.
///
/// You must explicitly advance the connection by calling any one of:
///
/// - [`DbConnection::frame_tick`].
#[cfg_attr(not(target_arch = "wasm32"), doc = "- [`DbConnection::run_threaded`].")]
#[cfg_attr(
target_arch = "wasm32",
doc = "- [`DbConnection::run_background_task`]."
)]
/// - [`DbConnection::run_async`].
/// - [`DbConnection::advance_one_message`].
#[cfg_attr(
not(target_arch = "wasm32"),
doc = "- [`DbConnection::advance_one_message_blocking`]."
)]
/// - [`DbConnection::advance_one_message_async`].
///
/// Which of these methods you should call depends on the specific needs of your application,
/// but you must call one of them, or else the connection will never progress.
pub struct DbConnection {
/// Access to tables defined by the module via extension traits implemented for [`RemoteTables`].
pub db: RemoteTables,
/// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`].
pub reducers: RemoteReducers,
#[doc(hidden)]
/// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`].
pub procedures: RemoteProcedures,
imp: __sdk::DbContextImpl<RemoteModule>,
}
impl __sdk::InModule for DbConnection {
type Module = RemoteModule;
}
impl __sdk::DbContext for DbConnection {
type DbView = RemoteTables;
type Reducers = RemoteReducers;
type Procedures = RemoteProcedures;
fn db(&self) -> &Self::DbView {
&self.db
}
fn reducers(&self) -> &Self::Reducers {
&self.reducers
}
fn procedures(&self) -> &Self::Procedures {
&self.procedures
}
fn is_active(&self) -> bool {
self.imp.is_active()
}
fn disconnect(&self) -> __sdk::Result<()> {
self.imp.disconnect()
}
type SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>;
fn subscription_builder(&self) -> Self::SubscriptionBuilder {
__sdk::SubscriptionBuilder::new(&self.imp)
}
fn try_identity(&self) -> Option<__sdk::Identity> {
self.imp.try_identity()
}
fn connection_id(&self) -> __sdk::ConnectionId {
self.imp.connection_id()
}
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {
self.imp.try_connection_id()
}
}
impl DbConnection {
/// Builder-pattern constructor for a connection to a remote module.
///
/// See [`__sdk::DbConnectionBuilder`] for required and optional configuration for the new connection.
pub fn builder() -> __sdk::DbConnectionBuilder<RemoteModule> {
__sdk::DbConnectionBuilder::new()
}
/// If any WebSocket messages are waiting, process one of them.
///
/// Returns `true` if a message was processed, or `false` if the queue is empty.
/// Callers should invoke this message in a loop until it returns `false`
/// or for as much time is available to process messages.
///
/// Returns an error if the connection is disconnected.
/// If the disconnection in question was normal,
/// i.e. the result of a call to [`__sdk::DbContext::disconnect`],
/// the returned error will be downcastable to [`__sdk::DisconnectedError`].
///
/// This is a low-level primitive exposed for power users who need significant control over scheduling.
/// Most applications should call [`Self::frame_tick`] each frame
/// to fully exhaust the queue whenever time is available.
pub fn advance_one_message(&self) -> __sdk::Result<bool> {
self.imp.advance_one_message()
}
/// Process one WebSocket message, potentially blocking the current thread until one is received.
///
/// Returns an error if the connection is disconnected.
/// If the disconnection in question was normal,
/// i.e. the result of a call to [`__sdk::DbContext::disconnect`],
/// the returned error will be downcastable to [`__sdk::DisconnectedError`].
///
/// This is a low-level primitive exposed for power users who need significant control over scheduling.
/// Most applications should call [`Self::run_threaded`] to spawn a thread
/// which advances the connection automatically.
#[cfg(not(target_arch = "wasm32"))]
pub fn advance_one_message_blocking(&self) -> __sdk::Result<()> {
self.imp.advance_one_message_blocking()
}
/// Process one WebSocket message, `await`ing until one is received.
///
/// Returns an error if the connection is disconnected.
/// If the disconnection in question was normal,
/// i.e. the result of a call to [`__sdk::DbContext::disconnect`],
/// the returned error will be downcastable to [`__sdk::DisconnectedError`].
///
/// This is a low-level primitive exposed for power users who need significant control over scheduling.
/// Most applications should call [`Self::run_async`] to run an `async` loop
/// which advances the connection when polled.
pub async fn advance_one_message_async(&self) -> __sdk::Result<()> {
self.imp.advance_one_message_async().await
}
/// Process all WebSocket messages waiting in the queue,
/// then return without `await`ing or blocking the current thread.
pub fn frame_tick(&self) -> __sdk::Result<()> {
self.imp.frame_tick()
}
/// Spawn a thread which processes WebSocket messages as they are received.
#[cfg(not(target_arch = "wasm32"))]
pub fn run_threaded(&self) -> std::thread::JoinHandle<()> {
self.imp.run_threaded()
}
/// Spawn a background task which processes WebSocket messages as they are received.
#[cfg(target_arch = "wasm32")]
pub fn run_background_task(&self) {
self.imp.run_background_task()
}
/// Run an `async` loop which processes WebSocket messages when polled.
pub async fn run_async(&self) -> __sdk::Result<()> {
self.imp.run_async().await
}
}
impl __sdk::DbConnection for DbConnection {
fn new(imp: __sdk::DbContextImpl<RemoteModule>) -> Self {
Self {
db: RemoteTables { imp: imp.clone() },
reducers: RemoteReducers { imp: imp.clone() },
procedures: RemoteProcedures { imp: imp.clone() },
imp,
}
}
}
/// A handle on a subscribed query.
// TODO: Document this better after implementing the new subscription API.
#[derive(Clone)]
pub struct SubscriptionHandle {
imp: __sdk::SubscriptionHandleImpl<RemoteModule>,
}
impl __sdk::InModule for SubscriptionHandle {
type Module = RemoteModule;
}
impl __sdk::SubscriptionHandle for SubscriptionHandle {
fn new(imp: __sdk::SubscriptionHandleImpl<RemoteModule>) -> Self {
Self { imp }
}
/// Returns true if this subscription has been terminated due to an unsubscribe call or an error.
fn is_ended(&self) -> bool {
self.imp.is_ended()
}
/// Returns true if this subscription has been applied and has not yet been unsubscribed.
fn is_active(&self) -> bool {
self.imp.is_active()
}
/// Unsubscribe from the query controlled by this `SubscriptionHandle`,
/// then run `on_end` when its rows are removed from the client cache.
fn unsubscribe_then(self, on_end: __sdk::OnEndedCallback<RemoteModule>) -> __sdk::Result<()> {
self.imp.unsubscribe_then(Some(on_end))
}
fn unsubscribe(self) -> __sdk::Result<()> {
self.imp.unsubscribe_then(None)
}
}
/// Alias trait for a [`__sdk::DbContext`] connected to this module,
/// with that trait's associated types bounded to this module's concrete types.
///
/// Users can use this trait as a boundary on definitions which should accept
/// either a [`DbConnection`] or an [`EventContext`] and operate on either.
pub trait RemoteDbContext:
__sdk::DbContext<
DbView = RemoteTables,
Reducers = RemoteReducers,
SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>,
>
{
}
impl<
Ctx: __sdk::DbContext<
DbView = RemoteTables,
Reducers = RemoteReducers,
SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>,
>,
> RemoteDbContext for Ctx
{
}
/// An [`__sdk::DbContext`] augmented with a [`__sdk::Event`],
/// passed to [`__sdk::Table::on_insert`], [`__sdk::Table::on_delete`] and [`__sdk::TableWithPrimaryKey::on_update`] callbacks.
pub struct EventContext {
/// Access to tables defined by the module via extension traits implemented for [`RemoteTables`].
pub db: RemoteTables,
/// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`].
pub reducers: RemoteReducers,
/// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`].
pub procedures: RemoteProcedures,
/// The event which caused these callbacks to run.
pub event: __sdk::Event<Reducer>,
imp: __sdk::DbContextImpl<RemoteModule>,
}
impl __sdk::AbstractEventContext for EventContext {
type Event = __sdk::Event<Reducer>;
fn event(&self) -> &Self::Event {
&self.event
}
fn new(imp: __sdk::DbContextImpl<RemoteModule>, event: Self::Event) -> Self {
Self {
db: RemoteTables { imp: imp.clone() },
reducers: RemoteReducers { imp: imp.clone() },
procedures: RemoteProcedures { imp: imp.clone() },
event,
imp,
}
}
}
impl __sdk::InModule for EventContext {
type Module = RemoteModule;
}
impl __sdk::DbContext for EventContext {
type DbView = RemoteTables;
type Reducers = RemoteReducers;
type Procedures = RemoteProcedures;
fn db(&self) -> &Self::DbView {
&self.db
}
fn reducers(&self) -> &Self::Reducers {
&self.reducers
}
fn procedures(&self) -> &Self::Procedures {
&self.procedures
}
fn is_active(&self) -> bool {
self.imp.is_active()
}
fn disconnect(&self) -> __sdk::Result<()> {
self.imp.disconnect()
}
type SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>;
fn subscription_builder(&self) -> Self::SubscriptionBuilder {
__sdk::SubscriptionBuilder::new(&self.imp)
}
fn try_identity(&self) -> Option<__sdk::Identity> {
self.imp.try_identity()
}
fn connection_id(&self) -> __sdk::ConnectionId {
self.imp.connection_id()
}
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {
self.imp.try_connection_id()
}
}
impl __sdk::EventContext for EventContext {}
/// An [`__sdk::DbContext`] augmented with a [`__sdk::ReducerEvent`],
/// passed to on-reducer callbacks.
pub struct ReducerEventContext {
/// Access to tables defined by the module via extension traits implemented for [`RemoteTables`].
pub db: RemoteTables,
/// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`].
pub reducers: RemoteReducers,
/// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`].
pub procedures: RemoteProcedures,
/// The event which caused these callbacks to run.
pub event: __sdk::ReducerEvent<Reducer>,
imp: __sdk::DbContextImpl<RemoteModule>,
}
impl __sdk::AbstractEventContext for ReducerEventContext {
type Event = __sdk::ReducerEvent<Reducer>;
fn event(&self) -> &Self::Event {
&self.event
}
fn new(imp: __sdk::DbContextImpl<RemoteModule>, event: Self::Event) -> Self {
Self {
db: RemoteTables { imp: imp.clone() },
reducers: RemoteReducers { imp: imp.clone() },
procedures: RemoteProcedures { imp: imp.clone() },
event,
imp,
}
}
}
impl __sdk::InModule for ReducerEventContext {
type Module = RemoteModule;
}
impl __sdk::DbContext for ReducerEventContext {
type DbView = RemoteTables;
type Reducers = RemoteReducers;
type Procedures = RemoteProcedures;
fn db(&self) -> &Self::DbView {
&self.db
}
fn reducers(&self) -> &Self::Reducers {
&self.reducers
}
fn procedures(&self) -> &Self::Procedures {
&self.procedures
}
fn is_active(&self) -> bool {
self.imp.is_active()
}
fn disconnect(&self) -> __sdk::Result<()> {
self.imp.disconnect()
}
type SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>;
fn subscription_builder(&self) -> Self::SubscriptionBuilder {
__sdk::SubscriptionBuilder::new(&self.imp)
}
fn try_identity(&self) -> Option<__sdk::Identity> {
self.imp.try_identity()
}
fn connection_id(&self) -> __sdk::ConnectionId {
self.imp.connection_id()
}
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {
self.imp.try_connection_id()
}
}
impl __sdk::ReducerEventContext for ReducerEventContext {}
/// An [`__sdk::DbContext`] passed to procedure callbacks.
pub struct ProcedureEventContext {
/// Access to tables defined by the module via extension traits implemented for [`RemoteTables`].
pub db: RemoteTables,
/// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`].
pub reducers: RemoteReducers,
/// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`].
pub procedures: RemoteProcedures,
imp: __sdk::DbContextImpl<RemoteModule>,
}
impl __sdk::AbstractEventContext for ProcedureEventContext {
type Event = ();
fn event(&self) -> &Self::Event {
&()
}
fn new(imp: __sdk::DbContextImpl<RemoteModule>, _event: Self::Event) -> Self {
Self {
db: RemoteTables { imp: imp.clone() },
reducers: RemoteReducers { imp: imp.clone() },
procedures: RemoteProcedures { imp: imp.clone() },
imp,
}
}
}
impl __sdk::InModule for ProcedureEventContext {
type Module = RemoteModule;
}
impl __sdk::DbContext for ProcedureEventContext {
type DbView = RemoteTables;
type Reducers = RemoteReducers;
type Procedures = RemoteProcedures;
fn db(&self) -> &Self::DbView {
&self.db
}
fn reducers(&self) -> &Self::Reducers {
&self.reducers
}
fn procedures(&self) -> &Self::Procedures {
&self.procedures
}
fn is_active(&self) -> bool {
self.imp.is_active()
}
fn disconnect(&self) -> __sdk::Result<()> {
self.imp.disconnect()
}
type SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>;
fn subscription_builder(&self) -> Self::SubscriptionBuilder {
__sdk::SubscriptionBuilder::new(&self.imp)
}
fn try_identity(&self) -> Option<__sdk::Identity> {
self.imp.try_identity()
}
fn connection_id(&self) -> __sdk::ConnectionId {
self.imp.connection_id()
}
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {
self.imp.try_connection_id()
}
}
impl __sdk::ProcedureEventContext for ProcedureEventContext {}
/// An [`__sdk::DbContext`] passed to [`__sdk::SubscriptionBuilder::on_applied`] and [`SubscriptionHandle::unsubscribe_then`] callbacks.
pub struct SubscriptionEventContext {
/// Access to tables defined by the module via extension traits implemented for [`RemoteTables`].
pub db: RemoteTables,
/// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`].
pub reducers: RemoteReducers,
/// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`].
pub procedures: RemoteProcedures,
imp: __sdk::DbContextImpl<RemoteModule>,
}
impl __sdk::AbstractEventContext for SubscriptionEventContext {
type Event = ();
fn event(&self) -> &Self::Event {
&()
}
fn new(imp: __sdk::DbContextImpl<RemoteModule>, _event: Self::Event) -> Self {
Self {
db: RemoteTables { imp: imp.clone() },
reducers: RemoteReducers { imp: imp.clone() },
procedures: RemoteProcedures { imp: imp.clone() },
imp,
}
}
}
impl __sdk::InModule for SubscriptionEventContext {
type Module = RemoteModule;
}
impl __sdk::DbContext for SubscriptionEventContext {
type DbView = RemoteTables;
type Reducers = RemoteReducers;
type Procedures = RemoteProcedures;
fn db(&self) -> &Self::DbView {
&self.db
}
fn reducers(&self) -> &Self::Reducers {
&self.reducers
}
fn procedures(&self) -> &Self::Procedures {
&self.procedures
}
fn is_active(&self) -> bool {
self.imp.is_active()
}
fn disconnect(&self) -> __sdk::Result<()> {
self.imp.disconnect()
}
type SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>;
fn subscription_builder(&self) -> Self::SubscriptionBuilder {
__sdk::SubscriptionBuilder::new(&self.imp)
}
fn try_identity(&self) -> Option<__sdk::Identity> {
self.imp.try_identity()
}
fn connection_id(&self) -> __sdk::ConnectionId {
self.imp.connection_id()
}
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {
self.imp.try_connection_id()
}
}
impl __sdk::SubscriptionEventContext for SubscriptionEventContext {}
/// An [`__sdk::DbContext`] augmented with a [`__sdk::Error`],
/// passed to [`__sdk::DbConnectionBuilder::on_disconnect`], [`__sdk::DbConnectionBuilder::on_connect_error`] and [`__sdk::SubscriptionBuilder::on_error`] callbacks.
pub struct ErrorContext {
/// Access to tables defined by the module via extension traits implemented for [`RemoteTables`].
pub db: RemoteTables,
/// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`].
pub reducers: RemoteReducers,
/// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`].
pub procedures: RemoteProcedures,
/// The event which caused these callbacks to run.
pub event: Option<__sdk::Error>,
imp: __sdk::DbContextImpl<RemoteModule>,
}
impl __sdk::AbstractEventContext for ErrorContext {
type Event = Option<__sdk::Error>;
fn event(&self) -> &Self::Event {
&self.event
}
fn new(imp: __sdk::DbContextImpl<RemoteModule>, event: Self::Event) -> Self {
Self {
db: RemoteTables { imp: imp.clone() },
reducers: RemoteReducers { imp: imp.clone() },
procedures: RemoteProcedures { imp: imp.clone() },
event,
imp,
}
}
}
impl __sdk::InModule for ErrorContext {
type Module = RemoteModule;
}
impl __sdk::DbContext for ErrorContext {
type DbView = RemoteTables;
type Reducers = RemoteReducers;
type Procedures = RemoteProcedures;
fn db(&self) -> &Self::DbView {
&self.db
}
fn reducers(&self) -> &Self::Reducers {
&self.reducers
}
fn procedures(&self) -> &Self::Procedures {
&self.procedures
}
fn is_active(&self) -> bool {
self.imp.is_active()
}
fn disconnect(&self) -> __sdk::Result<()> {
self.imp.disconnect()
}
type SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>;
fn subscription_builder(&self) -> Self::SubscriptionBuilder {
__sdk::SubscriptionBuilder::new(&self.imp)
}
fn try_identity(&self) -> Option<__sdk::Identity> {
self.imp.try_identity()
}
fn connection_id(&self) -> __sdk::ConnectionId {
self.imp.connection_id()
}
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {
self.imp.try_connection_id()
}
}
impl __sdk::ErrorContext for ErrorContext {}
impl __sdk::SpacetimeModule for RemoteModule {
type DbConnection = DbConnection;
type EventContext = EventContext;
type ReducerEventContext = ReducerEventContext;
type ProcedureEventContext = ProcedureEventContext;
type SubscriptionEventContext = SubscriptionEventContext;
type ErrorContext = ErrorContext;
type Reducer = Reducer;
type DbView = RemoteTables;
type Reducers = RemoteReducers;
type Procedures = RemoteProcedures;
type DbUpdate = DbUpdate;
type AppliedDiff<'r> = AppliedDiff<'r>;
type SubscriptionHandle = SubscriptionHandle;
type QueryBuilder = __sdk::QueryBuilder;
fn register_tables(client_cache: &mut __sdk::ClientCache<Self>) {}
const ALL_TABLE_NAMES: &'static [&'static str] = &[];
}