mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-05-06 07:26:43 -04:00
833 lines
26 KiB
Plaintext
833 lines
26 KiB
Plaintext
---
|
|
source: crates/cli/tests/codegen.rs
|
|
expression: outfiles
|
|
---
|
|
"AddPlayerReducer.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
|
|
using System;
|
|
using ClientApi;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
public static partial class Reducer
|
|
{
|
|
public static event Action<ClientApi.Event.Types.Status, Identity, string> OnAddPlayerEvent;
|
|
|
|
public static void AddPlayer(string name)
|
|
{
|
|
var _argArray = new object[] {name};
|
|
var _message = new NetworkManager.ReducerCallRequest {
|
|
fn = "add_player",
|
|
args = _argArray,
|
|
};
|
|
Newtonsoft.Json.JsonSerializerSettings _settings = new Newtonsoft.Json.JsonSerializerSettings
|
|
{
|
|
Converters = { new SpacetimeDB.SomeWrapperConverter(), new SpacetimeDB.EnumWrapperConverter() },
|
|
ContractResolver = new SpacetimeDB.JsonContractResolver(),
|
|
};
|
|
NetworkManager.instance.InternalCallReducer(Newtonsoft.Json.JsonConvert.SerializeObject(_message, _settings));
|
|
}
|
|
|
|
[ReducerCallback(FunctionName = "add_player")]
|
|
public static void OnAddPlayer(ClientApi.Event dbEvent)
|
|
{
|
|
if(OnAddPlayerEvent != null)
|
|
{
|
|
var args = dbEvent.FunctionCall.CallInfo.AddPlayerArgs;
|
|
OnAddPlayerEvent(dbEvent.Status, Identity.From(dbEvent.CallerIdentity.ToByteArray())
|
|
,(string)args.Name
|
|
);
|
|
}
|
|
}
|
|
[DeserializeEvent(FunctionName = "add_player")]
|
|
public static void AddPlayerDeserializeEventArgs(ClientApi.Event dbEvent)
|
|
{
|
|
var args = new AddPlayerArgsStruct();
|
|
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.Name = args_0_value.AsString();
|
|
var argsGeneric = new ReducerArgs();
|
|
argsGeneric.AddPlayerArgs = args;
|
|
dbEvent.FunctionCall.CallInfo = new ReducerEvent(ReducerType.AddPlayer, dbEvent.Message, dbEvent.Status, argsGeneric);
|
|
}
|
|
}
|
|
|
|
public struct AddPlayerArgsStruct
|
|
{
|
|
public string Name;
|
|
}
|
|
|
|
public partial struct ReducerArgs
|
|
{
|
|
[System.Runtime.InteropServices.FieldOffset(0)]
|
|
public AddPlayerArgsStruct AddPlayerArgs;
|
|
}
|
|
|
|
public partial class ReducerEvent
|
|
{
|
|
public AddPlayerArgsStruct AddPlayerArgs
|
|
{
|
|
get
|
|
{
|
|
if (Reducer != ReducerType.AddPlayer) throw new SpacetimeDB.ReducerMismatchException(Reducer.ToString(), "AddPlayer");
|
|
return Args.AddPlayerArgs;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
'''
|
|
"NamespaceTestC.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
|
|
using System;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
public partial class Namespace
|
|
{
|
|
public partial class Types
|
|
{
|
|
public enum TestC
|
|
{
|
|
Foo,
|
|
Bar,
|
|
}
|
|
}
|
|
public static SpacetimeDB.SATS.AlgebraicType GetAlgebraicTypeForTestC()
|
|
{
|
|
return SpacetimeDB.SATS.AlgebraicType.CreateSumType(new System.Collections.Generic.List<SpacetimeDB.SATS.SumTypeVariant>
|
|
{
|
|
new SpacetimeDB.SATS.SumTypeVariant("Foo", SpacetimeDB.SATS.AlgebraicType.CreateProductType(new SpacetimeDB.SATS.ProductTypeElement[]
|
|
{
|
|
})),
|
|
new SpacetimeDB.SATS.SumTypeVariant("Bar", SpacetimeDB.SATS.AlgebraicType.CreateProductType(new SpacetimeDB.SATS.ProductTypeElement[]
|
|
{
|
|
})),
|
|
});
|
|
}
|
|
public static Namespace.Types.TestC IntoTestC(SpacetimeDB.SATS.AlgebraicValue value)
|
|
{
|
|
var sumValue = value.AsSumValue();
|
|
switch(sumValue.tag)
|
|
{
|
|
case 0:
|
|
return Namespace.Types.TestC.Foo;
|
|
case 1:
|
|
return Namespace.Types.TestC.Bar;
|
|
}
|
|
|
|
return default;
|
|
}
|
|
}
|
|
}
|
|
'''
|
|
"ReducerEvent.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
|
|
using System;
|
|
using ClientApi;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
public enum ReducerType
|
|
{
|
|
Update,
|
|
AddPlayer,
|
|
RepeatingTest,
|
|
Test,
|
|
}
|
|
|
|
public partial class ReducerEvent
|
|
{
|
|
public ReducerType Reducer { get; private set; }
|
|
public string ErrMessage { get; private set; }
|
|
public ClientApi.Event.Types.Status Status { get; private set; }
|
|
private ReducerArgs Args;
|
|
|
|
public ReducerEvent(ReducerType reducer, string errMessage, ClientApi.Event.Types.Status status, ReducerArgs args)
|
|
{
|
|
Reducer = reducer;
|
|
ErrMessage = errMessage;
|
|
Status = status;
|
|
Args = args;
|
|
}
|
|
|
|
public object[] GetArgsAsObjectArray()
|
|
{
|
|
switch (Reducer)
|
|
{
|
|
case ReducerType.Update:
|
|
{
|
|
var args = UpdateArgs;
|
|
return new object[] {
|
|
};
|
|
}
|
|
case ReducerType.AddPlayer:
|
|
{
|
|
var args = AddPlayerArgs;
|
|
return new object[] {
|
|
args.Name,
|
|
};
|
|
}
|
|
case ReducerType.RepeatingTest:
|
|
{
|
|
var args = RepeatingTestArgs;
|
|
return new object[] {
|
|
args.PrevTime,
|
|
};
|
|
}
|
|
case ReducerType.Test:
|
|
{
|
|
var args = TestArgs;
|
|
return new object[] {
|
|
args.Arg,
|
|
args.Arg2,
|
|
args.Arg3,
|
|
};
|
|
}
|
|
default: throw new System.Exception($"Unhandled reducer case: {Reducer}. Please run SpacetimeDB code generator");
|
|
}
|
|
}
|
|
}
|
|
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Explicit)]
|
|
public partial struct ReducerArgs { }
|
|
}
|
|
'''
|
|
"RepeatingTestReducer.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
|
|
using System;
|
|
using ClientApi;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
public static partial class Reducer
|
|
{
|
|
public static event Action<ClientApi.Event.Types.Status, Identity, ulong> OnRepeatingTestEvent;
|
|
|
|
public static void RepeatingTest(ulong prevTime)
|
|
{
|
|
var _argArray = new object[] {prevTime};
|
|
var _message = new NetworkManager.ReducerCallRequest {
|
|
fn = "repeating_test",
|
|
args = _argArray,
|
|
};
|
|
Newtonsoft.Json.JsonSerializerSettings _settings = new Newtonsoft.Json.JsonSerializerSettings
|
|
{
|
|
Converters = { new SpacetimeDB.SomeWrapperConverter(), new SpacetimeDB.EnumWrapperConverter() },
|
|
ContractResolver = new SpacetimeDB.JsonContractResolver(),
|
|
};
|
|
NetworkManager.instance.InternalCallReducer(Newtonsoft.Json.JsonConvert.SerializeObject(_message, _settings));
|
|
}
|
|
|
|
[ReducerCallback(FunctionName = "repeating_test")]
|
|
public static void OnRepeatingTest(ClientApi.Event dbEvent)
|
|
{
|
|
if(OnRepeatingTestEvent != null)
|
|
{
|
|
var args = dbEvent.FunctionCall.CallInfo.RepeatingTestArgs;
|
|
OnRepeatingTestEvent(dbEvent.Status, Identity.From(dbEvent.CallerIdentity.ToByteArray())
|
|
,(ulong)args.PrevTime
|
|
);
|
|
}
|
|
}
|
|
[DeserializeEvent(FunctionName = "repeating_test")]
|
|
public static void RepeatingTestDeserializeEventArgs(ClientApi.Event dbEvent)
|
|
{
|
|
var args = new RepeatingTestArgsStruct();
|
|
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.U64), reader);
|
|
args.PrevTime = args_0_value.AsU64();
|
|
var argsGeneric = new ReducerArgs();
|
|
argsGeneric.RepeatingTestArgs = args;
|
|
dbEvent.FunctionCall.CallInfo = new ReducerEvent(ReducerType.RepeatingTest, dbEvent.Message, dbEvent.Status, argsGeneric);
|
|
}
|
|
}
|
|
|
|
public struct RepeatingTestArgsStruct
|
|
{
|
|
public ulong PrevTime;
|
|
}
|
|
|
|
public partial struct ReducerArgs
|
|
{
|
|
[System.Runtime.InteropServices.FieldOffset(0)]
|
|
public RepeatingTestArgsStruct RepeatingTestArgs;
|
|
}
|
|
|
|
public partial class ReducerEvent
|
|
{
|
|
public RepeatingTestArgsStruct RepeatingTestArgs
|
|
{
|
|
get
|
|
{
|
|
if (Reducer != ReducerType.RepeatingTest) throw new SpacetimeDB.ReducerMismatchException(Reducer.ToString(), "RepeatingTest");
|
|
return Args.RepeatingTestArgs;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
'''
|
|
"TestA.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
|
|
using System;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
public partial class TestA : IDatabaseTable
|
|
{
|
|
[Newtonsoft.Json.JsonProperty("x")]
|
|
public uint X;
|
|
[Newtonsoft.Json.JsonProperty("y")]
|
|
public uint Y;
|
|
[Newtonsoft.Json.JsonProperty("z")]
|
|
public string Z;
|
|
|
|
public static SpacetimeDB.SATS.AlgebraicType GetAlgebraicType()
|
|
{
|
|
return SpacetimeDB.SATS.AlgebraicType.CreateProductType(new SpacetimeDB.SATS.ProductTypeElement[]
|
|
{
|
|
new SpacetimeDB.SATS.ProductTypeElement("x", SpacetimeDB.SATS.AlgebraicType.CreatePrimitiveType(SpacetimeDB.SATS.BuiltinType.Type.U32)),
|
|
new SpacetimeDB.SATS.ProductTypeElement("y", SpacetimeDB.SATS.AlgebraicType.CreatePrimitiveType(SpacetimeDB.SATS.BuiltinType.Type.U32)),
|
|
new SpacetimeDB.SATS.ProductTypeElement("z", SpacetimeDB.SATS.AlgebraicType.CreatePrimitiveType(SpacetimeDB.SATS.BuiltinType.Type.String)),
|
|
});
|
|
}
|
|
|
|
public static explicit operator TestA(SpacetimeDB.SATS.AlgebraicValue value)
|
|
{
|
|
if (value == null) {
|
|
return null;
|
|
}
|
|
var productValue = value.AsProductValue();
|
|
return new TestA
|
|
{
|
|
X = productValue.elements[0].AsU32(),
|
|
Y = productValue.elements[1].AsU32(),
|
|
Z = productValue.elements[2].AsString(),
|
|
};
|
|
}
|
|
|
|
public static System.Collections.Generic.IEnumerable<TestA> Iter()
|
|
{
|
|
foreach(var entry in NetworkManager.clientDB.GetEntries("TestA"))
|
|
{
|
|
yield return (TestA)entry.Item2;
|
|
}
|
|
}
|
|
public static int Count()
|
|
{
|
|
return NetworkManager.clientDB.Count("TestA");
|
|
}
|
|
public static System.Collections.Generic.IEnumerable<TestA> FilterByX(uint value)
|
|
{
|
|
foreach(var entry in NetworkManager.clientDB.GetEntries("TestA"))
|
|
{
|
|
var productValue = entry.Item1.AsProductValue();
|
|
var compareValue = (uint)productValue.elements[0].AsU32();
|
|
if (compareValue == value) {
|
|
yield return (TestA)entry.Item2;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static System.Collections.Generic.IEnumerable<TestA> FilterByY(uint value)
|
|
{
|
|
foreach(var entry in NetworkManager.clientDB.GetEntries("TestA"))
|
|
{
|
|
var productValue = entry.Item1.AsProductValue();
|
|
var compareValue = (uint)productValue.elements[1].AsU32();
|
|
if (compareValue == value) {
|
|
yield return (TestA)entry.Item2;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static System.Collections.Generic.IEnumerable<TestA> FilterByZ(string value)
|
|
{
|
|
foreach(var entry in NetworkManager.clientDB.GetEntries("TestA"))
|
|
{
|
|
var productValue = entry.Item1.AsProductValue();
|
|
var compareValue = (string)productValue.elements[2].AsString();
|
|
if (compareValue == value) {
|
|
yield return (TestA)entry.Item2;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static bool ComparePrimaryKey(SpacetimeDB.SATS.AlgebraicType t, SpacetimeDB.SATS.AlgebraicValue _v1, SpacetimeDB.SATS.AlgebraicValue _v2)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public delegate void InsertEventHandler(TestA insertedValue, SpacetimeDB.ReducerEvent dbEvent);
|
|
public delegate void UpdateEventHandler(TestA oldValue, TestA newValue, SpacetimeDB.ReducerEvent dbEvent);
|
|
public delegate void DeleteEventHandler(TestA deletedValue, SpacetimeDB.ReducerEvent dbEvent);
|
|
public delegate void RowUpdateEventHandler(NetworkManager.TableOp op, TestA oldValue, TestA newValue, SpacetimeDB.ReducerEvent dbEvent);
|
|
public static event InsertEventHandler OnInsert;
|
|
public static event UpdateEventHandler OnUpdate;
|
|
public static event DeleteEventHandler OnBeforeDelete;
|
|
public static event DeleteEventHandler OnDelete;
|
|
public static event RowUpdateEventHandler OnRowUpdate;
|
|
|
|
public static void OnInsertEvent(object newValue, ClientApi.Event dbEvent)
|
|
{
|
|
OnInsert?.Invoke((TestA)newValue,dbEvent?.FunctionCall.CallInfo);
|
|
}
|
|
|
|
public static void OnUpdateEvent(object oldValue, object newValue, ClientApi.Event dbEvent)
|
|
{
|
|
OnUpdate?.Invoke((TestA)oldValue,(TestA)newValue,dbEvent?.FunctionCall.CallInfo);
|
|
}
|
|
|
|
public static void OnBeforeDeleteEvent(object oldValue, ClientApi.Event dbEvent)
|
|
{
|
|
OnBeforeDelete?.Invoke((TestA)oldValue,dbEvent?.FunctionCall.CallInfo);
|
|
}
|
|
|
|
public static void OnDeleteEvent(object oldValue, ClientApi.Event dbEvent)
|
|
{
|
|
OnDelete?.Invoke((TestA)oldValue,dbEvent?.FunctionCall.CallInfo);
|
|
}
|
|
|
|
public static void OnRowUpdateEvent(NetworkManager.TableOp op, object oldValue, object newValue, ClientApi.Event dbEvent)
|
|
{
|
|
OnRowUpdate?.Invoke(op, (TestA)oldValue,(TestA)newValue,dbEvent?.FunctionCall.CallInfo);
|
|
}
|
|
}
|
|
}
|
|
'''
|
|
"TestB.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
|
|
using System;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
public partial class TestB : IDatabaseTable
|
|
{
|
|
[Newtonsoft.Json.JsonProperty("foo")]
|
|
public string Foo;
|
|
|
|
public static SpacetimeDB.SATS.AlgebraicType GetAlgebraicType()
|
|
{
|
|
return SpacetimeDB.SATS.AlgebraicType.CreateProductType(new SpacetimeDB.SATS.ProductTypeElement[]
|
|
{
|
|
new SpacetimeDB.SATS.ProductTypeElement("foo", SpacetimeDB.SATS.AlgebraicType.CreatePrimitiveType(SpacetimeDB.SATS.BuiltinType.Type.String)),
|
|
});
|
|
}
|
|
|
|
public static explicit operator TestB(SpacetimeDB.SATS.AlgebraicValue value)
|
|
{
|
|
if (value == null) {
|
|
return null;
|
|
}
|
|
var productValue = value.AsProductValue();
|
|
return new TestB
|
|
{
|
|
Foo = productValue.elements[0].AsString(),
|
|
};
|
|
}
|
|
|
|
}
|
|
}
|
|
'''
|
|
"TestD.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
|
|
using System;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
public partial class TestD : IDatabaseTable
|
|
{
|
|
[Newtonsoft.Json.JsonProperty("test_c")]
|
|
[SpacetimeDB.Some]
|
|
public SpacetimeDB.Namespace.Types.TestC TestC;
|
|
|
|
public static SpacetimeDB.SATS.AlgebraicType GetAlgebraicType()
|
|
{
|
|
return SpacetimeDB.SATS.AlgebraicType.CreateProductType(new SpacetimeDB.SATS.ProductTypeElement[]
|
|
{
|
|
new SpacetimeDB.SATS.ProductTypeElement("test_c", SpacetimeDB.SATS.AlgebraicType.CreateSumType(new System.Collections.Generic.List<SpacetimeDB.SATS.SumTypeVariant>
|
|
{
|
|
new SpacetimeDB.SATS.SumTypeVariant("some", SpacetimeDB.Namespace.GetAlgebraicTypeForTestC()),
|
|
new SpacetimeDB.SATS.SumTypeVariant("none", SpacetimeDB.SATS.AlgebraicType.CreateProductType(new SpacetimeDB.SATS.ProductTypeElement[]
|
|
{
|
|
})),
|
|
})),
|
|
});
|
|
}
|
|
|
|
public static explicit operator TestD(SpacetimeDB.SATS.AlgebraicValue value)
|
|
{
|
|
if (value == null) {
|
|
return null;
|
|
}
|
|
var productValue = value.AsProductValue();
|
|
return new TestD
|
|
{
|
|
TestC = SpacetimeDB.Namespace.IntoTestC(productValue.elements[0].AsSumValue().tag == 1 ? null : productValue.elements[0].AsSumValue().value),
|
|
};
|
|
}
|
|
|
|
public static System.Collections.Generic.IEnumerable<TestD> Iter()
|
|
{
|
|
foreach(var entry in NetworkManager.clientDB.GetEntries("TestD"))
|
|
{
|
|
yield return (TestD)entry.Item2;
|
|
}
|
|
}
|
|
public static int Count()
|
|
{
|
|
return NetworkManager.clientDB.Count("TestD");
|
|
}
|
|
public static bool ComparePrimaryKey(SpacetimeDB.SATS.AlgebraicType t, SpacetimeDB.SATS.AlgebraicValue _v1, SpacetimeDB.SATS.AlgebraicValue _v2)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public delegate void InsertEventHandler(TestD insertedValue, SpacetimeDB.ReducerEvent dbEvent);
|
|
public delegate void UpdateEventHandler(TestD oldValue, TestD newValue, SpacetimeDB.ReducerEvent dbEvent);
|
|
public delegate void DeleteEventHandler(TestD deletedValue, SpacetimeDB.ReducerEvent dbEvent);
|
|
public delegate void RowUpdateEventHandler(NetworkManager.TableOp op, TestD oldValue, TestD newValue, SpacetimeDB.ReducerEvent dbEvent);
|
|
public static event InsertEventHandler OnInsert;
|
|
public static event UpdateEventHandler OnUpdate;
|
|
public static event DeleteEventHandler OnBeforeDelete;
|
|
public static event DeleteEventHandler OnDelete;
|
|
public static event RowUpdateEventHandler OnRowUpdate;
|
|
|
|
public static void OnInsertEvent(object newValue, ClientApi.Event dbEvent)
|
|
{
|
|
OnInsert?.Invoke((TestD)newValue,dbEvent?.FunctionCall.CallInfo);
|
|
}
|
|
|
|
public static void OnUpdateEvent(object oldValue, object newValue, ClientApi.Event dbEvent)
|
|
{
|
|
OnUpdate?.Invoke((TestD)oldValue,(TestD)newValue,dbEvent?.FunctionCall.CallInfo);
|
|
}
|
|
|
|
public static void OnBeforeDeleteEvent(object oldValue, ClientApi.Event dbEvent)
|
|
{
|
|
OnBeforeDelete?.Invoke((TestD)oldValue,dbEvent?.FunctionCall.CallInfo);
|
|
}
|
|
|
|
public static void OnDeleteEvent(object oldValue, ClientApi.Event dbEvent)
|
|
{
|
|
OnDelete?.Invoke((TestD)oldValue,dbEvent?.FunctionCall.CallInfo);
|
|
}
|
|
|
|
public static void OnRowUpdateEvent(NetworkManager.TableOp op, object oldValue, object newValue, ClientApi.Event dbEvent)
|
|
{
|
|
OnRowUpdate?.Invoke(op, (TestD)oldValue,(TestD)newValue,dbEvent?.FunctionCall.CallInfo);
|
|
}
|
|
}
|
|
}
|
|
'''
|
|
"TestE.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
|
|
using System;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
public partial class TestE : IDatabaseTable
|
|
{
|
|
[Newtonsoft.Json.JsonProperty("id")]
|
|
public ulong Id;
|
|
[Newtonsoft.Json.JsonProperty("name")]
|
|
public string Name;
|
|
|
|
public static SpacetimeDB.SATS.AlgebraicType GetAlgebraicType()
|
|
{
|
|
return SpacetimeDB.SATS.AlgebraicType.CreateProductType(new SpacetimeDB.SATS.ProductTypeElement[]
|
|
{
|
|
new SpacetimeDB.SATS.ProductTypeElement("id", SpacetimeDB.SATS.AlgebraicType.CreatePrimitiveType(SpacetimeDB.SATS.BuiltinType.Type.U64)),
|
|
new SpacetimeDB.SATS.ProductTypeElement("name", SpacetimeDB.SATS.AlgebraicType.CreatePrimitiveType(SpacetimeDB.SATS.BuiltinType.Type.String)),
|
|
});
|
|
}
|
|
|
|
public static explicit operator TestE(SpacetimeDB.SATS.AlgebraicValue value)
|
|
{
|
|
if (value == null) {
|
|
return null;
|
|
}
|
|
var productValue = value.AsProductValue();
|
|
return new TestE
|
|
{
|
|
Id = productValue.elements[0].AsU64(),
|
|
Name = productValue.elements[1].AsString(),
|
|
};
|
|
}
|
|
|
|
public static System.Collections.Generic.IEnumerable<TestE> Iter()
|
|
{
|
|
foreach(var entry in NetworkManager.clientDB.GetEntries("TestE"))
|
|
{
|
|
yield return (TestE)entry.Item2;
|
|
}
|
|
}
|
|
public static int Count()
|
|
{
|
|
return NetworkManager.clientDB.Count("TestE");
|
|
}
|
|
public static TestE FilterById(ulong value)
|
|
{
|
|
foreach(var entry in NetworkManager.clientDB.GetEntries("TestE"))
|
|
{
|
|
var productValue = entry.Item1.AsProductValue();
|
|
var compareValue = (ulong)productValue.elements[0].AsU64();
|
|
if (compareValue == value) {
|
|
return (TestE)entry.Item2;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static System.Collections.Generic.IEnumerable<TestE> FilterByName(string value)
|
|
{
|
|
foreach(var entry in NetworkManager.clientDB.GetEntries("TestE"))
|
|
{
|
|
var productValue = entry.Item1.AsProductValue();
|
|
var compareValue = (string)productValue.elements[1].AsString();
|
|
if (compareValue == value) {
|
|
yield return (TestE)entry.Item2;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static bool ComparePrimaryKey(SpacetimeDB.SATS.AlgebraicType t, SpacetimeDB.SATS.AlgebraicValue v1, SpacetimeDB.SATS.AlgebraicValue v2)
|
|
{
|
|
var primaryColumnValue1 = v1.AsProductValue().elements[0];
|
|
var primaryColumnValue2 = v2.AsProductValue().elements[0];
|
|
return SpacetimeDB.SATS.AlgebraicValue.Compare(t.product.elements[0].algebraicType, primaryColumnValue1, primaryColumnValue2);
|
|
}
|
|
|
|
public delegate void InsertEventHandler(TestE insertedValue, SpacetimeDB.ReducerEvent dbEvent);
|
|
public delegate void UpdateEventHandler(TestE oldValue, TestE newValue, SpacetimeDB.ReducerEvent dbEvent);
|
|
public delegate void DeleteEventHandler(TestE deletedValue, SpacetimeDB.ReducerEvent dbEvent);
|
|
public delegate void RowUpdateEventHandler(NetworkManager.TableOp op, TestE oldValue, TestE newValue, SpacetimeDB.ReducerEvent dbEvent);
|
|
public static event InsertEventHandler OnInsert;
|
|
public static event UpdateEventHandler OnUpdate;
|
|
public static event DeleteEventHandler OnBeforeDelete;
|
|
public static event DeleteEventHandler OnDelete;
|
|
public static event RowUpdateEventHandler OnRowUpdate;
|
|
|
|
public static void OnInsertEvent(object newValue, ClientApi.Event dbEvent)
|
|
{
|
|
OnInsert?.Invoke((TestE)newValue,dbEvent?.FunctionCall.CallInfo);
|
|
}
|
|
|
|
public static void OnUpdateEvent(object oldValue, object newValue, ClientApi.Event dbEvent)
|
|
{
|
|
OnUpdate?.Invoke((TestE)oldValue,(TestE)newValue,dbEvent?.FunctionCall.CallInfo);
|
|
}
|
|
|
|
public static void OnBeforeDeleteEvent(object oldValue, ClientApi.Event dbEvent)
|
|
{
|
|
OnBeforeDelete?.Invoke((TestE)oldValue,dbEvent?.FunctionCall.CallInfo);
|
|
}
|
|
|
|
public static void OnDeleteEvent(object oldValue, ClientApi.Event dbEvent)
|
|
{
|
|
OnDelete?.Invoke((TestE)oldValue,dbEvent?.FunctionCall.CallInfo);
|
|
}
|
|
|
|
public static void OnRowUpdateEvent(NetworkManager.TableOp op, object oldValue, object newValue, ClientApi.Event dbEvent)
|
|
{
|
|
OnRowUpdate?.Invoke(op, (TestE)oldValue,(TestE)newValue,dbEvent?.FunctionCall.CallInfo);
|
|
}
|
|
}
|
|
}
|
|
'''
|
|
"TestReducer.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
|
|
using System;
|
|
using ClientApi;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
public static partial class Reducer
|
|
{
|
|
public static event Action<ClientApi.Event.Types.Status, Identity, SpacetimeDB.TestA, SpacetimeDB.TestB, SpacetimeDB.Namespace.Types.TestC> OnTestEvent;
|
|
|
|
public static void Test(SpacetimeDB.TestA arg, SpacetimeDB.TestB arg2, SpacetimeDB.Namespace.Types.TestC arg3)
|
|
{
|
|
var _argArray = new object[] {arg, arg2, new EnumWrapper<SpacetimeDB.Namespace.Types.TestC>(arg3)};
|
|
var _message = new NetworkManager.ReducerCallRequest {
|
|
fn = "test",
|
|
args = _argArray,
|
|
};
|
|
Newtonsoft.Json.JsonSerializerSettings _settings = new Newtonsoft.Json.JsonSerializerSettings
|
|
{
|
|
Converters = { new SpacetimeDB.SomeWrapperConverter(), new SpacetimeDB.EnumWrapperConverter() },
|
|
ContractResolver = new SpacetimeDB.JsonContractResolver(),
|
|
};
|
|
NetworkManager.instance.InternalCallReducer(Newtonsoft.Json.JsonConvert.SerializeObject(_message, _settings));
|
|
}
|
|
|
|
[ReducerCallback(FunctionName = "test")]
|
|
public static void OnTest(ClientApi.Event dbEvent)
|
|
{
|
|
if(OnTestEvent != null)
|
|
{
|
|
var args = dbEvent.FunctionCall.CallInfo.TestArgs;
|
|
OnTestEvent(dbEvent.Status, Identity.From(dbEvent.CallerIdentity.ToByteArray())
|
|
,(SpacetimeDB.TestA)args.Arg
|
|
,(SpacetimeDB.TestB)args.Arg2
|
|
,(SpacetimeDB.Namespace.Types.TestC)args.Arg3
|
|
);
|
|
}
|
|
}
|
|
[DeserializeEvent(FunctionName = "test")]
|
|
public static void TestDeserializeEventArgs(ClientApi.Event dbEvent)
|
|
{
|
|
var args = new TestArgsStruct();
|
|
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.TestA.GetAlgebraicType(), reader);
|
|
args.Arg = (SpacetimeDB.TestA)(args_0_value);
|
|
var args_1_value = SpacetimeDB.SATS.AlgebraicValue.Deserialize(SpacetimeDB.TestB.GetAlgebraicType(), reader);
|
|
args.Arg2 = (SpacetimeDB.TestB)(args_1_value);
|
|
var args_2_value = SpacetimeDB.SATS.AlgebraicValue.Deserialize(SpacetimeDB.Namespace.GetAlgebraicTypeForTestC(), reader);
|
|
args.Arg3 = SpacetimeDB.Namespace.IntoTestC(args_2_value);
|
|
var argsGeneric = new ReducerArgs();
|
|
argsGeneric.TestArgs = args;
|
|
dbEvent.FunctionCall.CallInfo = new ReducerEvent(ReducerType.Test, dbEvent.Message, dbEvent.Status, argsGeneric);
|
|
}
|
|
}
|
|
|
|
public struct TestArgsStruct
|
|
{
|
|
public SpacetimeDB.TestA Arg;
|
|
public SpacetimeDB.TestB Arg2;
|
|
public SpacetimeDB.Namespace.Types.TestC Arg3;
|
|
}
|
|
|
|
public partial struct ReducerArgs
|
|
{
|
|
[System.Runtime.InteropServices.FieldOffset(0)]
|
|
public TestArgsStruct TestArgs;
|
|
}
|
|
|
|
public partial class ReducerEvent
|
|
{
|
|
public TestArgsStruct TestArgs
|
|
{
|
|
get
|
|
{
|
|
if (Reducer != ReducerType.Test) throw new SpacetimeDB.ReducerMismatchException(Reducer.ToString(), "Test");
|
|
return Args.TestArgs;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
'''
|
|
"UpdateReducer.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
|
|
using System;
|
|
using ClientApi;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
public static partial class Reducer
|
|
{
|
|
public static event Action<ClientApi.Event.Types.Status, Identity> OnUpdateEvent;
|
|
|
|
public static void Update()
|
|
{
|
|
var _argArray = new object[] {};
|
|
var _message = new NetworkManager.ReducerCallRequest {
|
|
fn = "__update__",
|
|
args = _argArray,
|
|
};
|
|
Newtonsoft.Json.JsonSerializerSettings _settings = new Newtonsoft.Json.JsonSerializerSettings
|
|
{
|
|
Converters = { new SpacetimeDB.SomeWrapperConverter(), new SpacetimeDB.EnumWrapperConverter() },
|
|
ContractResolver = new SpacetimeDB.JsonContractResolver(),
|
|
};
|
|
NetworkManager.instance.InternalCallReducer(Newtonsoft.Json.JsonConvert.SerializeObject(_message, _settings));
|
|
}
|
|
|
|
[ReducerCallback(FunctionName = "__update__")]
|
|
public static void OnUpdate(ClientApi.Event dbEvent)
|
|
{
|
|
if(OnUpdateEvent != null)
|
|
{
|
|
var args = dbEvent.FunctionCall.CallInfo.UpdateArgs;
|
|
OnUpdateEvent(dbEvent.Status, Identity.From(dbEvent.CallerIdentity.ToByteArray())
|
|
);
|
|
}
|
|
}
|
|
[DeserializeEvent(FunctionName = "__update__")]
|
|
public static void UpdateDeserializeEventArgs(ClientApi.Event dbEvent)
|
|
{
|
|
var args = new UpdateArgsStruct();
|
|
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 argsGeneric = new ReducerArgs();
|
|
argsGeneric.UpdateArgs = args;
|
|
dbEvent.FunctionCall.CallInfo = new ReducerEvent(ReducerType.Update, dbEvent.Message, dbEvent.Status, argsGeneric);
|
|
}
|
|
}
|
|
|
|
public struct UpdateArgsStruct
|
|
{
|
|
}
|
|
|
|
public partial struct ReducerArgs
|
|
{
|
|
[System.Runtime.InteropServices.FieldOffset(0)]
|
|
public UpdateArgsStruct UpdateArgs;
|
|
}
|
|
|
|
public partial class ReducerEvent
|
|
{
|
|
public UpdateArgsStruct UpdateArgs
|
|
{
|
|
get
|
|
{
|
|
if (Reducer != ReducerType.Update) throw new SpacetimeDB.ReducerMismatchException(Reducer.ToString(), "Update");
|
|
return Args.UpdateArgs;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
'''
|