diff --git a/crates/cli/tests/snapshots/codegen__codegen_csharp.snap b/crates/cli/tests/snapshots/codegen__codegen_csharp.snap
index 959739efad8..53d35834fd1 100644
--- a/crates/cli/tests/snapshots/codegen__codegen_csharp.snap
+++ b/crates/cli/tests/snapshots/codegen__codegen_csharp.snap
@@ -16,7 +16,7 @@ namespace SpacetimeDB
[SpacetimeDB.Type]
public partial class AddPlayer : IReducerArgs
{
- string IReducerArgs.ReducerName => "add_player";
+ uint IReducerArgs.ReducerIndex => 2;
public string Name = "";
}
@@ -36,7 +36,7 @@ namespace SpacetimeDB
[SpacetimeDB.Type]
public partial class AddPrivate : IReducerArgs
{
- string IReducerArgs.ReducerName => "add_private";
+ uint IReducerArgs.ReducerIndex => 3;
public string Name = "";
}
@@ -91,7 +91,7 @@ namespace SpacetimeDB
[SpacetimeDB.Type]
public partial class DeletePlayer : IReducerArgs
{
- string IReducerArgs.ReducerName => "delete_player";
+ uint IReducerArgs.ReducerIndex => 4;
public ulong Id;
}
@@ -111,7 +111,7 @@ namespace SpacetimeDB
[SpacetimeDB.Type]
public partial class DeletePlayersByName : IReducerArgs
{
- string IReducerArgs.ReducerName => "delete_players_by_name";
+ uint IReducerArgs.ReducerIndex => 5;
public string Name = "";
}
@@ -176,6 +176,42 @@ namespace SpacetimeDB
}
}
'''
+"IdentityConnectedReducer.cs" = '''
+// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
+// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
+//
+
+#nullable enable
+
+using System;
+
+namespace SpacetimeDB
+{
+ [SpacetimeDB.Type]
+ public partial class IdentityConnected : IReducerArgs
+ {
+ uint IReducerArgs.ReducerIndex => 0;
+ }
+}
+'''
+"InitReducer.cs" = '''
+// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
+// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
+//
+
+#nullable enable
+
+using System;
+
+namespace SpacetimeDB
+{
+ [SpacetimeDB.Type]
+ public partial class Init : IReducerArgs
+ {
+ uint IReducerArgs.ReducerIndex => 1;
+ }
+}
+'''
"NamespaceTestC.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
@@ -351,7 +387,7 @@ namespace SpacetimeDB
[SpacetimeDB.Type]
public partial class QueryPrivate : IReducerArgs
{
- string IReducerArgs.ReducerName => "query_private";
+ uint IReducerArgs.ReducerIndex => 6;
}
}
'''
@@ -412,7 +448,7 @@ namespace SpacetimeDB
[SpacetimeDB.Type]
public partial class RepeatingTest : IReducerArgs
{
- string IReducerArgs.ReducerName => "repeating_test";
+ uint IReducerArgs.ReducerIndex => 7;
public SpacetimeDB.RepeatingTestArg Arg = new();
}
@@ -510,7 +546,7 @@ namespace SpacetimeDB
[SpacetimeDB.Type]
public partial class TestBtreeIndexArgs : IReducerArgs
{
- string IReducerArgs.ReducerName => "test_btree_index_args";
+ uint IReducerArgs.ReducerIndex => 9;
}
}
'''
@@ -636,7 +672,7 @@ namespace SpacetimeDB
[SpacetimeDB.Type]
public partial class Test : IReducerArgs
{
- string IReducerArgs.ReducerName => "test";
+ uint IReducerArgs.ReducerIndex => 8;
public SpacetimeDB.TestA Arg = new();
public SpacetimeDB.TestB Arg2 = new();
@@ -882,6 +918,38 @@ namespace SpacetimeDB
{
internal RemoteReducers(DbConnection conn, SetReducerFlags SetReducerFlags) : base(conn) { this.SetCallReducerFlags = SetReducerFlags; }
internal readonly SetReducerFlags SetCallReducerFlags;
+ public delegate void IdentityConnectedHandler(EventContext ctx);
+ public event IdentityConnectedHandler? OnIdentityConnected;
+
+ public void IdentityConnected()
+ {
+ conn.InternalCallReducer(new IdentityConnected { }, this.SetCallReducerFlags.IdentityConnectedFlags);
+ }
+
+ public bool InvokeIdentityConnected(EventContext ctx, IdentityConnected args)
+ {
+ if (OnIdentityConnected == null) return false;
+ OnIdentityConnected(
+ ctx
+ );
+ return true;
+ }
+ public delegate void InitHandler(EventContext ctx);
+ public event InitHandler? OnInit;
+
+ public void Init()
+ {
+ conn.InternalCallReducer(new Init { }, this.SetCallReducerFlags.InitFlags);
+ }
+
+ public bool InvokeInit(EventContext ctx, Init args)
+ {
+ if (OnInit == null) return false;
+ OnInit(
+ ctx
+ );
+ return true;
+ }
public delegate void AddPlayerHandler(EventContext ctx, string name);
public event AddPlayerHandler? OnAddPlayer;
@@ -1024,6 +1092,10 @@ namespace SpacetimeDB
public sealed class SetReducerFlags
{
internal SetReducerFlags() { }
+ internal CallReducerFlags IdentityConnectedFlags;
+ public void IdentityConnected(CallReducerFlags flags) { this.IdentityConnectedFlags = flags; }
+ internal CallReducerFlags InitFlags;
+ public void Init(CallReducerFlags flags) { this.InitFlags = flags; }
internal CallReducerFlags AddPlayerFlags;
public void AddPlayer(CallReducerFlags flags) { this.AddPlayerFlags = flags; }
internal CallReducerFlags AddPrivateFlags;
@@ -1058,6 +1130,8 @@ namespace SpacetimeDB
[Type]
public partial record Reducer : TaggedEnum<(
+ IdentityConnected IdentityConnected,
+ Init Init,
AddPlayer AddPlayer,
AddPrivate AddPrivate,
DeletePlayer DeletePlayer,
@@ -1066,9 +1140,7 @@ namespace SpacetimeDB
RepeatingTest RepeatingTest,
Test Test,
TestBtreeIndexArgs TestBtreeIndexArgs,
- Unit StdbNone,
- Unit StdbIdentityConnected,
- Unit StdbIdentityDisconnected
+ Unit StdbNone
)>;
public class DbConnection : DbConnectionBase
{
@@ -1081,33 +1153,32 @@ namespace SpacetimeDB
SetReducerFlags = new();
Reducers = new(this, this.SetReducerFlags);
- clientDB.AddTable("has_special_stuff", Db.HasSpecialStuff);
- clientDB.AddTable("pk_multi_identity", Db.PkMultiIdentity);
- clientDB.AddTable("points", Db.Points);
- clientDB.AddTable("private", Db.Private);
- clientDB.AddTable("repeating_test_arg", Db.RepeatingTestArg);
- clientDB.AddTable("test_a", Db.TestA);
- clientDB.AddTable("test_d", Db.TestD);
- clientDB.AddTable("test_e", Db.TestE);
- clientDB.AddTable("test_f", Db.TestF);
+ clientDB.AddTable(0, Db.HasSpecialStuff);
+ clientDB.AddTable(1, Db.PkMultiIdentity);
+ clientDB.AddTable(2, Db.Points);
+ clientDB.AddTable(3, Db.Private);
+ clientDB.AddTable(4, Db.RepeatingTestArg);
+ clientDB.AddTable(5, Db.TestA);
+ clientDB.AddTable(6, Db.TestD);
+ clientDB.AddTable(7, Db.TestE);
+ clientDB.AddTable(8, Db.TestF);
}
- protected override Reducer ToReducer(TransactionUpdate update)
+ protected override Reducer ToReducer(uint reducerIdx, TransactionUpdate update)
{
var encodedArgs = update.ReducerCall.Args;
- return update.ReducerCall.ReducerName switch {
- "add_player" => new Reducer.AddPlayer(BSATNHelpers.Decode(encodedArgs)),
- "add_private" => new Reducer.AddPrivate(BSATNHelpers.Decode(encodedArgs)),
- "delete_player" => new Reducer.DeletePlayer(BSATNHelpers.Decode(encodedArgs)),
- "delete_players_by_name" => new Reducer.DeletePlayersByName(BSATNHelpers.Decode(encodedArgs)),
- "query_private" => new Reducer.QueryPrivate(BSATNHelpers.Decode(encodedArgs)),
- "repeating_test" => new Reducer.RepeatingTest(BSATNHelpers.Decode(encodedArgs)),
- "test" => new Reducer.Test(BSATNHelpers.Decode(encodedArgs)),
- "test_btree_index_args" => new Reducer.TestBtreeIndexArgs(BSATNHelpers.Decode(encodedArgs)),
- "" => new Reducer.StdbNone(default),
- "__identity_connected__" => new Reducer.StdbIdentityConnected(default),
- "__identity_disconnected__" => new Reducer.StdbIdentityDisconnected(default),
- "" => new Reducer.StdbNone(default),
+ return reducerIdx switch {
+ 0 => new Reducer.IdentityConnected(BSATNHelpers.Decode(encodedArgs)),
+ 1 => new Reducer.Init(BSATNHelpers.Decode(encodedArgs)),
+ 2 => new Reducer.AddPlayer(BSATNHelpers.Decode(encodedArgs)),
+ 3 => new Reducer.AddPrivate(BSATNHelpers.Decode(encodedArgs)),
+ 4 => new Reducer.DeletePlayer(BSATNHelpers.Decode(encodedArgs)),
+ 5 => new Reducer.DeletePlayersByName(BSATNHelpers.Decode(encodedArgs)),
+ 6 => new Reducer.QueryPrivate(BSATNHelpers.Decode(encodedArgs)),
+ 7 => new Reducer.RepeatingTest(BSATNHelpers.Decode(encodedArgs)),
+ 8 => new Reducer.Test(BSATNHelpers.Decode(encodedArgs)),
+ 9 => new Reducer.TestBtreeIndexArgs(BSATNHelpers.Decode(encodedArgs)),
+ 4294967295 => new Reducer.StdbNone(default),
var reducer => throw new ArgumentOutOfRangeException("Reducer", $"Unknown reducer {reducer}")
};
}
@@ -1119,6 +1190,8 @@ namespace SpacetimeDB
{
var eventContext = (EventContext)context;
return reducer switch {
+ Reducer.IdentityConnected(var args) => Reducers.InvokeIdentityConnected(eventContext, args),
+ Reducer.Init(var args) => Reducers.InvokeInit(eventContext, args),
Reducer.AddPlayer(var args) => Reducers.InvokeAddPlayer(eventContext, args),
Reducer.AddPrivate(var args) => Reducers.InvokeAddPrivate(eventContext, args),
Reducer.DeletePlayer(var args) => Reducers.InvokeDeletePlayer(eventContext, args),
@@ -1127,9 +1200,7 @@ namespace SpacetimeDB
Reducer.RepeatingTest(var args) => Reducers.InvokeRepeatingTest(eventContext, args),
Reducer.Test(var args) => Reducers.InvokeTest(eventContext, args),
Reducer.TestBtreeIndexArgs(var args) => Reducers.InvokeTestBtreeIndexArgs(eventContext, args),
- Reducer.StdbNone or
- Reducer.StdbIdentityConnected or
- Reducer.StdbIdentityDisconnected => true,
+ Reducer.StdbNone => true,
_ => throw new ArgumentOutOfRangeException("Reducer", $"Unknown reducer {reducer}")
};
}