-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
554 additions
and
1,910 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,131 +1,43 @@ | ||
// 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 System.Collections.Generic; | ||
using SpacetimeDB; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.Serialization; | ||
|
||
namespace SpacetimeDB.Types | ||
{ | ||
[Newtonsoft.Json.JsonObject(Newtonsoft.Json.MemberSerialization.OptIn)] | ||
public partial class Message : IDatabaseTable | ||
[SpacetimeDB.Type] | ||
[DataContract] | ||
public partial class Message : SpacetimeDB.DatabaseTable<Message, SpacetimeDB.Types.ReducerEvent> | ||
{ | ||
[Newtonsoft.Json.JsonProperty("sender")] | ||
public SpacetimeDB.Identity Sender; | ||
[Newtonsoft.Json.JsonProperty("sent")] | ||
[DataMember(Name = "sender")] | ||
public SpacetimeDB.Identity Sender = new(); | ||
[DataMember(Name = "sent")] | ||
public ulong Sent; | ||
[Newtonsoft.Json.JsonProperty("text")] | ||
public string Text; | ||
|
||
|
||
private static void InternalOnValueInserted(object insertedValue) | ||
{ | ||
var val = (Message)insertedValue; | ||
} | ||
|
||
private static void InternalOnValueDeleted(object deletedValue) | ||
{ | ||
var val = (Message)deletedValue; | ||
} | ||
[DataMember(Name = "text")] | ||
public string Text = ""; | ||
|
||
public static SpacetimeDB.SATS.AlgebraicType GetAlgebraicType() | ||
public static IEnumerable<Message> FilterBySender(SpacetimeDB.Identity value) | ||
{ | ||
return SpacetimeDB.SATS.AlgebraicType.CreateProductType(new SpacetimeDB.SATS.ProductTypeElement[] | ||
{ | ||
new SpacetimeDB.SATS.ProductTypeElement("sender", SpacetimeDB.SATS.AlgebraicType.CreateProductType(new SpacetimeDB.SATS.ProductTypeElement[] | ||
{ | ||
new SpacetimeDB.SATS.ProductTypeElement("__identity_bytes", SpacetimeDB.SATS.AlgebraicType.CreateArrayType(SpacetimeDB.SATS.AlgebraicType.CreatePrimitiveType(SpacetimeDB.SATS.BuiltinType.Type.U8))), | ||
})), | ||
new SpacetimeDB.SATS.ProductTypeElement("sent", SpacetimeDB.SATS.AlgebraicType.CreatePrimitiveType(SpacetimeDB.SATS.BuiltinType.Type.U64)), | ||
new SpacetimeDB.SATS.ProductTypeElement("text", SpacetimeDB.SATS.AlgebraicType.CreatePrimitiveType(SpacetimeDB.SATS.BuiltinType.Type.String)), | ||
}); | ||
return Query(x => x.Sender == value); | ||
} | ||
|
||
public static explicit operator Message(SpacetimeDB.SATS.AlgebraicValue value) | ||
public static IEnumerable<Message> FilterBySent(ulong value) | ||
{ | ||
if (value == null) { | ||
return null; | ||
} | ||
var productValue = value.AsProductValue(); | ||
return new Message | ||
{ | ||
Sender = SpacetimeDB.Identity.From(productValue.elements[0].AsProductValue().elements[0].AsBytes()), | ||
Sent = productValue.elements[1].AsU64(), | ||
Text = productValue.elements[2].AsString(), | ||
}; | ||
return Query(x => x.Sent == value); | ||
} | ||
|
||
public static System.Collections.Generic.IEnumerable<Message> Iter() | ||
{ | ||
foreach(var entry in SpacetimeDBClient.clientDB.GetEntries("Message")) | ||
{ | ||
yield return (Message)entry.Item2; | ||
} | ||
} | ||
public static int Count() | ||
public static IEnumerable<Message> FilterByText(string value) | ||
{ | ||
return SpacetimeDBClient.clientDB.Count("Message"); | ||
} | ||
public static System.Collections.Generic.IEnumerable<Message> FilterBySender(SpacetimeDB.Identity value) | ||
{ | ||
foreach(var entry in SpacetimeDBClient.clientDB.GetEntries("Message")) | ||
{ | ||
var productValue = entry.Item1.AsProductValue(); | ||
var compareValue = Identity.From(productValue.elements[0].AsProductValue().elements[0].AsBytes()); | ||
if (compareValue == value) { | ||
yield return (Message)entry.Item2; | ||
} | ||
} | ||
return Query(x => x.Text == value); | ||
} | ||
|
||
public static System.Collections.Generic.IEnumerable<Message> FilterBySent(ulong value) | ||
{ | ||
foreach(var entry in SpacetimeDBClient.clientDB.GetEntries("Message")) | ||
{ | ||
var productValue = entry.Item1.AsProductValue(); | ||
var compareValue = (ulong)productValue.elements[1].AsU64(); | ||
if (compareValue == value) { | ||
yield return (Message)entry.Item2; | ||
} | ||
} | ||
} | ||
|
||
public static System.Collections.Generic.IEnumerable<Message> FilterByText(string value) | ||
{ | ||
foreach(var entry in SpacetimeDBClient.clientDB.GetEntries("Message")) | ||
{ | ||
var productValue = entry.Item1.AsProductValue(); | ||
var compareValue = (string)productValue.elements[2].AsString(); | ||
if (compareValue == value) { | ||
yield return (Message)entry.Item2; | ||
} | ||
} | ||
} | ||
|
||
public static bool ComparePrimaryKey(SpacetimeDB.SATS.AlgebraicType t, SpacetimeDB.SATS.AlgebraicValue _v1, SpacetimeDB.SATS.AlgebraicValue _v2) | ||
{ | ||
return false; | ||
} | ||
|
||
public delegate void InsertEventHandler(Message insertedValue, SpacetimeDB.Types.ReducerEvent dbEvent); | ||
public delegate void DeleteEventHandler(Message deletedValue, SpacetimeDB.Types.ReducerEvent dbEvent); | ||
public static event InsertEventHandler OnInsert; | ||
public static event DeleteEventHandler OnBeforeDelete; | ||
public static event DeleteEventHandler OnDelete; | ||
|
||
public static void OnInsertEvent(object newValue, ClientApi.Event dbEvent) | ||
{ | ||
OnInsert?.Invoke((Message)newValue,(ReducerEvent)dbEvent?.FunctionCall.CallInfo); | ||
} | ||
|
||
public static void OnBeforeDeleteEvent(object oldValue, ClientApi.Event dbEvent) | ||
{ | ||
OnBeforeDelete?.Invoke((Message)oldValue,(ReducerEvent)dbEvent?.FunctionCall.CallInfo); | ||
} | ||
|
||
public static void OnDeleteEvent(object oldValue, ClientApi.Event dbEvent) | ||
{ | ||
OnDelete?.Invoke((Message)oldValue,(ReducerEvent)dbEvent?.FunctionCall.CallInfo); | ||
} | ||
} | ||
} |
67 changes: 0 additions & 67 deletions
67
examples/quickstart/client/module_bindings/ReducerEvent.cs
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
examples/quickstart/client/module_bindings/ReducerJsonSettings.cs
This file was deleted.
Oops, something went wrong.
62 changes: 22 additions & 40 deletions
62
examples/quickstart/client/module_bindings/SendMessageReducer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,43 @@ | ||
// 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 ClientApi; | ||
using Newtonsoft.Json.Linq; | ||
using SpacetimeDB; | ||
|
||
namespace SpacetimeDB.Types | ||
{ | ||
[SpacetimeDB.Type] | ||
public partial class SendMessageArgsStruct : IReducerArgs | ||
{ | ||
ReducerType IReducerArgs.ReducerType => ReducerType.SendMessage; | ||
string IReducerArgsBase.ReducerName => "send_message"; | ||
bool IReducerArgs.InvokeHandler(ReducerEvent reducerEvent) => Reducer.OnSendMessage(reducerEvent, this); | ||
|
||
public string Text = ""; | ||
} | ||
|
||
public static partial class Reducer | ||
{ | ||
public delegate void SendMessageHandler(ReducerEvent reducerEvent, string text); | ||
public static event SendMessageHandler OnSendMessageEvent; | ||
public static event SendMessageHandler? OnSendMessageEvent; | ||
|
||
public static void SendMessage(string text) | ||
{ | ||
var _argArray = new object[] {text}; | ||
var _message = new SpacetimeDBClient.ReducerCallRequest { | ||
fn = "send_message", | ||
args = _argArray, | ||
}; | ||
SpacetimeDBClient.instance.InternalCallReducer(Newtonsoft.Json.JsonConvert.SerializeObject(_message, _settings)); | ||
SpacetimeDBClient.instance.InternalCallReducer(new SendMessageArgsStruct { Text = text }); | ||
} | ||
|
||
[ReducerCallback(FunctionName = "send_message")] | ||
public static bool OnSendMessage(ClientApi.Event dbEvent) | ||
public static bool OnSendMessage(ReducerEvent reducerEvent, SendMessageArgsStruct args) | ||
{ | ||
if(OnSendMessageEvent != null) | ||
{ | ||
var args = ((ReducerEvent)dbEvent.FunctionCall.CallInfo).SendMessageArgs; | ||
OnSendMessageEvent((ReducerEvent)dbEvent.FunctionCall.CallInfo | ||
,(string)args.Text | ||
); | ||
return true; | ||
} | ||
return false; | ||
if (OnSendMessageEvent == null) return false; | ||
OnSendMessageEvent( | ||
reducerEvent, | ||
args.Text | ||
); | ||
return true; | ||
} | ||
|
||
[DeserializeEvent(FunctionName = "send_message")] | ||
public static void SendMessageDeserializeEventArgs(ClientApi.Event dbEvent) | ||
{ | ||
var args = new SendMessageArgsStruct(); | ||
var bsatnBytes = dbEvent.FunctionCall.ArgBytes; | ||
using var ms = new System.IO.MemoryStream(); | ||
ms.SetLength(bsatnBytes.Length); | ||
bsatnBytes.CopyTo(ms.GetBuffer(), 0); | ||
ms.Position = 0; | ||
using var reader = new System.IO.BinaryReader(ms); | ||
var args_0_value = SpacetimeDB.SATS.AlgebraicValue.Deserialize(SpacetimeDB.SATS.AlgebraicType.CreatePrimitiveType(SpacetimeDB.SATS.BuiltinType.Type.String), reader); | ||
args.Text = args_0_value.AsString(); | ||
dbEvent.FunctionCall.CallInfo = new ReducerEvent(ReducerType.SendMessage, "send_message", dbEvent.Timestamp, Identity.From(dbEvent.CallerIdentity.ToByteArray()), Address.From(dbEvent.CallerAddress.ToByteArray()), dbEvent.Message, dbEvent.Status, args); | ||
} | ||
} | ||
|
||
public partial class SendMessageArgsStruct | ||
{ | ||
public string Text; | ||
} | ||
|
||
} |
Oops, something went wrong.