Skip to content

Commit

Permalink
execute gen-client-api.sh against centril/websocket-light
Browse files Browse the repository at this point in the history
support TransactionUpdateLight
support SetReducerFlags
  • Loading branch information
Centril committed Oct 15, 2024
1 parent f1b8fa8 commit 3798ed7
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ internal UserHandle()

public sealed class RemoteReducers : RemoteBase<DbConnection>
{
internal RemoteReducers(DbConnection conn) : base(conn) {}
internal RemoteReducers(DbConnection conn, SetReducerFlags SetReducerFlags) : base(conn) { this.SetCallReducerFlags = SetReducerFlags; }
internal readonly SetReducerFlags SetCallReducerFlags;
public delegate void SendMessageHandler(EventContext ctx, string text);
public event SendMessageHandler? OnSendMessage;

public void SendMessage(string text)
{
conn.InternalCallReducer(new SendMessage { Text = text });
conn.InternalCallReducer(new SendMessage { Text = text }, this.SetCallReducerFlags.SendMessageFlags);
}

public bool InvokeSendMessage(EventContext ctx, SendMessage args)
Expand All @@ -86,7 +87,7 @@ public bool InvokeSendMessage(EventContext ctx, SendMessage args)

public void SetName(string name)
{
conn.InternalCallReducer(new SetName { Name = name });
conn.InternalCallReducer(new SetName { Name = name }, this.SetCallReducerFlags.SetNameFlags);
}

public bool InvokeSetName(EventContext ctx, SetName args)
Expand All @@ -100,14 +101,25 @@ public bool InvokeSetName(EventContext ctx, SetName args)
}
}

public sealed class SetReducerFlags
{
internal SetReducerFlags() { }
internal CallReducerFlags SendMessageFlags;
public void SendMessage(CallReducerFlags flags) { this.SendMessageFlags = flags; }
internal CallReducerFlags SetNameFlags;
public void SetName(CallReducerFlags flags) { this.SetNameFlags = flags; }
}

public partial record EventContext : DbContext<RemoteTables>, IEventContext
{
public readonly RemoteReducers Reducers;
public readonly SetReducerFlags SetReducerFlags;
public readonly Event<Reducer> Event;

internal EventContext(DbConnection conn, Event<Reducer> reducerEvent) : base(conn.Db)
{
Reducers = conn.Reducers;
SetReducerFlags = conn.SetReducerFlags;
Event = reducerEvent;
}
}
Expand All @@ -124,10 +136,12 @@ public class DbConnection : DbConnectionBase<DbConnection, Reducer>
{
public readonly RemoteTables Db = new();
public readonly RemoteReducers Reducers;
public readonly SetReducerFlags SetReducerFlags;

public DbConnection()
{
Reducers = new(this);
SetReducerFlags = new();
Reducers = new(this, this.SetReducerFlags);

clientDB.AddTable<Message>("message", Db.Message);
clientDB.AddTable<User>("user", Db.User);
Expand All @@ -136,7 +150,8 @@ public DbConnection()
protected override Reducer ToReducer(TransactionUpdate update)
{
var encodedArgs = update.ReducerCall.Args;
return update.ReducerCall.ReducerName switch {
return update.ReducerCall.ReducerName switch
{
"send_message" => new Reducer.SendMessage(BSATNHelpers.Decode<SendMessage>(encodedArgs)),
"set_name" => new Reducer.SetName(BSATNHelpers.Decode<SetName>(encodedArgs)),
"<none>" => new Reducer.StdbNone(default),
Expand All @@ -153,7 +168,8 @@ protected override IEventContext ToEventContext(Event<Reducer> reducerEvent) =>
protected override bool Dispatch(IEventContext context, Reducer reducer)
{
var eventContext = (EventContext)context;
return reducer switch {
return reducer switch
{
Reducer.SendMessage(var args) => Reducers.InvokeSendMessage(eventContext, args),
Reducer.SetName(var args) => Reducers.InvokeSetName(eventContext, args),
Reducer.StdbNone or
Expand Down
9 changes: 9 additions & 0 deletions src/CallReducerFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace SpacetimeDB
{
public enum CallReducerFlags : byte
{
// This is the default.
FullUpdate = 0,
NoSuccessNotify = 1,
}
}
1 change: 0 additions & 1 deletion src/SpacetimeDB/ClientApi/BsatnRowList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System;
using SpacetimeDB;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace SpacetimeDB.ClientApi
Expand Down
7 changes: 5 additions & 2 deletions src/SpacetimeDB/ClientApi/CallReducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System;
using SpacetimeDB;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace SpacetimeDB.ClientApi
Expand All @@ -22,16 +21,20 @@ public partial class CallReducer
public byte[] Args;
[DataMember(Name = "request_id")]
public uint RequestId;
[DataMember(Name = "flags")]
public byte Flags;

public CallReducer(
string Reducer,
byte[] Args,
uint RequestId
uint RequestId,
byte Flags
)
{
this.Reducer = Reducer;
this.Args = Args;
this.RequestId = RequestId;
this.Flags = Flags;
}

public CallReducer()
Expand Down
1 change: 0 additions & 1 deletion src/SpacetimeDB/ClientApi/OneOffQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System;
using SpacetimeDB;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace SpacetimeDB.ClientApi
Expand Down
1 change: 0 additions & 1 deletion src/SpacetimeDB/ClientApi/OneOffQueryResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System;
using SpacetimeDB;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace SpacetimeDB.ClientApi
Expand Down
1 change: 0 additions & 1 deletion src/SpacetimeDB/ClientApi/QueryUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System;
using SpacetimeDB;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace SpacetimeDB.ClientApi
Expand Down
1 change: 0 additions & 1 deletion src/SpacetimeDB/ClientApi/ReducerCallInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System;
using SpacetimeDB;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace SpacetimeDB.ClientApi
Expand Down
1 change: 1 addition & 0 deletions src/SpacetimeDB/ClientApi/ServerMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace SpacetimeDB.ClientApi
public partial record ServerMessage : SpacetimeDB.TaggedEnum<(
SpacetimeDB.ClientApi.InitialSubscription InitialSubscription,
SpacetimeDB.ClientApi.TransactionUpdate TransactionUpdate,
SpacetimeDB.ClientApi.TransactionUpdateLight TransactionUpdateLight,
SpacetimeDB.ClientApi.IdentityToken IdentityToken,
SpacetimeDB.ClientApi.OneOffQueryResponse OneOffQueryResponse
)>;
Expand Down
38 changes: 38 additions & 0 deletions src/SpacetimeDB/ClientApi/TransactionUpdateLight.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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;
using SpacetimeDB;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace SpacetimeDB.ClientApi
{
[SpacetimeDB.Type]
[DataContract]
public partial class TransactionUpdateLight
{
[DataMember(Name = "request_id")]
public uint RequestId;
[DataMember(Name = "update")]
public SpacetimeDB.ClientApi.DatabaseUpdate Update;

public TransactionUpdateLight(
uint RequestId,
SpacetimeDB.ClientApi.DatabaseUpdate Update
)
{
this.RequestId = RequestId;
this.Update = Update;
}

public TransactionUpdateLight()
{
this.Update = new();
}

}
}
Loading

0 comments on commit 3798ed7

Please sign in to comment.