mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-05-07 08:10:42 -04:00
c0442ea146
# Description of Changes Basic tests for templates, the test tries to generate each of the template, build and publish the SpacetimeDB part, and build or type check the client side. This PR also includes bindings for all of the clients as it's needed for the tests to work and given the choices to either generate during the test run or include the bindings in git we chose the latter. This makes it consistent across the templates as some of them already included bindings. # Expected complexity level and risk 1 --------- Co-authored-by: clockwork-labs-bot <clockwork-labs-bot@users.noreply.github.com> Co-authored-by: rekhoff <r.ekhoff@clockworklabs.io>
630 lines
25 KiB
C#
Generated
630 lines
25 KiB
C#
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.0 (commit 5183461758f0c9cb05138a5054c947a7aeb8497e).
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
using SpacetimeDB.ClientApi;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.Serialization;
|
|
|
|
namespace SpacetimeDB.Types
|
|
{
|
|
public sealed partial class RemoteReducers : RemoteBase
|
|
{
|
|
internal RemoteReducers(DbConnection conn) : base(conn) { }
|
|
internal event Action<ReducerEventContext, Exception>? InternalOnUnhandledReducerError;
|
|
}
|
|
|
|
public sealed partial class RemoteProcedures : RemoteBase
|
|
{
|
|
internal RemoteProcedures(DbConnection conn) : base(conn) { }
|
|
}
|
|
|
|
public sealed partial class RemoteTables : RemoteTablesBase
|
|
{
|
|
public RemoteTables(DbConnection conn)
|
|
{
|
|
AddTable(Person = new(conn));
|
|
}
|
|
}
|
|
|
|
|
|
public interface IRemoteDbContext : IDbContext<RemoteTables, RemoteReducers, SubscriptionBuilder, RemoteProcedures>
|
|
{
|
|
public event Action<ReducerEventContext, Exception>? OnUnhandledReducerError;
|
|
}
|
|
|
|
public sealed class EventContext : IEventContext, IRemoteDbContext
|
|
{
|
|
private readonly DbConnection conn;
|
|
|
|
/// <summary>
|
|
/// The event that caused this callback to run.
|
|
/// </summary>
|
|
public readonly Event<Reducer> Event;
|
|
|
|
/// <summary>
|
|
/// Access to tables in the client cache, which stores a read-only replica of the remote database state.
|
|
///
|
|
/// The returned <c>DbView</c> will have a method to access each table defined by the module.
|
|
/// </summary>
|
|
public RemoteTables Db => conn.Db;
|
|
/// <summary>
|
|
/// Access to reducers defined by the module.
|
|
///
|
|
/// The returned <c>RemoteReducers</c> will have a method to invoke each reducer defined by the module,
|
|
/// plus methods for adding and removing callbacks on each of those reducers.
|
|
/// </summary>
|
|
public RemoteReducers Reducers => conn.Reducers;
|
|
/// <summary>
|
|
/// Access to procedures defined by the module.
|
|
///
|
|
/// The returned <c>RemoteProcedures</c> will have a method to invoke each procedure defined by the module,
|
|
/// with a callback for when the procedure completes and returns a value.
|
|
/// </summary>
|
|
public RemoteProcedures Procedures => conn.Procedures;
|
|
/// <summary>
|
|
/// Returns <c>true</c> if the connection is active, i.e. has not yet disconnected.
|
|
/// </summary>
|
|
public bool IsActive => conn.IsActive;
|
|
/// <summary>
|
|
/// Close the connection.
|
|
///
|
|
/// Throws an error if the connection is already closed.
|
|
/// </summary>
|
|
public void Disconnect()
|
|
{
|
|
conn.Disconnect();
|
|
}
|
|
/// <summary>
|
|
/// Start building a subscription.
|
|
/// </summary>
|
|
/// <returns>A builder-pattern constructor for subscribing to queries,
|
|
/// causing matching rows to be replicated into the client cache.</returns>
|
|
public SubscriptionBuilder SubscriptionBuilder() => conn.SubscriptionBuilder();
|
|
/// <summary>
|
|
/// Get the <c>Identity</c> of this connection.
|
|
///
|
|
/// This method returns null if the connection was constructed anonymously
|
|
/// and we have not yet received our newly-generated <c>Identity</c> from the host.
|
|
/// </summary>
|
|
public Identity? Identity => conn.Identity;
|
|
/// <summary>
|
|
/// Get this connection's <c>ConnectionId</c>.
|
|
/// </summary>
|
|
public ConnectionId ConnectionId => conn.ConnectionId;
|
|
/// <summary>
|
|
/// Register a callback to be called when a reducer with no handler returns an error.
|
|
/// </summary>
|
|
public event Action<ReducerEventContext, Exception>? OnUnhandledReducerError
|
|
{
|
|
add => Reducers.InternalOnUnhandledReducerError += value;
|
|
remove => Reducers.InternalOnUnhandledReducerError -= value;
|
|
}
|
|
|
|
internal EventContext(DbConnection conn, Event<Reducer> Event)
|
|
{
|
|
this.conn = conn;
|
|
this.Event = Event;
|
|
}
|
|
}
|
|
|
|
public sealed class ReducerEventContext : IReducerEventContext, IRemoteDbContext
|
|
{
|
|
private readonly DbConnection conn;
|
|
/// <summary>
|
|
/// The reducer event that caused this callback to run.
|
|
/// </summary>
|
|
public readonly ReducerEvent<Reducer> Event;
|
|
|
|
/// <summary>
|
|
/// Access to tables in the client cache, which stores a read-only replica of the remote database state.
|
|
///
|
|
/// The returned <c>DbView</c> will have a method to access each table defined by the module.
|
|
/// </summary>
|
|
public RemoteTables Db => conn.Db;
|
|
/// <summary>
|
|
/// Access to reducers defined by the module.
|
|
///
|
|
/// The returned <c>RemoteReducers</c> will have a method to invoke each reducer defined by the module,
|
|
/// plus methods for adding and removing callbacks on each of those reducers.
|
|
/// </summary>
|
|
public RemoteReducers Reducers => conn.Reducers;
|
|
/// <summary>
|
|
/// Access to procedures defined by the module.
|
|
///
|
|
/// The returned <c>RemoteProcedures</c> will have a method to invoke each procedure defined by the module,
|
|
/// with a callback for when the procedure completes and returns a value.
|
|
/// </summary>
|
|
public RemoteProcedures Procedures => conn.Procedures;
|
|
/// <summary>
|
|
/// Returns <c>true</c> if the connection is active, i.e. has not yet disconnected.
|
|
/// </summary>
|
|
public bool IsActive => conn.IsActive;
|
|
/// <summary>
|
|
/// Close the connection.
|
|
///
|
|
/// Throws an error if the connection is already closed.
|
|
/// </summary>
|
|
public void Disconnect()
|
|
{
|
|
conn.Disconnect();
|
|
}
|
|
/// <summary>
|
|
/// Start building a subscription.
|
|
/// </summary>
|
|
/// <returns>A builder-pattern constructor for subscribing to queries,
|
|
/// causing matching rows to be replicated into the client cache.</returns>
|
|
public SubscriptionBuilder SubscriptionBuilder() => conn.SubscriptionBuilder();
|
|
/// <summary>
|
|
/// Get the <c>Identity</c> of this connection.
|
|
///
|
|
/// This method returns null if the connection was constructed anonymously
|
|
/// and we have not yet received our newly-generated <c>Identity</c> from the host.
|
|
/// </summary>
|
|
public Identity? Identity => conn.Identity;
|
|
/// <summary>
|
|
/// Get this connection's <c>ConnectionId</c>.
|
|
/// </summary>
|
|
public ConnectionId ConnectionId => conn.ConnectionId;
|
|
/// <summary>
|
|
/// Register a callback to be called when a reducer with no handler returns an error.
|
|
/// </summary>
|
|
public event Action<ReducerEventContext, Exception>? OnUnhandledReducerError
|
|
{
|
|
add => Reducers.InternalOnUnhandledReducerError += value;
|
|
remove => Reducers.InternalOnUnhandledReducerError -= value;
|
|
}
|
|
|
|
internal ReducerEventContext(DbConnection conn, ReducerEvent<Reducer> reducerEvent)
|
|
{
|
|
this.conn = conn;
|
|
Event = reducerEvent;
|
|
}
|
|
}
|
|
|
|
public sealed class ErrorContext : IErrorContext, IRemoteDbContext
|
|
{
|
|
private readonly DbConnection conn;
|
|
/// <summary>
|
|
/// The <c>Exception</c> that caused this error callback to be run.
|
|
/// </summary>
|
|
public readonly Exception Event;
|
|
Exception IErrorContext.Event
|
|
{
|
|
get
|
|
{
|
|
return Event;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Access to tables in the client cache, which stores a read-only replica of the remote database state.
|
|
///
|
|
/// The returned <c>DbView</c> will have a method to access each table defined by the module.
|
|
/// </summary>
|
|
public RemoteTables Db => conn.Db;
|
|
/// <summary>
|
|
/// Access to reducers defined by the module.
|
|
///
|
|
/// The returned <c>RemoteReducers</c> will have a method to invoke each reducer defined by the module,
|
|
/// plus methods for adding and removing callbacks on each of those reducers.
|
|
/// </summary>
|
|
public RemoteReducers Reducers => conn.Reducers;
|
|
/// <summary>
|
|
/// Access to procedures defined by the module.
|
|
///
|
|
/// The returned <c>RemoteProcedures</c> will have a method to invoke each procedure defined by the module,
|
|
/// with a callback for when the procedure completes and returns a value.
|
|
/// </summary>
|
|
public RemoteProcedures Procedures => conn.Procedures;
|
|
/// <summary>
|
|
/// Returns <c>true</c> if the connection is active, i.e. has not yet disconnected.
|
|
/// </summary>
|
|
public bool IsActive => conn.IsActive;
|
|
/// <summary>
|
|
/// Close the connection.
|
|
///
|
|
/// Throws an error if the connection is already closed.
|
|
/// </summary>
|
|
public void Disconnect()
|
|
{
|
|
conn.Disconnect();
|
|
}
|
|
/// <summary>
|
|
/// Start building a subscription.
|
|
/// </summary>
|
|
/// <returns>A builder-pattern constructor for subscribing to queries,
|
|
/// causing matching rows to be replicated into the client cache.</returns>
|
|
public SubscriptionBuilder SubscriptionBuilder() => conn.SubscriptionBuilder();
|
|
/// <summary>
|
|
/// Get the <c>Identity</c> of this connection.
|
|
///
|
|
/// This method returns null if the connection was constructed anonymously
|
|
/// and we have not yet received our newly-generated <c>Identity</c> from the host.
|
|
/// </summary>
|
|
public Identity? Identity => conn.Identity;
|
|
/// <summary>
|
|
/// Get this connection's <c>ConnectionId</c>.
|
|
/// </summary>
|
|
public ConnectionId ConnectionId => conn.ConnectionId;
|
|
/// <summary>
|
|
/// Register a callback to be called when a reducer with no handler returns an error.
|
|
/// </summary>
|
|
public event Action<ReducerEventContext, Exception>? OnUnhandledReducerError
|
|
{
|
|
add => Reducers.InternalOnUnhandledReducerError += value;
|
|
remove => Reducers.InternalOnUnhandledReducerError -= value;
|
|
}
|
|
|
|
internal ErrorContext(DbConnection conn, Exception error)
|
|
{
|
|
this.conn = conn;
|
|
Event = error;
|
|
}
|
|
}
|
|
|
|
public sealed class SubscriptionEventContext : ISubscriptionEventContext, IRemoteDbContext
|
|
{
|
|
private readonly DbConnection conn;
|
|
|
|
/// <summary>
|
|
/// Access to tables in the client cache, which stores a read-only replica of the remote database state.
|
|
///
|
|
/// The returned <c>DbView</c> will have a method to access each table defined by the module.
|
|
/// </summary>
|
|
public RemoteTables Db => conn.Db;
|
|
/// <summary>
|
|
/// Access to reducers defined by the module.
|
|
///
|
|
/// The returned <c>RemoteReducers</c> will have a method to invoke each reducer defined by the module,
|
|
/// plus methods for adding and removing callbacks on each of those reducers.
|
|
/// </summary>
|
|
public RemoteReducers Reducers => conn.Reducers;
|
|
/// <summary>
|
|
/// Access to procedures defined by the module.
|
|
///
|
|
/// The returned <c>RemoteProcedures</c> will have a method to invoke each procedure defined by the module,
|
|
/// with a callback for when the procedure completes and returns a value.
|
|
/// </summary>
|
|
public RemoteProcedures Procedures => conn.Procedures;
|
|
/// <summary>
|
|
/// Returns <c>true</c> if the connection is active, i.e. has not yet disconnected.
|
|
/// </summary>
|
|
public bool IsActive => conn.IsActive;
|
|
/// <summary>
|
|
/// Close the connection.
|
|
///
|
|
/// Throws an error if the connection is already closed.
|
|
/// </summary>
|
|
public void Disconnect()
|
|
{
|
|
conn.Disconnect();
|
|
}
|
|
/// <summary>
|
|
/// Start building a subscription.
|
|
/// </summary>
|
|
/// <returns>A builder-pattern constructor for subscribing to queries,
|
|
/// causing matching rows to be replicated into the client cache.</returns>
|
|
public SubscriptionBuilder SubscriptionBuilder() => conn.SubscriptionBuilder();
|
|
/// <summary>
|
|
/// Get the <c>Identity</c> of this connection.
|
|
///
|
|
/// This method returns null if the connection was constructed anonymously
|
|
/// and we have not yet received our newly-generated <c>Identity</c> from the host.
|
|
/// </summary>
|
|
public Identity? Identity => conn.Identity;
|
|
/// <summary>
|
|
/// Get this connection's <c>ConnectionId</c>.
|
|
/// </summary>
|
|
public ConnectionId ConnectionId => conn.ConnectionId;
|
|
/// <summary>
|
|
/// Register a callback to be called when a reducer with no handler returns an error.
|
|
/// </summary>
|
|
public event Action<ReducerEventContext, Exception>? OnUnhandledReducerError
|
|
{
|
|
add => Reducers.InternalOnUnhandledReducerError += value;
|
|
remove => Reducers.InternalOnUnhandledReducerError -= value;
|
|
}
|
|
|
|
internal SubscriptionEventContext(DbConnection conn)
|
|
{
|
|
this.conn = conn;
|
|
}
|
|
}
|
|
|
|
public sealed class ProcedureEventContext : IProcedureEventContext, IRemoteDbContext
|
|
{
|
|
private readonly DbConnection conn;
|
|
/// <summary>
|
|
/// The procedure event that caused this callback to run.
|
|
/// </summary>
|
|
public readonly ProcedureEvent Event;
|
|
|
|
/// <summary>
|
|
/// Access to tables in the client cache, which stores a read-only replica of the remote database state.
|
|
///
|
|
/// The returned <c>DbView</c> will have a method to access each table defined by the module.
|
|
/// </summary>
|
|
public RemoteTables Db => conn.Db;
|
|
/// <summary>
|
|
/// Access to reducers defined by the module.
|
|
///
|
|
/// The returned <c>RemoteReducers</c> will have a method to invoke each reducer defined by the module,
|
|
/// plus methods for adding and removing callbacks on each of those reducers.
|
|
/// </summary>
|
|
public RemoteReducers Reducers => conn.Reducers;
|
|
/// <summary>
|
|
/// Access to procedures defined by the module.
|
|
///
|
|
/// The returned <c>RemoteProcedures</c> will have a method to invoke each procedure defined by the module,
|
|
/// with a callback for when the procedure completes and returns a value.
|
|
/// </summary>
|
|
public RemoteProcedures Procedures => conn.Procedures;
|
|
/// <summary>
|
|
/// Returns <c>true</c> if the connection is active, i.e. has not yet disconnected.
|
|
/// </summary>
|
|
public bool IsActive => conn.IsActive;
|
|
/// <summary>
|
|
/// Close the connection.
|
|
///
|
|
/// Throws an error if the connection is already closed.
|
|
/// </summary>
|
|
public void Disconnect()
|
|
{
|
|
conn.Disconnect();
|
|
}
|
|
/// <summary>
|
|
/// Start building a subscription.
|
|
/// </summary>
|
|
/// <returns>A builder-pattern constructor for subscribing to queries,
|
|
/// causing matching rows to be replicated into the client cache.</returns>
|
|
public SubscriptionBuilder SubscriptionBuilder() => conn.SubscriptionBuilder();
|
|
/// <summary>
|
|
/// Get the <c>Identity</c> of this connection.
|
|
///
|
|
/// This method returns null if the connection was constructed anonymously
|
|
/// and we have not yet received our newly-generated <c>Identity</c> from the host.
|
|
/// </summary>
|
|
public Identity? Identity => conn.Identity;
|
|
/// <summary>
|
|
/// Get this connection's <c>ConnectionId</c>.
|
|
/// </summary>
|
|
public ConnectionId ConnectionId => conn.ConnectionId;
|
|
/// <summary>
|
|
/// Register a callback to be called when a reducer with no handler returns an error.
|
|
/// </summary>
|
|
public event Action<ReducerEventContext, Exception>? OnUnhandledReducerError
|
|
{
|
|
add => Reducers.InternalOnUnhandledReducerError += value;
|
|
remove => Reducers.InternalOnUnhandledReducerError -= value;
|
|
}
|
|
|
|
internal ProcedureEventContext(DbConnection conn, ProcedureEvent Event)
|
|
{
|
|
this.conn = conn;
|
|
this.Event = Event;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Builder-pattern constructor for subscription queries.
|
|
/// </summary>
|
|
public sealed class SubscriptionBuilder
|
|
{
|
|
private readonly IDbConnection conn;
|
|
|
|
private event Action<SubscriptionEventContext>? Applied;
|
|
private event Action<ErrorContext, Exception>? Error;
|
|
|
|
/// <summary>
|
|
/// Private API, use <c>conn.SubscriptionBuilder()</c> instead.
|
|
/// </summary>
|
|
public SubscriptionBuilder(IDbConnection conn)
|
|
{
|
|
this.conn = conn;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register a callback to run when the subscription is applied.
|
|
/// </summary>
|
|
public SubscriptionBuilder OnApplied(
|
|
Action<SubscriptionEventContext> callback
|
|
)
|
|
{
|
|
Applied += callback;
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register a callback to run when the subscription fails.
|
|
///
|
|
/// Note that this callback may run either when attempting to apply the subscription,
|
|
/// in which case <c>Self::on_applied</c> will never run,
|
|
/// or later during the subscription's lifetime if the module's interface changes,
|
|
/// in which case <c>Self::on_applied</c> may have already run.
|
|
/// </summary>
|
|
public SubscriptionBuilder OnError(
|
|
Action<ErrorContext, Exception> callback
|
|
)
|
|
{
|
|
Error += callback;
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a typed query to this subscription.
|
|
///
|
|
/// This is the entry point for building subscriptions without writing SQL by hand.
|
|
/// Once a typed query is added, only typed queries may follow (SQL and typed queries cannot be mixed).
|
|
/// </summary>
|
|
public TypedSubscriptionBuilder AddQuery<TRow>(
|
|
Func<QueryBuilder, global::SpacetimeDB.IQuery<TRow>> build
|
|
)
|
|
{
|
|
var typed = new TypedSubscriptionBuilder(conn, Applied, Error);
|
|
return typed.AddQuery(build);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Subscribe to the following SQL queries.
|
|
///
|
|
/// This method returns immediately, with the data not yet added to the DbConnection.
|
|
/// The provided callbacks will be invoked once the data is returned from the remote server.
|
|
/// Data from all the provided queries will be returned at the same time.
|
|
///
|
|
/// See the SpacetimeDB SQL docs for more information on SQL syntax:
|
|
/// <a href="https://spacetimedb.com/docs/sql">https://spacetimedb.com/docs/sql</a>
|
|
/// </summary>
|
|
public SubscriptionHandle Subscribe(
|
|
string[] querySqls
|
|
) => new(conn, Applied, Error, querySqls);
|
|
|
|
/// <summary>
|
|
/// Subscribe to all rows from all tables.
|
|
///
|
|
/// This method is intended as a convenience
|
|
/// for applications where client-side memory use and network bandwidth are not concerns.
|
|
/// Applications where these resources are a constraint
|
|
/// should register more precise queries via <c>Self.Subscribe</c>
|
|
/// in order to replicate only the subset of data which the client needs to function.
|
|
///
|
|
/// This method should not be combined with <c>Self.Subscribe</c> on the same <c>DbConnection</c>.
|
|
/// A connection may either <c>Self.Subscribe</c> to particular queries,
|
|
/// or <c>Self.SubscribeToAllTables</c>, but not both.
|
|
/// Attempting to call <c>Self.Subscribe</c>
|
|
/// on a <c>DbConnection</c> that has previously used <c>Self.SubscribeToAllTables</c>,
|
|
/// or vice versa, may misbehave in any number of ways,
|
|
/// including dropping subscriptions, corrupting the client cache, or panicking.
|
|
/// </summary>
|
|
public SubscriptionHandle SubscribeToAllTables() =>
|
|
new(conn, Applied, Error, QueryBuilder.AllTablesSqlQueries());
|
|
}
|
|
|
|
public sealed class SubscriptionHandle : SubscriptionHandleBase<SubscriptionEventContext, ErrorContext>
|
|
{
|
|
/// <summary>
|
|
/// Internal API. Construct <c>SubscriptionHandle</c>s using <c>conn.SubscriptionBuilder</c>.
|
|
/// </summary>
|
|
public SubscriptionHandle(
|
|
IDbConnection conn,
|
|
Action<SubscriptionEventContext>? onApplied,
|
|
Action<ErrorContext, Exception>? onError,
|
|
string[] querySqls
|
|
) : base(conn, onApplied, onError, querySqls)
|
|
{ }
|
|
}
|
|
|
|
public sealed class QueryBuilder
|
|
{
|
|
public From From { get; } = new();
|
|
|
|
internal static string[] AllTablesSqlQueries() => new string[]
|
|
{
|
|
new QueryBuilder().From.Person().ToSql(),
|
|
}
|
|
;
|
|
}
|
|
|
|
public sealed class From
|
|
{
|
|
public global::SpacetimeDB.Table<Person, PersonCols, PersonIxCols> Person() => new("Person", new PersonCols("Person"), new PersonIxCols("Person"));
|
|
}
|
|
|
|
public sealed class TypedSubscriptionBuilder
|
|
{
|
|
private readonly IDbConnection conn;
|
|
private Action<SubscriptionEventContext>? Applied;
|
|
private Action<ErrorContext, Exception>? Error;
|
|
private readonly List<string> querySqls = new();
|
|
|
|
internal TypedSubscriptionBuilder(IDbConnection conn, Action<SubscriptionEventContext>? applied, Action<ErrorContext, Exception>? error)
|
|
{
|
|
this.conn = conn;
|
|
Applied = applied;
|
|
Error = error;
|
|
}
|
|
|
|
public TypedSubscriptionBuilder OnApplied(Action<SubscriptionEventContext> callback)
|
|
{
|
|
Applied += callback;
|
|
return this;
|
|
}
|
|
|
|
public TypedSubscriptionBuilder OnError(Action<ErrorContext, Exception> callback)
|
|
{
|
|
Error += callback;
|
|
return this;
|
|
}
|
|
|
|
public TypedSubscriptionBuilder AddQuery<TRow>(Func<QueryBuilder, global::SpacetimeDB.IQuery<TRow>> build)
|
|
{
|
|
var qb = new QueryBuilder();
|
|
querySqls.Add(build(qb).ToSql());
|
|
return this;
|
|
}
|
|
|
|
public SubscriptionHandle Subscribe() => new(conn, Applied, Error, querySqls.ToArray());
|
|
}
|
|
|
|
public abstract partial class Reducer
|
|
{
|
|
private Reducer() { }
|
|
}
|
|
|
|
public abstract partial class Procedure
|
|
{
|
|
private Procedure() { }
|
|
}
|
|
|
|
public sealed class DbConnection : DbConnectionBase<DbConnection, RemoteTables, Reducer>
|
|
{
|
|
public override RemoteTables Db { get; }
|
|
public readonly RemoteReducers Reducers;
|
|
public readonly RemoteProcedures Procedures;
|
|
|
|
public DbConnection()
|
|
{
|
|
Db = new(this);
|
|
Reducers = new(this);
|
|
Procedures = new(this);
|
|
}
|
|
|
|
protected override IEventContext ToEventContext(Event<Reducer> Event) =>
|
|
new EventContext(this, Event);
|
|
|
|
protected override IReducerEventContext ToReducerEventContext(ReducerEvent<Reducer> reducerEvent) =>
|
|
new ReducerEventContext(this, reducerEvent);
|
|
|
|
protected override ISubscriptionEventContext MakeSubscriptionEventContext() =>
|
|
new SubscriptionEventContext(this);
|
|
|
|
protected override IErrorContext ToErrorContext(Exception exception) =>
|
|
new ErrorContext(this, exception);
|
|
|
|
protected override IProcedureEventContext ToProcedureEventContext(ProcedureEvent procedureEvent) =>
|
|
new ProcedureEventContext(this, procedureEvent);
|
|
|
|
protected override bool Dispatch(IReducerEventContext context, Reducer reducer)
|
|
{
|
|
var eventContext = (ReducerEventContext)context;
|
|
return reducer switch
|
|
{
|
|
Reducer.Add args => Reducers.InvokeAdd(eventContext, args),
|
|
Reducer.SayHello args => Reducers.InvokeSayHello(eventContext, args),
|
|
_ => throw new ArgumentOutOfRangeException("Reducer", $"Unknown reducer {reducer}")
|
|
};
|
|
}
|
|
|
|
public SubscriptionBuilder SubscriptionBuilder() => new(this);
|
|
public event Action<ReducerEventContext, Exception> OnUnhandledReducerError
|
|
{
|
|
add => Reducers.InternalOnUnhandledReducerError += value;
|
|
remove => Reducers.InternalOnUnhandledReducerError -= value;
|
|
}
|
|
}
|
|
}
|