diff --git a/.github/workflows/csharp-test.yml b/.github/workflows/csharp-test.yml index b1f8d834997..1fc6718772f 100644 --- a/.github/workflows/csharp-test.yml +++ b/.github/workflows/csharp-test.yml @@ -15,6 +15,14 @@ jobs: cancel-in-progress: true timeout-minutes: 30 steps: + - run: df -h + # Free up disk space because otherwise we run out during the test + - name: "node-cleanup" + run: | + sudo rm -rf /usr/local/lib/android + sudo docker image prune --all --force + sudo docker builder prune -a + - run: df -h - name: Checkout repository id: checkout-stdb uses: actions/checkout@v4 diff --git a/crates/bindings-csharp/BSATN.Codegen/Type.cs b/crates/bindings-csharp/BSATN.Codegen/Type.cs index 4bfbf45ec7e..0ba58eb61d8 100644 --- a/crates/bindings-csharp/BSATN.Codegen/Type.cs +++ b/crates/bindings-csharp/BSATN.Codegen/Type.cs @@ -594,16 +594,16 @@ public override string ToString() => write = "value.WriteFields(writer);"; - var declHashName = (MemberDeclaration decl) => $"___hash{decl.Name}"; + string DeclHashName(MemberDeclaration decl) => $"___hash{decl.Name}"; getHashCode = $$""" - {{string.Join("\n", bsatnDecls.Select(decl => decl.Type.GetHashCodeStatement(decl.Name, declHashName(decl))))}} - return {{JoinOrValue( - " ^\n ", - bsatnDecls.Select(declHashName), - "0" // if there are no members, the hash is 0. - )}}; - """; + {{string.Join("\n", bsatnDecls.Select(decl => decl.Type.GetHashCodeStatement(decl.Name, DeclHashName(decl))))}} + return {{JoinOrValue( + " ^\n ", + bsatnDecls.Select((Func?)DeclHashName), + "0" // if there are no members, the hash is 0. + )}}; + """; } extensions.Contents.Append( @@ -643,7 +643,7 @@ public override int GetHashCode() // If we are a reference type, various equality methods need to take nullable references. // If we are a value type, everything is pleasantly by-value. var fullNameMaybeRef = $"{FullName}{(Scope.IsStruct ? "" : "?")}"; - var declEqualsName = (MemberDeclaration decl) => $"___eq{decl.Name}"; + string DeclEqualsName(MemberDeclaration decl) => $"___eq{decl.Name}"; extensions.Contents.Append( $$""" @@ -652,10 +652,10 @@ public override int GetHashCode() public bool Equals({{fullNameMaybeRef}} that) { {{(Scope.IsStruct ? "" : "if (((object?)that) == null) { return false; }\n ")}} - {{string.Join("\n", bsatnDecls.Select(decl => decl.Type.EqualsStatement($"this.{decl.Name}", $"that.{decl.Name}", declEqualsName(decl))))}} + {{string.Join("\n", bsatnDecls.Select(decl => decl.Type.EqualsStatement($"this.{decl.Name}", $"that.{decl.Name}", DeclEqualsName(decl))))}} return {{JoinOrValue( " &&\n ", - bsatnDecls.Select(declEqualsName), + bsatnDecls.Select((Func?)DeclEqualsName), "true" // if there are no elements, the structs are equal :) )}}; } diff --git a/crates/bindings-csharp/BSATN.Runtime.Tests/Tests.cs b/crates/bindings-csharp/BSATN.Runtime.Tests/Tests.cs index c22879a596c..620adef4662 100644 --- a/crates/bindings-csharp/BSATN.Runtime.Tests/Tests.cs +++ b/crates/bindings-csharp/BSATN.Runtime.Tests/Tests.cs @@ -246,20 +246,15 @@ public BasicDataClass((int x, string y, int? z, string? w) data) } [Type] - public partial struct BasicDataStruct + public partial struct BasicDataStruct(int x, string y, int? z, string? w) { - public int X; - public string Y; - public int? Z; - public string? W; + public int X = x; + public string Y = y; + public int? Z = z; + public string? W = w; public BasicDataStruct((int x, string y, int? z, string? w) data) - { - X = data.x; - Y = data.y; - Z = data.z; - W = data.w; - } + : this(data.x, data.y, data.z, data.w) { } } [Type] @@ -315,12 +310,12 @@ public void Add(bool collides) } } - public double CollisionFraction + public readonly double CollisionFraction { get => (double)Collisions / (double)Comparisons; } - public void AssertCollisionsLessThan(double fraction) + public readonly void AssertCollisionsLessThan(double fraction) { Assert.True( CollisionFraction < fraction, @@ -630,14 +625,10 @@ public static void GeneratedNestedListRoundTrip() static readonly Gen<(ContainsNestedList e1, ContainsNestedList e2)> GenTwoContainsNestedList = Gen.Select(GenContainsNestedList, GenContainsNestedList, (e1, e2) => (e1, e2)); - class EnumerableEqualityComparer : EqualityComparer> + class EnumerableEqualityComparer(EqualityComparer equalityComparer) + : EqualityComparer> { - private readonly EqualityComparer EqualityComparer; - - public EnumerableEqualityComparer(EqualityComparer equalityComparer) - { - EqualityComparer = equalityComparer; - } + private readonly EqualityComparer EqualityComparer = equalityComparer; public override bool Equals(IEnumerable? x, IEnumerable? y) => x == null ? y == null : (y == null ? false : x.SequenceEqual(y, EqualityComparer)); diff --git a/crates/bindings-csharp/BSATN.Runtime/BSATN/AlgebraicType.cs b/crates/bindings-csharp/BSATN.Runtime/BSATN/AlgebraicType.cs index 603feae5c78..2c0a0f0f7a9 100644 --- a/crates/bindings-csharp/BSATN.Runtime/BSATN/AlgebraicType.cs +++ b/crates/bindings-csharp/BSATN.Runtime/BSATN/AlgebraicType.cs @@ -6,17 +6,10 @@ public interface ITypeRegistrar } [SpacetimeDB.Type] -public partial struct AggregateElement +public partial struct AggregateElement(string? name, AlgebraicType algebraicType) { - public string? Name; - - public AlgebraicType AlgebraicType; - - public AggregateElement(string name, AlgebraicType algebraicType) - { - Name = name; - AlgebraicType = algebraicType; - } + public string? Name = name; + public AlgebraicType AlgebraicType = algebraicType; } [SpacetimeDB.Type] diff --git a/crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs b/crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs index bce87b273bc..ccc2fc682a1 100644 --- a/crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs +++ b/crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs @@ -129,7 +129,22 @@ public interface IReadWrite /// Note: the [Type] macro rejects enums with explicitly set values (see Codegen.Tests), /// so this array is guaranteed to be continuous and indexed starting from 0. /// - private static readonly T[] TagToValue = Enum.GetValues(typeof(T)).Cast().ToArray(); +#if NET8_0_OR_GREATER + private static readonly T[] TagToValue = System.Enum.GetValues(); +#else + private static readonly T[] TagToValue = CreateTagToValue(); + + private static T[] CreateTagToValue() + { + var values = System.Enum.GetValues(typeof(T)); + var result = new T[values.Length]; + for (var i = 0; i < values.Length; i++) + { + result[i] = (T)values.GetValue(i); + } + return result; + } +#endif public T Read(BinaryReader reader) { @@ -173,15 +188,31 @@ public void Write(BinaryWriter writer, T value) } } - public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) => - registrar.RegisterType( + public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) + { + return registrar.RegisterType( (_) => - new AlgebraicType.Sum( - Enum.GetNames(typeof(T)) - .Select(name => new AggregateElement(name, AlgebraicType.Unit)) - .ToArray() - ) + { +#if NET8_0_OR_GREATER + return new AlgebraicType.Sum( + [ + .. System + .Enum.GetNames() + .Select(name => new AggregateElement(name, AlgebraicType.Unit)), + ] + ); +#else + var names = System.Enum.GetNames(typeof(T)); + var elements = new AggregateElement[names.Length]; + for (var i = 0; i < names.Length; i++) + { + elements[i] = new AggregateElement(names[i], AlgebraicType.Unit); + } + return new AlgebraicType.Sum(elements); +#endif + } ); + } } public readonly struct RefOption : IReadWrite diff --git a/crates/bindings-csharp/BSATN.Runtime/Builtins.cs b/crates/bindings-csharp/BSATN.Runtime/Builtins.cs index a3478d18023..0675dc6137f 100644 --- a/crates/bindings-csharp/BSATN.Runtime/Builtins.cs +++ b/crates/bindings-csharp/BSATN.Runtime/Builtins.cs @@ -331,7 +331,7 @@ public static implicit operator DateTimeOffset(Timestamp t) => DateTimeOffset.UnixEpoch.AddTicks(t.MicrosecondsSinceUnixEpoch * Util.TicksPerMicrosecond); public static implicit operator Timestamp(DateTimeOffset offset) => - new Timestamp(offset.Subtract(DateTimeOffset.UnixEpoch).Ticks / Util.TicksPerMicrosecond); + new(offset.Subtract(DateTimeOffset.UnixEpoch).Ticks / Util.TicksPerMicrosecond); // For backwards-compatibility. public readonly DateTimeOffset ToStd() => this; @@ -347,7 +347,7 @@ public override readonly string ToString() public static readonly Timestamp UNIX_EPOCH = new(0); public static Timestamp FromTimeDurationSinceUnixEpoch(TimeDuration timeDuration) => - new Timestamp(timeDuration.Microseconds); + new(timeDuration.Microseconds); public readonly TimeDuration ToTimeDurationSinceUnixEpoch() => TimeDurationSince(UNIX_EPOCH); @@ -357,15 +357,15 @@ public static Timestamp FromTimeSpanSinceUnixEpoch(TimeSpan timeSpan) => public readonly TimeSpan ToTimeSpanSinceUnixEpoch() => (TimeSpan)ToTimeDurationSinceUnixEpoch(); public readonly TimeDuration TimeDurationSince(Timestamp earlier) => - new TimeDuration(checked(MicrosecondsSinceUnixEpoch - earlier.MicrosecondsSinceUnixEpoch)); + new(checked(MicrosecondsSinceUnixEpoch - earlier.MicrosecondsSinceUnixEpoch)); public static Timestamp operator +(Timestamp point, TimeDuration interval) => - new Timestamp(checked(point.MicrosecondsSinceUnixEpoch + interval.Microseconds)); + new(checked(point.MicrosecondsSinceUnixEpoch + interval.Microseconds)); public static Timestamp operator -(Timestamp point, TimeDuration interval) => - new Timestamp(checked(point.MicrosecondsSinceUnixEpoch - interval.Microseconds)); + new(checked(point.MicrosecondsSinceUnixEpoch - interval.Microseconds)); - public int CompareTo(Timestamp that) + public readonly int CompareTo(Timestamp that) { return this.MicrosecondsSinceUnixEpoch.CompareTo(that.MicrosecondsSinceUnixEpoch); } @@ -466,10 +466,10 @@ public static implicit operator TimeDuration(TimeSpan timeSpan) => new(timeSpan.Ticks / Util.TicksPerMicrosecond); public static TimeDuration operator +(TimeDuration lhs, TimeDuration rhs) => - new TimeDuration(checked(lhs.Microseconds + rhs.Microseconds)); + new(checked(lhs.Microseconds + rhs.Microseconds)); public static TimeDuration operator -(TimeDuration lhs, TimeDuration rhs) => - new TimeDuration(checked(lhs.Microseconds + rhs.Microseconds)); + new(checked(lhs.Microseconds - rhs.Microseconds)); // For backwards-compatibility. public readonly TimeSpan ToStd() => this; @@ -548,7 +548,7 @@ long microsSinceUnixEpoch // --- auto-generated --- private ScheduleAt() { } - internal enum @enum : byte + internal enum EnumTag : byte { Interval, Time, @@ -560,15 +560,15 @@ public sealed record Time(Timestamp Time_) : ScheduleAt; public readonly partial struct BSATN : IReadWrite { - internal static readonly SpacetimeDB.BSATN.Enum<@enum> __enumTag = new(); + internal static readonly SpacetimeDB.BSATN.Enum __enumTag = new(); internal static readonly TimeDuration.BSATN Interval = new(); internal static readonly Timestamp.BSATN Time = new(); public ScheduleAt Read(BinaryReader reader) => __enumTag.Read(reader) switch { - @enum.Interval => new Interval(Interval.Read(reader)), - @enum.Time => new Time(Time.Read(reader)), + EnumTag.Interval => new Interval(Interval.Read(reader)), + EnumTag.Time => new Time(Time.Read(reader)), _ => throw new InvalidOperationException( "Invalid tag value, this state should be unreachable." ), @@ -579,12 +579,12 @@ public void Write(BinaryWriter writer, ScheduleAt value) switch (value) { case Interval(var inner): - __enumTag.Write(writer, @enum.Interval); + __enumTag.Write(writer, EnumTag.Interval); Interval.Write(writer, inner); break; case Time(var inner): - __enumTag.Write(writer, @enum.Time); + __enumTag.Write(writer, EnumTag.Time); Time.Write(writer, inner); break; } diff --git a/crates/bindings-csharp/Codegen/Module.cs b/crates/bindings-csharp/Codegen/Module.cs index fb9f1d6fd79..aab179caca6 100644 --- a/crates/bindings-csharp/Codegen/Module.cs +++ b/crates/bindings-csharp/Codegen/Module.cs @@ -466,7 +466,12 @@ public ulong Delete({{argsBounds}}) => } } - public record struct View(string viewName, string tableName, string view, string getter); + public record struct View( + string ViewName, + string TableName, + string ViewCode, + string GetterCode + ); public IEnumerable GenerateViews() { @@ -539,7 +544,7 @@ v.Scheduled is { } scheduled } } - public record Constraint(ColumnDeclaration Col, int Pos, ColumnAttrs Attr) + public readonly record struct Constraint(ColumnDeclaration Col, int Pos, ColumnAttrs Attr) { public ViewIndex ToIndex() => new(new ColumnRef(Pos, Col.Name)); } @@ -853,8 +858,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context) tables .SelectMany((t, ct) => t.GenerateViews()) .WithTrackingName("SpacetimeDB.Table.GenerateViews"), - v => v.viewName, - v => v.tableName + v => v.ViewName, + v => v.TableName ); var rlsFilters = context @@ -919,11 +924,11 @@ internal ReducerContext(Identity identity, ConnectionId? connectionId, Random ra } namespace Internal.TableHandles { - {{string.Join("\n", tableViews.Select(v => v.view))}} + {{string.Join("\n", tableViews.Select(v => v.ViewCode))}} } public sealed class Local { - {{string.Join("\n", tableViews.Select(v => v.getter))}} + {{string.Join("\n", tableViews.Select(v => v.GetterCode))}} } } @@ -949,7 +954,7 @@ public static void Main() { )}} {{string.Join( "\n", - tableViews.Select(t => $"SpacetimeDB.Internal.Module.RegisterTable<{t.tableName}, SpacetimeDB.Internal.TableHandles.{t.viewName}>();") + tableViews.Select(t => $"SpacetimeDB.Internal.Module.RegisterTable<{t.TableName}, SpacetimeDB.Internal.TableHandles.{t.ViewName}>();") )}} {{string.Join( "\n", diff --git a/crates/bindings-csharp/Runtime/Internal/Module.cs b/crates/bindings-csharp/Runtime/Internal/Module.cs index ecd079e1ad8..b3e526f3d49 100644 --- a/crates/bindings-csharp/Runtime/Internal/Module.cs +++ b/crates/bindings-csharp/Runtime/Internal/Module.cs @@ -11,7 +11,7 @@ partial class RawModuleDefV9 // Fix it up to a different mangling scheme if it causes problems. private static string GetFriendlyName(Type type) => type.IsGenericType - ? $"{type.Name.Remove(type.Name.IndexOf('`'))}_{string.Join("_", type.GetGenericArguments().Select(GetFriendlyName))}" + ? $"{type.Name[..type.Name.IndexOf('`')]}_{string.Join("_", type.GetGenericArguments().Select(GetFriendlyName))}" : type.Name; private void RegisterTypeName(AlgebraicType.Ref typeRef) diff --git a/sdks/csharp/tests~/SnapshotTests.VerifySampleDump_dumpName=LegacySubscribeAll.verified.txt b/sdks/csharp/tests~/SnapshotTests.VerifySampleDump_dumpName=LegacySubscribeAll.verified.txt index 4dd3f646b4f..ad04d010a6e 100644 --- a/sdks/csharp/tests~/SnapshotTests.VerifySampleDump_dumpName=LegacySubscribeAll.verified.txt +++ b/sdks/csharp/tests~/SnapshotTests.VerifySampleDump_dumpName=LegacySubscribeAll.verified.txt @@ -18,8 +18,8 @@ ConnectionId: Guid_1 }, user: { - Identity: Identity_1, - Online: true + identity: Identity_1, + online: true } }, OnInsertUser: { @@ -35,14 +35,26 @@ ConnectionId: Guid_1 }, user: { - Identity: Identity_2, - Online: true + identity: Identity_2, + online: true } }, OnInsertUser: { eventContext: { Event: { - $type: Event.UnknownTransaction + $type: Event.Reducer, + ReducerEvent: { + Timestamp: 1718487763059031, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_3, + CallerConnectionId: Guid_2, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.IdentityConnected + } + } }, Db: {Scrubbed}, Reducers: {Scrubbed}, @@ -52,14 +64,27 @@ ConnectionId: Guid_1 }, user: { - Identity: Identity_3, - Online: true + identity: Identity_3, + online: true } }, OnUpdateUser: { eventContext: { Event: { - $type: Event.UnknownTransaction + $type: Event.Reducer, + ReducerEvent: { + Timestamp: 1718487768057579, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_1, + CallerConnectionId: Guid_3, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SetName, + name: A + } + } }, Db: {Scrubbed}, Reducers: {Scrubbed}, @@ -69,19 +94,61 @@ ConnectionId: Guid_1 }, oldUser: { - Identity: Identity_1, - Online: true + identity: Identity_1, + online: true }, newUser: { - Identity: Identity_1, - Name: A, - Online: true + identity: Identity_1, + name: A, + online: true } }, + OnSetName: { + Event: { + Timestamp: 1718487768057579, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_1, + CallerConnectionId: Guid_3, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SetName, + name: A + } + }, + Db: { + Message: { + Count: 4 + }, + User: { + Identity: {}, + Count: 3 + } + }, + Reducers: {}, + SetReducerFlags: {}, + IsActive: false, + Identity: Identity_1, + ConnectionId: Guid_1 + }, OnInsertMessage: { eventContext: { Event: { - $type: Event.UnknownTransaction + $type: Event.Reducer, + ReducerEvent: { + Timestamp: 1718487775346381, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_3, + CallerConnectionId: Guid_2, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SendMessage, + text: Hello, A! + } + } }, Db: {Scrubbed}, Reducers: {Scrubbed}, @@ -91,15 +158,57 @@ ConnectionId: Guid_1 }, message: { - Sender: Identity_3, - Sent: 1718487775346381, - Text: Hello, A! + sender: Identity_3, + sent: 1718487775346381, + text: Hello, A! } }, + OnSendMessage: { + Event: { + Timestamp: 1718487775346381, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_3, + CallerConnectionId: Guid_2, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SendMessage, + text: Hello, A! + } + }, + Db: { + Message: { + Count: 4 + }, + User: { + Identity: {}, + Count: 3 + } + }, + Reducers: {}, + SetReducerFlags: {}, + IsActive: false, + Identity: Identity_1, + ConnectionId: Guid_1 + }, OnUpdateUser: { eventContext: { Event: { - $type: Event.UnknownTransaction + $type: Event.Reducer, + ReducerEvent: { + Timestamp: 1718487777307855, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_3, + CallerConnectionId: Guid_2, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SetName, + name: B + } + } }, Db: {Scrubbed}, Reducers: {Scrubbed}, @@ -109,19 +218,61 @@ ConnectionId: Guid_1 }, oldUser: { - Identity: Identity_3, - Online: true + identity: Identity_3, + online: true }, newUser: { - Identity: Identity_3, - Name: B, - Online: true + identity: Identity_3, + name: B, + online: true } }, + OnSetName: { + Event: { + Timestamp: 1718487777307855, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_3, + CallerConnectionId: Guid_2, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SetName, + name: B + } + }, + Db: { + Message: { + Count: 4 + }, + User: { + Identity: {}, + Count: 3 + } + }, + Reducers: {}, + SetReducerFlags: {}, + IsActive: false, + Identity: Identity_1, + ConnectionId: Guid_1 + }, OnInsertMessage: { eventContext: { Event: { - $type: Event.UnknownTransaction + $type: Event.Reducer, + ReducerEvent: { + Timestamp: 1718487783175083, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_1, + CallerConnectionId: Guid_3, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SendMessage, + text: Hello, B! + } + } }, Db: {Scrubbed}, Reducers: {Scrubbed}, @@ -131,15 +282,57 @@ ConnectionId: Guid_1 }, message: { - Sender: Identity_1, - Sent: 1718487783175083, - Text: Hello, B! + sender: Identity_1, + sent: 1718487783175083, + text: Hello, B! } }, + OnSendMessage: { + Event: { + Timestamp: 1718487783175083, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_1, + CallerConnectionId: Guid_3, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SendMessage, + text: Hello, B! + } + }, + Db: { + Message: { + Count: 4 + }, + User: { + Identity: {}, + Count: 3 + } + }, + Reducers: {}, + SetReducerFlags: {}, + IsActive: false, + Identity: Identity_1, + ConnectionId: Guid_1 + }, OnInsertMessage: { eventContext: { Event: { - $type: Event.UnknownTransaction + $type: Event.Reducer, + ReducerEvent: { + Timestamp: 1718487787645364, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_3, + CallerConnectionId: Guid_2, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SendMessage, + text: Goodbye! + } + } }, Db: {Scrubbed}, Reducers: {Scrubbed}, @@ -149,15 +342,56 @@ ConnectionId: Guid_1 }, message: { - Sender: Identity_3, - Sent: 1718487787645364, - Text: Goodbye! + sender: Identity_3, + sent: 1718487787645364, + text: Goodbye! } }, + OnSendMessage: { + Event: { + Timestamp: 1718487787645364, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_3, + CallerConnectionId: Guid_2, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SendMessage, + text: Goodbye! + } + }, + Db: { + Message: { + Count: 4 + }, + User: { + Identity: {}, + Count: 3 + } + }, + Reducers: {}, + SetReducerFlags: {}, + IsActive: false, + Identity: Identity_1, + ConnectionId: Guid_1 + }, OnUpdateUser: { eventContext: { Event: { - $type: Event.UnknownTransaction + $type: Event.Reducer, + ReducerEvent: { + Timestamp: 1718487791901504, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_3, + CallerConnectionId: Guid_2, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.IdentityDisconnected + } + } }, Db: {Scrubbed}, Reducers: {Scrubbed}, @@ -167,20 +401,33 @@ ConnectionId: Guid_1 }, oldUser: { - Identity: Identity_3, - Name: B, - Online: true + identity: Identity_3, + name: B, + online: true }, newUser: { - Identity: Identity_3, - Name: B, - Online: false + identity: Identity_3, + name: B, + online: false } }, OnInsertMessage: { eventContext: { Event: { - $type: Event.UnknownTransaction + $type: Event.Reducer, + ReducerEvent: { + Timestamp: 1718487794937841, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_1, + CallerConnectionId: Guid_3, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SendMessage, + text: Goodbye! + } + } }, Db: {Scrubbed}, Reducers: {Scrubbed}, @@ -190,49 +437,78 @@ ConnectionId: Guid_1 }, message: { - Sender: Identity_1, - Sent: 1718487794937841, - Text: Goodbye! + sender: Identity_1, + sent: 1718487794937841, + text: Goodbye! } + }, + OnSendMessage: { + Event: { + Timestamp: 1718487794937841, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_1, + CallerConnectionId: Guid_3, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SendMessage, + text: Goodbye! + } + }, + Db: { + Message: { + Count: 4 + }, + User: { + Identity: {}, + Count: 3 + } + }, + Reducers: {}, + SetReducerFlags: {}, + IsActive: false, + Identity: Identity_1, + ConnectionId: Guid_1 } }, FinalSnapshot: { User: [ { - Identity: Identity_1, - Name: A, - Online: true + identity: Identity_1, + name: A, + online: true }, { - Identity: Identity_2, - Online: true + identity: Identity_2, + online: true }, { - Identity: Identity_3, - Name: B, - Online: false + identity: Identity_3, + name: B, + online: false } ], Message: [ { - Sender: Identity_3, - Sent: 1718487775346381, - Text: Hello, A! + sender: Identity_3, + sent: 1718487775346381, + text: Hello, A! }, { - Sender: Identity_1, - Sent: 1718487783175083, - Text: Hello, B! + sender: Identity_1, + sent: 1718487783175083, + text: Hello, B! }, { - Sender: Identity_3, - Sent: 1718487787645364, - Text: Goodbye! + sender: Identity_3, + sent: 1718487787645364, + text: Goodbye! }, { - Sender: Identity_1, - Sent: 1718487794937841, - Text: Goodbye! + sender: Identity_1, + sent: 1718487794937841, + text: Goodbye! } ] }, diff --git a/sdks/csharp/tests~/SnapshotTests.VerifySampleDump_dumpName=SubscribeApplied.verified.txt b/sdks/csharp/tests~/SnapshotTests.VerifySampleDump_dumpName=SubscribeApplied.verified.txt index fa31e49891f..9368d6d83a9 100644 --- a/sdks/csharp/tests~/SnapshotTests.VerifySampleDump_dumpName=SubscribeApplied.verified.txt +++ b/sdks/csharp/tests~/SnapshotTests.VerifySampleDump_dumpName=SubscribeApplied.verified.txt @@ -18,8 +18,8 @@ ConnectionId: Guid_1 }, user: { - Identity: Identity_1, - Online: true + identity: Identity_1, + online: true } }, OnInsertUser: { @@ -35,14 +35,26 @@ ConnectionId: Guid_1 }, user: { - Identity: Identity_2, - Online: true + identity: Identity_2, + online: true } }, OnInsertUser: { eventContext: { Event: { - $type: Event.UnknownTransaction + $type: Event.Reducer, + ReducerEvent: { + Timestamp: 1718487763059031, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_3, + CallerConnectionId: Guid_2, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.IdentityConnected + } + } }, Db: {Scrubbed}, Reducers: {Scrubbed}, @@ -52,14 +64,27 @@ ConnectionId: Guid_1 }, user: { - Identity: Identity_3, - Online: true + identity: Identity_3, + online: true } }, OnUpdateUser: { eventContext: { Event: { - $type: Event.UnknownTransaction + $type: Event.Reducer, + ReducerEvent: { + Timestamp: 1718487768057579, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_1, + CallerConnectionId: Guid_3, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SetName, + name: A + } + } }, Db: {Scrubbed}, Reducers: {Scrubbed}, @@ -69,19 +94,61 @@ ConnectionId: Guid_1 }, oldUser: { - Identity: Identity_1, - Online: true + identity: Identity_1, + online: true }, newUser: { - Identity: Identity_1, - Name: A, - Online: true + identity: Identity_1, + name: A, + online: true } }, + OnSetName: { + Event: { + Timestamp: 1718487768057579, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_1, + CallerConnectionId: Guid_3, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SetName, + name: A + } + }, + Db: { + Message: { + Count: 4 + }, + User: { + Identity: {}, + Count: 3 + } + }, + Reducers: {}, + SetReducerFlags: {}, + IsActive: false, + Identity: Identity_1, + ConnectionId: Guid_1 + }, OnInsertMessage: { eventContext: { Event: { - $type: Event.UnknownTransaction + $type: Event.Reducer, + ReducerEvent: { + Timestamp: 1718487775346381, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_3, + CallerConnectionId: Guid_2, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SendMessage, + text: Hello, A! + } + } }, Db: {Scrubbed}, Reducers: {Scrubbed}, @@ -91,15 +158,57 @@ ConnectionId: Guid_1 }, message: { - Sender: Identity_3, - Sent: 1718487775346381, - Text: Hello, A! + sender: Identity_3, + sent: 1718487775346381, + text: Hello, A! } }, + OnSendMessage: { + Event: { + Timestamp: 1718487775346381, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_3, + CallerConnectionId: Guid_2, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SendMessage, + text: Hello, A! + } + }, + Db: { + Message: { + Count: 4 + }, + User: { + Identity: {}, + Count: 3 + } + }, + Reducers: {}, + SetReducerFlags: {}, + IsActive: false, + Identity: Identity_1, + ConnectionId: Guid_1 + }, OnUpdateUser: { eventContext: { Event: { - $type: Event.UnknownTransaction + $type: Event.Reducer, + ReducerEvent: { + Timestamp: 1718487777307855, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_3, + CallerConnectionId: Guid_2, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SetName, + name: B + } + } }, Db: {Scrubbed}, Reducers: {Scrubbed}, @@ -109,19 +218,61 @@ ConnectionId: Guid_1 }, oldUser: { - Identity: Identity_3, - Online: true + identity: Identity_3, + online: true }, newUser: { - Identity: Identity_3, - Name: B, - Online: true + identity: Identity_3, + name: B, + online: true } }, + OnSetName: { + Event: { + Timestamp: 1718487777307855, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_3, + CallerConnectionId: Guid_2, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SetName, + name: B + } + }, + Db: { + Message: { + Count: 4 + }, + User: { + Identity: {}, + Count: 3 + } + }, + Reducers: {}, + SetReducerFlags: {}, + IsActive: false, + Identity: Identity_1, + ConnectionId: Guid_1 + }, OnInsertMessage: { eventContext: { Event: { - $type: Event.UnknownTransaction + $type: Event.Reducer, + ReducerEvent: { + Timestamp: 1718487783175083, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_1, + CallerConnectionId: Guid_3, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SendMessage, + text: Hello, B! + } + } }, Db: {Scrubbed}, Reducers: {Scrubbed}, @@ -131,15 +282,57 @@ ConnectionId: Guid_1 }, message: { - Sender: Identity_1, - Sent: 1718487783175083, - Text: Hello, B! + sender: Identity_1, + sent: 1718487783175083, + text: Hello, B! } }, + OnSendMessage: { + Event: { + Timestamp: 1718487783175083, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_1, + CallerConnectionId: Guid_3, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SendMessage, + text: Hello, B! + } + }, + Db: { + Message: { + Count: 4 + }, + User: { + Identity: {}, + Count: 3 + } + }, + Reducers: {}, + SetReducerFlags: {}, + IsActive: false, + Identity: Identity_1, + ConnectionId: Guid_1 + }, OnInsertMessage: { eventContext: { Event: { - $type: Event.UnknownTransaction + $type: Event.Reducer, + ReducerEvent: { + Timestamp: 1718487787645364, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_3, + CallerConnectionId: Guid_2, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SendMessage, + text: Goodbye! + } + } }, Db: {Scrubbed}, Reducers: {Scrubbed}, @@ -149,15 +342,56 @@ ConnectionId: Guid_1 }, message: { - Sender: Identity_3, - Sent: 1718487787645364, - Text: Goodbye! + sender: Identity_3, + sent: 1718487787645364, + text: Goodbye! } }, + OnSendMessage: { + Event: { + Timestamp: 1718487787645364, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_3, + CallerConnectionId: Guid_2, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SendMessage, + text: Goodbye! + } + }, + Db: { + Message: { + Count: 4 + }, + User: { + Identity: {}, + Count: 3 + } + }, + Reducers: {}, + SetReducerFlags: {}, + IsActive: false, + Identity: Identity_1, + ConnectionId: Guid_1 + }, OnUpdateUser: { eventContext: { Event: { - $type: Event.UnknownTransaction + $type: Event.Reducer, + ReducerEvent: { + Timestamp: 1718487791901504, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_3, + CallerConnectionId: Guid_2, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.IdentityDisconnected + } + } }, Db: {Scrubbed}, Reducers: {Scrubbed}, @@ -167,20 +401,33 @@ ConnectionId: Guid_1 }, oldUser: { - Identity: Identity_3, - Name: B, - Online: true + identity: Identity_3, + name: B, + online: true }, newUser: { - Identity: Identity_3, - Name: B, - Online: false + identity: Identity_3, + name: B, + online: false } }, OnInsertMessage: { eventContext: { Event: { - $type: Event.UnknownTransaction + $type: Event.Reducer, + ReducerEvent: { + Timestamp: 1718487794937841, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_1, + CallerConnectionId: Guid_3, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SendMessage, + text: Goodbye! + } + } }, Db: {Scrubbed}, Reducers: {Scrubbed}, @@ -190,11 +437,40 @@ ConnectionId: Guid_1 }, message: { - Sender: Identity_1, - Sent: 1718487794937841, - Text: Goodbye! + sender: Identity_1, + sent: 1718487794937841, + text: Goodbye! } }, + OnSendMessage: { + Event: { + Timestamp: 1718487794937841, + Status: { + $type: Status.Committed + }, + CallerIdentity: Identity_1, + CallerConnectionId: Guid_3, + EnergyConsumed: {}, + Reducer: { + $type: Reducer.SendMessage, + text: Goodbye! + } + }, + Db: { + Message: { + Count: 4 + }, + User: { + Identity: {}, + Count: 3 + } + }, + Reducers: {}, + SetReducerFlags: {}, + IsActive: false, + Identity: Identity_1, + ConnectionId: Guid_1 + }, OnDeleteMessage: { eventContext: { Event: { @@ -208,9 +484,9 @@ ConnectionId: Guid_1 }, message: { - Sender: Identity_3, - Sent: 1718487775346381, - Text: Hello, A! + sender: Identity_3, + sent: 1718487775346381, + text: Hello, A! } }, OnDeleteMessage: { @@ -226,9 +502,9 @@ ConnectionId: Guid_1 }, message: { - Sender: Identity_1, - Sent: 1718487783175083, - Text: Hello, B! + sender: Identity_1, + sent: 1718487783175083, + text: Hello, B! } }, OnDeleteMessage: { @@ -244,9 +520,9 @@ ConnectionId: Guid_1 }, message: { - Sender: Identity_3, - Sent: 1718487787645364, - Text: Goodbye! + sender: Identity_3, + sent: 1718487787645364, + text: Goodbye! } }, OnDeleteMessage: { @@ -262,9 +538,9 @@ ConnectionId: Guid_1 }, message: { - Sender: Identity_1, - Sent: 1718487794937841, - Text: Goodbye! + sender: Identity_1, + sent: 1718487794937841, + text: Goodbye! } }, LogWarning: Subscription Error: $bad query dude, @@ -281,9 +557,9 @@ ConnectionId: Guid_1 }, message: { - Sender: Identity_3, - Sent: 1718487775346381, - Text: Hello, A! + sender: Identity_3, + sent: 1718487775346381, + text: Hello, A! } }, OnInsertMessage: { @@ -299,9 +575,9 @@ ConnectionId: Guid_1 }, message: { - Sender: Identity_1, - Sent: 1718487783175083, - Text: Hello, B! + sender: Identity_1, + sent: 1718487783175083, + text: Hello, B! } }, OnInsertMessage: { @@ -317,9 +593,9 @@ ConnectionId: Guid_1 }, message: { - Sender: Identity_3, - Sent: 1718487787645364, - Text: Goodbye! + sender: Identity_3, + sent: 1718487787645364, + text: Goodbye! } }, OnInsertMessage: { @@ -335,49 +611,49 @@ ConnectionId: Guid_1 }, message: { - Sender: Identity_1, - Sent: 1718487794937841, - Text: Goodbye! + sender: Identity_1, + sent: 1718487794937841, + text: Goodbye! } } }, FinalSnapshot: { User: [ { - Identity: Identity_1, - Name: A, - Online: true + identity: Identity_1, + name: A, + online: true }, { - Identity: Identity_2, - Online: true + identity: Identity_2, + online: true }, { - Identity: Identity_3, - Name: B, - Online: false + identity: Identity_3, + name: B, + online: false } ], Message: [ { - Sender: Identity_1, - Sent: 1718487794937841, - Text: Goodbye! + sender: Identity_1, + sent: 1718487794937841, + text: Goodbye! }, { - Sender: Identity_3, - Sent: 1718487787645364, - Text: Goodbye! + sender: Identity_3, + sent: 1718487787645364, + text: Goodbye! }, { - Sender: Identity_1, - Sent: 1718487783175083, - Text: Hello, B! + sender: Identity_1, + sent: 1718487783175083, + text: Hello, B! }, { - Sender: Identity_3, - Sent: 1718487775346381, - Text: Hello, A! + sender: Identity_3, + sent: 1718487775346381, + text: Hello, A! } ] },