Skip to content

Commit

Permalink
bless insta snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Oct 23, 2024
1 parent 5a1f67c commit 10c465f
Showing 1 changed file with 108 additions and 37 deletions.
145 changes: 108 additions & 37 deletions crates/cli/tests/snapshots/codegen__codegen_csharp.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
}
Expand All @@ -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 = "";
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 = "";
}
Expand Down Expand Up @@ -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.
// <auto-generated />

#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.
// <auto-generated />

#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.
Expand Down Expand Up @@ -351,7 +387,7 @@ namespace SpacetimeDB
[SpacetimeDB.Type]
public partial class QueryPrivate : IReducerArgs
{
string IReducerArgs.ReducerName => "query_private";
uint IReducerArgs.ReducerIndex => 6;
}
}
'''
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -510,7 +546,7 @@ namespace SpacetimeDB
[SpacetimeDB.Type]
public partial class TestBtreeIndexArgs : IReducerArgs
{
string IReducerArgs.ReducerName => "test_btree_index_args";
uint IReducerArgs.ReducerIndex => 9;
}
}
'''
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1058,6 +1130,8 @@ namespace SpacetimeDB

[Type]
public partial record Reducer : TaggedEnum<(
IdentityConnected IdentityConnected,
Init Init,
AddPlayer AddPlayer,
AddPrivate AddPrivate,
DeletePlayer DeletePlayer,
Expand All @@ -1066,9 +1140,7 @@ namespace SpacetimeDB
RepeatingTest RepeatingTest,
Test Test,
TestBtreeIndexArgs TestBtreeIndexArgs,
Unit StdbNone,
Unit StdbIdentityConnected,
Unit StdbIdentityDisconnected
Unit StdbNone
)>;
public class DbConnection : DbConnectionBase<DbConnection, Reducer>
{
Expand All @@ -1081,33 +1153,32 @@ namespace SpacetimeDB
SetReducerFlags = new();
Reducers = new(this, this.SetReducerFlags);

clientDB.AddTable<HasSpecialStuff>("has_special_stuff", Db.HasSpecialStuff);
clientDB.AddTable<PkMultiIdentity>("pk_multi_identity", Db.PkMultiIdentity);
clientDB.AddTable<Point>("points", Db.Points);
clientDB.AddTable<Private>("private", Db.Private);
clientDB.AddTable<RepeatingTestArg>("repeating_test_arg", Db.RepeatingTestArg);
clientDB.AddTable<TestA>("test_a", Db.TestA);
clientDB.AddTable<TestD>("test_d", Db.TestD);
clientDB.AddTable<TestE>("test_e", Db.TestE);
clientDB.AddTable<TestFoobar>("test_f", Db.TestF);
clientDB.AddTable<HasSpecialStuff>(0, Db.HasSpecialStuff);
clientDB.AddTable<PkMultiIdentity>(1, Db.PkMultiIdentity);
clientDB.AddTable<Point>(2, Db.Points);
clientDB.AddTable<Private>(3, Db.Private);
clientDB.AddTable<RepeatingTestArg>(4, Db.RepeatingTestArg);
clientDB.AddTable<TestA>(5, Db.TestA);
clientDB.AddTable<TestD>(6, Db.TestD);
clientDB.AddTable<TestE>(7, Db.TestE);
clientDB.AddTable<TestFoobar>(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<AddPlayer>(encodedArgs)),
"add_private" => new Reducer.AddPrivate(BSATNHelpers.Decode<AddPrivate>(encodedArgs)),
"delete_player" => new Reducer.DeletePlayer(BSATNHelpers.Decode<DeletePlayer>(encodedArgs)),
"delete_players_by_name" => new Reducer.DeletePlayersByName(BSATNHelpers.Decode<DeletePlayersByName>(encodedArgs)),
"query_private" => new Reducer.QueryPrivate(BSATNHelpers.Decode<QueryPrivate>(encodedArgs)),
"repeating_test" => new Reducer.RepeatingTest(BSATNHelpers.Decode<RepeatingTest>(encodedArgs)),
"test" => new Reducer.Test(BSATNHelpers.Decode<Test>(encodedArgs)),
"test_btree_index_args" => new Reducer.TestBtreeIndexArgs(BSATNHelpers.Decode<TestBtreeIndexArgs>(encodedArgs)),
"<none>" => 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<IdentityConnected>(encodedArgs)),
1 => new Reducer.Init(BSATNHelpers.Decode<Init>(encodedArgs)),
2 => new Reducer.AddPlayer(BSATNHelpers.Decode<AddPlayer>(encodedArgs)),
3 => new Reducer.AddPrivate(BSATNHelpers.Decode<AddPrivate>(encodedArgs)),
4 => new Reducer.DeletePlayer(BSATNHelpers.Decode<DeletePlayer>(encodedArgs)),
5 => new Reducer.DeletePlayersByName(BSATNHelpers.Decode<DeletePlayersByName>(encodedArgs)),
6 => new Reducer.QueryPrivate(BSATNHelpers.Decode<QueryPrivate>(encodedArgs)),
7 => new Reducer.RepeatingTest(BSATNHelpers.Decode<RepeatingTest>(encodedArgs)),
8 => new Reducer.Test(BSATNHelpers.Decode<Test>(encodedArgs)),
9 => new Reducer.TestBtreeIndexArgs(BSATNHelpers.Decode<TestBtreeIndexArgs>(encodedArgs)),
4294967295 => new Reducer.StdbNone(default),
var reducer => throw new ArgumentOutOfRangeException("Reducer", $"Unknown reducer {reducer}")
};
}
Expand All @@ -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),
Expand All @@ -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}")
};
}
Expand Down

0 comments on commit 10c465f

Please sign in to comment.