mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-05-06 15:49:35 -04:00
6882232108
# Description of Changes
In the Rust client SDK, with this PR, doing
`.with_debug_to_file("path.txt")` on the connection builder will result
in the SDK logging additional verbose info to `path.txt`.
# API and ABI breaking changes
Adds a new user-facing-ish API to the Rust client SDK.
# Expected complexity level and risk
2? Some possibility of deadlock due to adding a new mutex, but this is
explicitly not for production use.
# Testing
- [x] Ran `chat-console-rs` locally with this enabled and got some debug
logs out of it.
783 lines
25 KiB
Rust
Generated
783 lines
25 KiB
Rust
Generated
// 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.0.4 (commit 912be0bbc1fedbe62ab968e1a0775235ab7f650d).
|
|
|
|
#![allow(unused, clippy::all)]
|
|
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
|
|
|
pub mod add_reducer;
|
|
pub mod person_table;
|
|
pub mod person_type;
|
|
pub mod say_hello_reducer;
|
|
|
|
pub use add_reducer::add;
|
|
pub use person_table::*;
|
|
pub use person_type::Person;
|
|
pub use say_hello_reducer::say_hello;
|
|
|
|
#[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 {
|
|
Add { name: String },
|
|
SayHello,
|
|
}
|
|
|
|
impl __sdk::InModule for Reducer {
|
|
type Module = RemoteModule;
|
|
}
|
|
|
|
impl __sdk::Reducer for Reducer {
|
|
fn reducer_name(&self) -> &'static str {
|
|
match self {
|
|
Reducer::Add { .. } => "add",
|
|
Reducer::SayHello => "say_hello",
|
|
_ => unreachable!(),
|
|
}
|
|
}
|
|
#[allow(clippy::clone_on_copy)]
|
|
fn args_bsatn(&self) -> Result<Vec<u8>, __sats::bsatn::EncodeError> {
|
|
match self {
|
|
Reducer::Add { name } => __sats::bsatn::to_vec(&add_reducer::AddArgs { name: name.clone() }),
|
|
Reducer::SayHello => __sats::bsatn::to_vec(&say_hello_reducer::SayHelloArgs {}),
|
|
_ => unreachable!(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Default, Debug)]
|
|
#[allow(non_snake_case)]
|
|
#[doc(hidden)]
|
|
pub struct DbUpdate {
|
|
person: __sdk::TableUpdate<Person>,
|
|
}
|
|
|
|
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[..] {
|
|
"person" => db_update.person.append(person_table::parse_table_update(table_update)?),
|
|
|
|
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.person = cache.apply_diff_to_table::<Person>("person", &self.person);
|
|
|
|
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[..] {
|
|
"person" => db_update
|
|
.person
|
|
.append(__sdk::parse_row_list_as_inserts(table_rows.rows)?),
|
|
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[..] {
|
|
"person" => db_update
|
|
.person
|
|
.append(__sdk::parse_row_list_as_deletes(table_rows.rows)?),
|
|
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> {
|
|
person: __sdk::TableAppliedDiff<'r, Person>,
|
|
__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>) {
|
|
callbacks.invoke_table_row_callbacks::<Person>("person", &self.person, event);
|
|
}
|
|
}
|
|
|
|
#[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`].
|
|
/// - [`DbConnection::run_threaded`].
|
|
/// - [`DbConnection::run_async`].
|
|
/// - [`DbConnection::advance_one_message`].
|
|
/// - [`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.
|
|
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.
|
|
pub fn run_threaded(&self) -> std::thread::JoinHandle<()> {
|
|
self.imp.run_threaded()
|
|
}
|
|
|
|
/// 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>) {
|
|
person_table::register_table(client_cache);
|
|
}
|
|
const ALL_TABLE_NAMES: &'static [&'static str] = &["person"];
|
|
}
|