diff --git a/crates/bindings-csharp/.config/dotnet-tools.json b/crates/bindings-csharp/.config/dotnet-tools.json index 0f7387f442b..3c61b7bca08 100644 --- a/crates/bindings-csharp/.config/dotnet-tools.json +++ b/crates/bindings-csharp/.config/dotnet-tools.json @@ -8,6 +8,13 @@ "dotnet-csharpier" ], "rollForward": false + }, + "verify.tool": { + "version": "0.6.0", + "commands": [ + "dotnet-verify" + ], + "rollForward": false } } } \ No newline at end of file diff --git a/crates/bindings-csharp/BSATN.Runtime.Tests/Tests.cs b/crates/bindings-csharp/BSATN.Runtime.Tests/Tests.cs index 3a68eeff9ae..472863e6b40 100644 --- a/crates/bindings-csharp/BSATN.Runtime.Tests/Tests.cs +++ b/crates/bindings-csharp/BSATN.Runtime.Tests/Tests.cs @@ -6,30 +6,30 @@ namespace SpacetimeDB; public static class BSATNRuntimeTests { [Fact] - public static void AddressRoundtrips() + public static void ConnectionIdRoundtrips() { var str = "00112233445566778899AABBCCDDEEFF"; - var addr = Address.FromHexString(str); + var connId = ConnectionId.FromHexString(str); - Assert.NotNull(addr); - Assert.Equal(addr.ToString(), str); + Assert.NotNull(connId); + Assert.Equal(connId.ToString(), str); var bytes = Convert.FromHexString(str); - var addr2 = Address.FromBigEndian(bytes); - Assert.Equal(addr2, addr); + var connId2 = ConnectionId.FromBigEndian(bytes); + Assert.Equal(connId2, connId); Array.Reverse(bytes); - var addr3 = Address.From(bytes); - Assert.Equal(addr3, addr); + var connId3 = ConnectionId.From(bytes); + Assert.Equal(connId3, connId); var memoryStream = new MemoryStream(); - var bsatn = new Address.BSATN(); + var bsatn = new ConnectionId.BSATN(); using (var writer = new BinaryWriter(memoryStream)) { - if (addr is { } addrNotNull) + if (connId is { } connIdNotNull) { - bsatn.Write(writer, addrNotNull); + bsatn.Write(writer, connIdNotNull); } else { @@ -39,18 +39,18 @@ public static void AddressRoundtrips() var littleEndianBytes = memoryStream.ToArray(); var reader = new BinaryReader(new MemoryStream(littleEndianBytes)); - var addr4 = bsatn.Read(reader); - Assert.Equal(addr4, addr); + var connId4 = bsatn.Read(reader); + Assert.Equal(connId4, connId); // Note: From = FromLittleEndian - var addr5 = Address.From(littleEndianBytes); - Assert.Equal(addr5, addr); + var connId5 = ConnectionId.From(littleEndianBytes); + Assert.Equal(connId5, connId); } static readonly Gen genHex = Gen.String[Gen.Char["0123456789abcdef"], 0, 128]; [Fact] - public static void AddressLengthCheck() + public static void ConnectionIdLengthCheck() { genHex.Sample(s => { @@ -58,7 +58,7 @@ public static void AddressLengthCheck() { return; } - Assert.ThrowsAny(() => Address.FromHexString(s)); + Assert.ThrowsAny(() => ConnectionId.FromHexString(s)); }); Gen.Byte.Array[0, 64] .Sample(arr => @@ -67,8 +67,8 @@ public static void AddressLengthCheck() { return; } - Assert.ThrowsAny(() => Address.FromBigEndian(arr)); - Assert.ThrowsAny(() => Address.From(arr)); + Assert.ThrowsAny(() => ConnectionId.FromBigEndian(arr)); + Assert.ThrowsAny(() => ConnectionId.From(arr)); }); } @@ -136,7 +136,7 @@ public static void NonHexStrings() { // n.b. 32 chars long Assert.ThrowsAny( - () => Address.FromHexString("these are not hex characters....") + () => ConnectionId.FromHexString("these are not hex characters....") ); } diff --git a/crates/bindings-csharp/BSATN.Runtime/Builtins.cs b/crates/bindings-csharp/BSATN.Runtime/Builtins.cs index 281cfb58345..99c0162aad1 100644 --- a/crates/bindings-csharp/BSATN.Runtime/Builtins.cs +++ b/crates/bindings-csharp/BSATN.Runtime/Builtins.cs @@ -118,68 +118,69 @@ public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) => } [StructLayout(LayoutKind.Sequential)] -public readonly record struct Address +public readonly record struct ConnectionId { private readonly U128 value; - internal Address(U128 v) => value = v; + internal ConnectionId(U128 v) => value = v; /// - /// Create an Address from a LITTLE-ENDIAN byte array. + /// Create a ConnectionId from a LITTLE-ENDIAN byte array. /// - /// If you are parsing an Address from a string, you probably want FromHexString instead, + /// If you are parsing a ConnectionId from a string, you probably want FromHexString instead, /// or, failing that, FromBigEndian. /// - /// Returns null if the resulting address is the default. + /// Returns null if the resulting ConnectionId is the default. /// /// - public static Address? From(ReadOnlySpan bytes) + public static ConnectionId? From(ReadOnlySpan bytes) { - var addr = Util.Read
(bytes, littleEndian: true); - return addr == default ? null : addr; + var id = Util.Read(bytes, littleEndian: true); + return id == default ? null : id; } /// - /// Create an Address from a BIG-ENDIAN byte array. + /// Create a ConnectionId from a BIG-ENDIAN byte array. /// - /// This method is the correct choice if you have converted the bytes of a hexadecimal-formatted Address + /// This method is the correct choice if you have converted the bytes of a hexadecimal-formatted ConnectionId /// to a byte array in the following way: /// /// "0xb0b1b2..." /// -> /// [0xb0, 0xb1, 0xb2, ...] /// - /// Returns null if the resulting address is the default. + /// Returns null if the resulting ConnectionId is the default. /// /// - public static Address? FromBigEndian(ReadOnlySpan bytes) + public static ConnectionId? FromBigEndian(ReadOnlySpan bytes) { - var addr = Util.Read
(bytes, littleEndian: false); - return addr == default ? null : addr; + var id = Util.Read(bytes, littleEndian: false); + return id == default ? null : id; } /// - /// Create an Address from a hex string. + /// Create a ConnectionId from a hex string. /// /// /// - public static Address? FromHexString(string hex) => FromBigEndian(Util.StringToByteArray(hex)); + public static ConnectionId? FromHexString(string hex) => + FromBigEndian(Util.StringToByteArray(hex)); - public static Address Random() + public static ConnectionId Random() { var random = new Random(); - var addr = new Address(); - random.NextBytes(Util.AsBytes(ref addr)); - return addr; + var id = new ConnectionId(); + random.NextBytes(Util.AsBytes(ref id)); + return id; } // --- auto-generated --- - public readonly struct BSATN : IReadWrite
+ public readonly struct BSATN : IReadWrite { - public Address Read(BinaryReader reader) => + public ConnectionId Read(BinaryReader reader) => new(new SpacetimeDB.BSATN.U128Stdb().Read(reader)); - public void Write(BinaryWriter writer, Address value) => + public void Write(BinaryWriter writer, ConnectionId value) => new SpacetimeDB.BSATN.U128Stdb().Write(writer, value.value); // --- / auto-generated --- @@ -190,7 +191,7 @@ public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) => new AlgebraicType.Product( [ // Using this specific name here is important. - new("__address__", new AlgebraicType.U128(default)), + new("__connection_id__", new AlgebraicType.U128(default)), ] ); // --- / customized --- diff --git a/crates/bindings-csharp/Codegen.Tests/fixtures/client/Lib.cs b/crates/bindings-csharp/Codegen.Tests/fixtures/client/Lib.cs index e1a82bb3d3b..7999e65762f 100644 --- a/crates/bindings-csharp/Codegen.Tests/fixtures/client/Lib.cs +++ b/crates/bindings-csharp/Codegen.Tests/fixtures/client/Lib.cs @@ -65,7 +65,7 @@ public partial struct PublicTable public double DoubleField; public string StringField; public Identity IdentityField; - public Address AddressField; + public ConnectionId ConnectionIdField; public CustomStruct CustomStructField; public CustomClass CustomClassField; public CustomEnum CustomEnumField; diff --git a/crates/bindings-csharp/Codegen.Tests/fixtures/client/snapshots/Type#PublicTable.verified.cs b/crates/bindings-csharp/Codegen.Tests/fixtures/client/snapshots/Type#PublicTable.verified.cs index e993d0875c6..dd14d7ecd20 100644 --- a/crates/bindings-csharp/Codegen.Tests/fixtures/client/snapshots/Type#PublicTable.verified.cs +++ b/crates/bindings-csharp/Codegen.Tests/fixtures/client/snapshots/Type#PublicTable.verified.cs @@ -23,7 +23,7 @@ public void ReadFields(System.IO.BinaryReader reader) DoubleField = BSATN.DoubleField.Read(reader); StringField = BSATN.StringField.Read(reader); IdentityField = BSATN.IdentityField.Read(reader); - AddressField = BSATN.AddressField.Read(reader); + ConnectionIdField = BSATN.ConnectionIdField.Read(reader); CustomStructField = BSATN.CustomStructField.Read(reader); CustomClassField = BSATN.CustomClassField.Read(reader); CustomEnumField = BSATN.CustomEnumField.Read(reader); @@ -52,7 +52,7 @@ public void WriteFields(System.IO.BinaryWriter writer) BSATN.DoubleField.Write(writer, DoubleField); BSATN.StringField.Write(writer, StringField); BSATN.IdentityField.Write(writer, IdentityField); - BSATN.AddressField.Write(writer, AddressField); + BSATN.ConnectionIdField.Write(writer, ConnectionIdField); BSATN.CustomStructField.Write(writer, CustomStructField); BSATN.CustomClassField.Write(writer, CustomClassField); BSATN.CustomEnumField.Write(writer, CustomEnumField); @@ -81,7 +81,7 @@ public void WriteFields(System.IO.BinaryWriter writer) internal static readonly SpacetimeDB.BSATN.F64 DoubleField = new(); internal static readonly SpacetimeDB.BSATN.String StringField = new(); internal static readonly SpacetimeDB.Identity.BSATN IdentityField = new(); - internal static readonly SpacetimeDB.Address.BSATN AddressField = new(); + internal static readonly SpacetimeDB.ConnectionId.BSATN ConnectionIdField = new(); internal static readonly CustomStruct.BSATN CustomStructField = new(); internal static readonly CustomClass.BSATN CustomClassField = new(); internal static readonly SpacetimeDB.BSATN.Enum CustomEnumField = new(); @@ -128,7 +128,7 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar new(nameof(DoubleField), DoubleField.GetAlgebraicType(registrar)), new(nameof(StringField), StringField.GetAlgebraicType(registrar)), new(nameof(IdentityField), IdentityField.GetAlgebraicType(registrar)), - new(nameof(AddressField), AddressField.GetAlgebraicType(registrar)), + new(nameof(ConnectionIdField), ConnectionIdField.GetAlgebraicType(registrar)), new(nameof(CustomStructField), CustomStructField.GetAlgebraicType(registrar)), new(nameof(CustomClassField), CustomClassField.GetAlgebraicType(registrar)), new(nameof(CustomEnumField), CustomEnumField.GetAlgebraicType(registrar)), diff --git a/crates/bindings-csharp/Codegen.Tests/fixtures/diag/snapshots/Module#FFI.verified.cs b/crates/bindings-csharp/Codegen.Tests/fixtures/diag/snapshots/Module#FFI.verified.cs index 7ca9fe09852..8b12ae2bba3 100644 --- a/crates/bindings-csharp/Codegen.Tests/fixtures/diag/snapshots/Module#FFI.verified.cs +++ b/crates/bindings-csharp/Codegen.Tests/fixtures/diag/snapshots/Module#FFI.verified.cs @@ -10,18 +10,23 @@ namespace SpacetimeDB { public sealed record ReducerContext : DbContext, Internal.IReducerContext { - public readonly Identity CallerIdentity; - public readonly Address? CallerAddress; + public readonly Identity Sender; + public readonly ConnectionId? ConnectionId; public readonly Random Rng; public readonly Timestamp Timestamp; // We need this property to be non-static for parity with client SDK. public Identity Identity => Internal.IReducerContext.GetIdentity(); - internal ReducerContext(Identity identity, Address? address, Random random, Timestamp time) + internal ReducerContext( + Identity identity, + ConnectionId? connectionId, + Random random, + Timestamp time + ) { - CallerIdentity = identity; - CallerAddress = address; + Sender = identity; + ConnectionId = connectionId; Rng = random; Timestamp = time; } @@ -938,8 +943,8 @@ public void Invoke(BinaryReader reader, SpacetimeDB.Internal.IReducerContext ctx public static void Main() { SpacetimeDB.Internal.Module.SetReducerContextConstructor( - (identity, address, random, time) => - new SpacetimeDB.ReducerContext(identity, address, random, time) + (identity, connectionId, random, time) => + new SpacetimeDB.ReducerContext(identity, connectionId, random, time) ); SpacetimeDB.Internal.Module.RegisterReducer<__ReducerWithReservedPrefix>(); @@ -1001,8 +1006,8 @@ public static SpacetimeDB.Internal.Errno __call_reducer__( ulong sender_1, ulong sender_2, ulong sender_3, - ulong address_0, - ulong address_1, + ulong conn_id_0, + ulong conn_id_1, SpacetimeDB.Timestamp timestamp, SpacetimeDB.Internal.BytesSource args, SpacetimeDB.Internal.BytesSink error @@ -1013,8 +1018,8 @@ SpacetimeDB.Internal.BytesSink error sender_1, sender_2, sender_3, - address_0, - address_1, + conn_id_0, + conn_id_1, timestamp, args, error diff --git a/crates/bindings-csharp/Codegen.Tests/fixtures/server/Lib.cs b/crates/bindings-csharp/Codegen.Tests/fixtures/server/Lib.cs index 06e0ebad171..c1396458618 100644 --- a/crates/bindings-csharp/Codegen.Tests/fixtures/server/Lib.cs +++ b/crates/bindings-csharp/Codegen.Tests/fixtures/server/Lib.cs @@ -68,7 +68,7 @@ public partial struct PublicTable public double DoubleField; public string StringField; public Identity IdentityField; - public Address AddressField; + public ConnectionId ConnectionIdField; public CustomStruct CustomStructField; public CustomClass CustomClassField; public CustomEnum CustomEnumField; diff --git a/crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Module#FFI.verified.cs b/crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Module#FFI.verified.cs index d143e87ff07..0ed5057507b 100644 --- a/crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Module#FFI.verified.cs +++ b/crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Module#FFI.verified.cs @@ -10,18 +10,23 @@ namespace SpacetimeDB { public sealed record ReducerContext : DbContext, Internal.IReducerContext { - public readonly Identity CallerIdentity; - public readonly Address? CallerAddress; + public readonly Identity Sender; + public readonly ConnectionId? ConnectionId; public readonly Random Rng; public readonly Timestamp Timestamp; // We need this property to be non-static for parity with client SDK. public Identity Identity => Internal.IReducerContext.GetIdentity(); - internal ReducerContext(Identity identity, Address? address, Random random, Timestamp time) + internal ReducerContext( + Identity identity, + ConnectionId? connectionId, + Random random, + Timestamp time + ) { - CallerIdentity = identity; - CallerAddress = address; + Sender = identity; + ConnectionId = connectionId; Rng = random; Timestamp = time; } @@ -1092,8 +1097,8 @@ public void Invoke(BinaryReader reader, SpacetimeDB.Internal.IReducerContext ctx public static void Main() { SpacetimeDB.Internal.Module.SetReducerContextConstructor( - (identity, address, random, time) => - new SpacetimeDB.ReducerContext(identity, address, random, time) + (identity, connectionId, random, time) => + new SpacetimeDB.ReducerContext(identity, connectionId, random, time) ); SpacetimeDB.Internal.Module.RegisterReducer(); @@ -1149,8 +1154,8 @@ public static SpacetimeDB.Internal.Errno __call_reducer__( ulong sender_1, ulong sender_2, ulong sender_3, - ulong address_0, - ulong address_1, + ulong conn_id_0, + ulong conn_id_1, SpacetimeDB.Timestamp timestamp, SpacetimeDB.Internal.BytesSource args, SpacetimeDB.Internal.BytesSink error @@ -1161,8 +1166,8 @@ SpacetimeDB.Internal.BytesSink error sender_1, sender_2, sender_3, - address_0, - address_1, + conn_id_0, + conn_id_1, timestamp, args, error diff --git a/crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Module#PublicTable.verified.cs b/crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Module#PublicTable.verified.cs index 7b61dabf5ff..fff8e1a426f 100644 --- a/crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Module#PublicTable.verified.cs +++ b/crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Module#PublicTable.verified.cs @@ -26,7 +26,7 @@ public void ReadFields(System.IO.BinaryReader reader) DoubleField = BSATN.DoubleField.Read(reader); StringField = BSATN.StringField.Read(reader); IdentityField = BSATN.IdentityField.Read(reader); - AddressField = BSATN.AddressField.Read(reader); + ConnectionIdField = BSATN.ConnectionIdField.Read(reader); CustomStructField = BSATN.CustomStructField.Read(reader); CustomClassField = BSATN.CustomClassField.Read(reader); CustomEnumField = BSATN.CustomEnumField.Read(reader); @@ -58,7 +58,7 @@ public void WriteFields(System.IO.BinaryWriter writer) BSATN.DoubleField.Write(writer, DoubleField); BSATN.StringField.Write(writer, StringField); BSATN.IdentityField.Write(writer, IdentityField); - BSATN.AddressField.Write(writer, AddressField); + BSATN.ConnectionIdField.Write(writer, ConnectionIdField); BSATN.CustomStructField.Write(writer, CustomStructField); BSATN.CustomClassField.Write(writer, CustomClassField); BSATN.CustomEnumField.Write(writer, CustomEnumField); @@ -90,7 +90,7 @@ public void WriteFields(System.IO.BinaryWriter writer) internal static readonly SpacetimeDB.BSATN.F64 DoubleField = new(); internal static readonly SpacetimeDB.BSATN.String StringField = new(); internal static readonly SpacetimeDB.Identity.BSATN IdentityField = new(); - internal static readonly SpacetimeDB.Address.BSATN AddressField = new(); + internal static readonly SpacetimeDB.ConnectionId.BSATN ConnectionIdField = new(); internal static readonly CustomStruct.BSATN CustomStructField = new(); internal static readonly CustomClass.BSATN CustomClassField = new(); internal static readonly SpacetimeDB.BSATN.Enum CustomEnumField = new(); @@ -140,7 +140,7 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar new(nameof(DoubleField), DoubleField.GetAlgebraicType(registrar)), new(nameof(StringField), StringField.GetAlgebraicType(registrar)), new(nameof(IdentityField), IdentityField.GetAlgebraicType(registrar)), - new(nameof(AddressField), AddressField.GetAlgebraicType(registrar)), + new(nameof(ConnectionIdField), ConnectionIdField.GetAlgebraicType(registrar)), new(nameof(CustomStructField), CustomStructField.GetAlgebraicType(registrar)), new(nameof(CustomClassField), CustomClassField.GetAlgebraicType(registrar)), new(nameof(CustomEnumField), CustomEnumField.GetAlgebraicType(registrar)), diff --git a/crates/bindings-csharp/Codegen/Module.cs b/crates/bindings-csharp/Codegen/Module.cs index 9fc3f894d92..0a4bacba423 100644 --- a/crates/bindings-csharp/Codegen/Module.cs +++ b/crates/bindings-csharp/Codegen/Module.cs @@ -103,7 +103,7 @@ or SpecialType.System_Int64 { SpecialType.System_String or SpecialType.System_Boolean => true, SpecialType.None => type.ToString() - is "SpacetimeDB.Address" + is "SpacetimeDB.ConnectionId" or "SpacetimeDB.Identity", _ => false, } @@ -819,17 +819,17 @@ public void Initialize(IncrementalGeneratorInitializationContext context) namespace SpacetimeDB { public sealed record ReducerContext : DbContext, Internal.IReducerContext { - public readonly Identity CallerIdentity; - public readonly Address? CallerAddress; + public readonly Identity Sender; + public readonly ConnectionId? ConnectionId; public readonly Random Rng; public readonly Timestamp Timestamp; // We need this property to be non-static for parity with client SDK. public Identity Identity => Internal.IReducerContext.GetIdentity(); - internal ReducerContext(Identity identity, Address? address, Random random, Timestamp time) { - CallerIdentity = identity; - CallerAddress = address; + internal ReducerContext(Identity identity, ConnectionId? connectionId, Random random, Timestamp time) { + Sender = identity; + ConnectionId = connectionId; Rng = random; Timestamp = time; } @@ -856,7 +856,7 @@ static class ModuleRegistration { [DynamicDependency(DynamicallyAccessedMemberTypes.PublicMethods, typeof(SpacetimeDB.Internal.Module))] #endif public static void Main() { - SpacetimeDB.Internal.Module.SetReducerContextConstructor((identity, address, random, time) => new SpacetimeDB.ReducerContext(identity, address, random, time)); + SpacetimeDB.Internal.Module.SetReducerContextConstructor((identity, connectionId, random, time) => new SpacetimeDB.ReducerContext(identity, connectionId, random, time)); {{string.Join( "\n", @@ -882,8 +882,8 @@ public static SpacetimeDB.Internal.Errno __call_reducer__( ulong sender_1, ulong sender_2, ulong sender_3, - ulong address_0, - ulong address_1, + ulong conn_id_0, + ulong conn_id_1, SpacetimeDB.Timestamp timestamp, SpacetimeDB.Internal.BytesSource args, SpacetimeDB.Internal.BytesSink error @@ -893,8 +893,8 @@ SpacetimeDB.Internal.BytesSink error sender_1, sender_2, sender_3, - address_0, - address_1, + conn_id_0, + conn_id_1, timestamp, args, error diff --git a/crates/bindings-csharp/Runtime/Internal/Module.cs b/crates/bindings-csharp/Runtime/Internal/Module.cs index cf69ab8aa11..83606b167bd 100644 --- a/crates/bindings-csharp/Runtime/Internal/Module.cs +++ b/crates/bindings-csharp/Runtime/Internal/Module.cs @@ -42,10 +42,11 @@ public static class Module private static readonly RawModuleDefV9 moduleDef = new(); private static readonly List reducers = []; - private static Func? newContext = null; + private static Func? newContext = + null; public static void SetReducerContextConstructor( - Func ctor + Func ctor ) => newContext = ctor; readonly struct TypeRegistrar() : ITypeRegistrar @@ -169,8 +170,8 @@ public static Errno __call_reducer__( ulong sender_1, ulong sender_2, ulong sender_3, - ulong address_0, - ulong address_1, + ulong conn_id_0, + ulong conn_id_1, Timestamp timestamp, BytesSource args, BytesSink error @@ -181,13 +182,13 @@ BytesSink error var senderIdentity = Identity.From( MemoryMarshal.AsBytes([sender_0, sender_1, sender_2, sender_3]).ToArray() ); - var senderAddress = Address.From( - MemoryMarshal.AsBytes([address_0, address_1]).ToArray() + var connectionId = ConnectionId.From( + MemoryMarshal.AsBytes([conn_id_0, conn_id_1]).ToArray() ); var random = new Random((int)timestamp.MicrosecondsSinceUnixEpoch); var time = timestamp.ToStd(); - var ctx = newContext!(senderIdentity, senderAddress, random, time); + var ctx = newContext!(senderIdentity, connectionId, random, time); using var stream = new MemoryStream(args.Consume()); using var reader = new BinaryReader(stream); diff --git a/crates/bindings-csharp/Runtime/bindings.c b/crates/bindings-csharp/Runtime/bindings.c index 5dbd3386936..03f510f9991 100644 --- a/crates/bindings-csharp/Runtime/bindings.c +++ b/crates/bindings-csharp/Runtime/bindings.c @@ -141,11 +141,11 @@ EXPORT_VOID(__describe_module__, (BytesSink description), &description); EXPORT(int16_t, __call_reducer__, (uint32_t id, uint64_t sender_0, uint64_t sender_1, uint64_t sender_2, uint64_t sender_3, - uint64_t address_0, uint64_t address_1, + uint64_t conn_id_0, uint64_t conn_id_1, uint64_t timestamp, BytesSource args, BytesSink error), &id, &sender_0, &sender_1, &sender_2, &sender_3, - &address_0, &address_1, + &conn_id_0, &conn_id_1, ×tamp, &args, &error); #endif diff --git a/crates/bindings-sys/src/lib.rs b/crates/bindings-sys/src/lib.rs index 84a074ff254..7ce6e3b98fe 100644 --- a/crates/bindings-sys/src/lib.rs +++ b/crates/bindings-sys/src/lib.rs @@ -672,8 +672,8 @@ pub mod raw { sender_1: u64, sender_2: u64, sender_3: u64, - address_0: u64, - address_1: u64, + conn_id_0: u64, + conn_id_1: u64, timestamp: u64, args: Buffer, ) -> Result; diff --git a/crates/bindings/src/lib.rs b/crates/bindings/src/lib.rs index 1a83a4a4a1f..d33d9a724d4 100644 --- a/crates/bindings/src/lib.rs +++ b/crates/bindings/src/lib.rs @@ -33,8 +33,8 @@ pub use spacetimedb_lib; pub use spacetimedb_lib::de::{Deserialize, DeserializeOwned}; pub use spacetimedb_lib::sats; pub use spacetimedb_lib::ser::Serialize; -pub use spacetimedb_lib::Address; pub use spacetimedb_lib::AlgebraicValue; +pub use spacetimedb_lib::ConnectionId; pub use spacetimedb_lib::Identity; pub use spacetimedb_lib::ScheduleAt; pub use spacetimedb_lib::TimeDuration; @@ -52,14 +52,10 @@ pub struct ReducerContext { pub sender: Identity, /// The time at which the reducer was started. pub timestamp: Timestamp, - /// The `Address` of the client that invoked the reducer. + /// The `ConnectionId` of the client that invoked the reducer. /// - /// `None` if no `Address` was supplied to the `/database/call` HTTP endpoint, - /// or via the CLI's `spacetime call` subcommand. - /// - /// For automatic reducers, i.e. `init`, `update` and scheduled reducers, - /// this will be the module's `Address`. - pub address: Option
, + /// Will be `None` for scheduled reducers. + pub connection_id: Option, pub db: Local, #[cfg(feature = "rand")] @@ -73,7 +69,7 @@ impl ReducerContext { db: Local {}, sender: Identity::__dummy(), timestamp: Timestamp::UNIX_EPOCH, - address: None, + connection_id: None, rng: std::cell::OnceCell::new(), } } diff --git a/crates/bindings/src/rt.rs b/crates/bindings/src/rt.rs index 4960f16626b..e329cd896f5 100644 --- a/crates/bindings/src/rt.rs +++ b/crates/bindings/src/rt.rs @@ -8,7 +8,7 @@ use spacetimedb_lib::de::{self, Deserialize, SeqProductAccess}; use spacetimedb_lib::sats::typespace::TypespaceBuilder; use spacetimedb_lib::sats::{impl_deserialize, impl_serialize, ProductTypeElement}; use spacetimedb_lib::ser::{Serialize, SerializeSeqProduct}; -use spacetimedb_lib::{bsatn, Address, Identity, ProductType, RawModuleDef, Timestamp}; +use spacetimedb_lib::{bsatn, ConnectionId, Identity, ProductType, RawModuleDef, Timestamp}; use spacetimedb_primitives::*; use std::fmt; use std::marker::PhantomData; @@ -459,10 +459,10 @@ extern "C" fn __describe_module__(description: BytesSink) { /// /// Note that `to_byte_array` uses LITTLE-ENDIAN order! This matches most host systems. /// -/// The `address_{0-1}` are the pieces of a `[u8; 16]` (`u128`) representing the callers's `Address`. -/// They are encoded as follows (assuming `address.as_byte_array(): [u8; 16]`): -/// - `address_0` contains bytes `[0 ..8 ]`. -/// - `address_1` contains bytes `[8 ..16]`. +/// The `conn_id_{0-1}` are the pieces of a `[u8; 16]` (`u128`) representing the callers's [`ConnectionId`]. +/// They are encoded as follows (assuming `conn_id.as_le_byte_array(): [u8; 16]`): +/// - `conn_id_0` contains bytes `[0 ..8 ]`. +/// - `conn_id_1` contains bytes `[8 ..16]`. /// /// Again, note that `to_byte_array` uses LITTLE-ENDIAN order! This matches most host systems. /// @@ -484,8 +484,8 @@ extern "C" fn __call_reducer__( sender_1: u64, sender_2: u64, sender_3: u64, - address_0: u64, - address_1: u64, + conn_id_0: u64, + conn_id_1: u64, timestamp: u64, args: BytesSource, error: BytesSink, @@ -495,12 +495,12 @@ extern "C" fn __call_reducer__( let sender: [u8; 32] = bytemuck::must_cast(sender); let sender = Identity::from_byte_array(sender); // The LITTLE-ENDIAN constructor. - // Piece together `address_i` into an `Address`. - // The all-zeros `address` (`Address::__DUMMY`) is interpreted as `None`. - let address = [address_0, address_1]; - let address: [u8; 16] = bytemuck::must_cast(address); - let address = Address::from_byte_array(address); // The LITTLE-ENDIAN constructor. - let address = (address != Address::__DUMMY).then_some(address); + // Piece together `conn_id_i` into a `ConnectionId`. + // The all-zeros `ConnectionId` (`ConnectionId::ZERO`) is interpreted as `None`. + let conn_id = [conn_id_0, conn_id_1]; + let conn_id: [u8; 16] = bytemuck::must_cast(conn_id); + let conn_id = ConnectionId::from_le_byte_array(conn_id); // The LITTLE-ENDIAN constructor. + let conn_id = (conn_id != ConnectionId::ZERO).then_some(conn_id); // Assemble the `ReducerContext`. let timestamp = Timestamp::from_micros_since_unix_epoch(timestamp as i64); @@ -508,7 +508,7 @@ extern "C" fn __call_reducer__( db: crate::Local {}, sender, timestamp, - address, + connection_id: conn_id, rng: std::cell::OnceCell::new(), }; diff --git a/crates/bindings/src/table.rs b/crates/bindings/src/table.rs index 9ce2202e87b..a4718ac3316 100644 --- a/crates/bindings/src/table.rs +++ b/crates/bindings/src/table.rs @@ -10,7 +10,7 @@ pub use spacetimedb_lib::db::raw_def::v9::TableAccess; use spacetimedb_lib::Hash; pub use spacetimedb_primitives::{ColId, IndexId}; -use crate::{bsatn, sys, Address, DeserializeOwned, Identity, IterBuf, Serialize, SpacetimeType, TableId}; +use crate::{bsatn, sys, ConnectionId, DeserializeOwned, Identity, IterBuf, Serialize, SpacetimeType, TableId}; /// Implemented for every `TableHandle` struct generated in the client `module_bindings` /// and the module macroexpansion. @@ -466,7 +466,7 @@ impl_filterable_value! { String, &str => String, Identity: Copy, - Address: Copy, + ConnectionId: Copy, Hash: Copy, // Some day we will likely also want to support `Vec` and `[u8]`, diff --git a/crates/bindings/tests/ui/reducers.stderr b/crates/bindings/tests/ui/reducers.stderr index d7b376dfc8a..b66ab354668 100644 --- a/crates/bindings/tests/ui/reducers.stderr +++ b/crates/bindings/tests/ui/reducers.stderr @@ -70,12 +70,12 @@ error[E0277]: the reducer argument `Test` does not implement `SpacetimeType` = help: the following other types implement trait `SpacetimeType`: &T () - Address - AddressForUrl AlgebraicTypeRef Arc ArrayType Box + ColId + ColumnAttribute and $N others = note: required for `Test` to implement `ReducerArg` diff --git a/crates/bindings/tests/ui/tables.stderr b/crates/bindings/tests/ui/tables.stderr index c3774dc9089..931f4a46312 100644 --- a/crates/bindings/tests/ui/tables.stderr +++ b/crates/bindings/tests/ui/tables.stderr @@ -21,12 +21,12 @@ error[E0277]: the column type `Test` does not implement `SpacetimeType` = help: the following other types implement trait `SpacetimeType`: &T () - Address - AddressForUrl AlgebraicTypeRef Arc ArrayType Box + ColId + ColumnAttribute and $N others = note: required for `Test` to implement `TableColumn` @@ -40,12 +40,12 @@ error[E0277]: the trait bound `Test: SpacetimeType` is not satisfied = help: the following other types implement trait `SpacetimeType`: &T () - Address - AddressForUrl AlgebraicTypeRef Arc ArrayType Box + ColId + ColumnAttribute and $N others error[E0277]: the trait bound `Test: Deserialize<'de>` is not satisfied @@ -61,11 +61,11 @@ error[E0277]: the trait bound `Test: Deserialize<'de>` is not satisfied &'de [u8] &'de str () - Address - AddressForUrl AlgebraicTypeRef Arc<[T]> ArrayType + Box + Box<[T]> and $N others note: required by a bound in `spacetimedb::spacetimedb_lib::de::SeqProductAccess::next_element` --> $WORKSPACE/crates/sats/src/de.rs @@ -83,11 +83,11 @@ error[E0277]: the trait bound `Test: Deserialize<'_>` is not satisfied &'de [u8] &'de str () - Address - AddressForUrl AlgebraicTypeRef Arc<[T]> ArrayType + Box + Box<[T]> and $N others note: required by a bound in `get_field_value` --> $WORKSPACE/crates/sats/src/de.rs @@ -104,12 +104,12 @@ error[E0277]: the trait bound `Test: Serialize` is not satisfied = help: the following other types implement trait `Serialize`: &T () - Address - AddressForUrl AlgebraicTypeRef Arc ArrayType ArrayValue + Bound + Box and $N others note: required by a bound in `spacetimedb::spacetimedb_lib::ser::SerializeNamedProduct::serialize_element` --> $WORKSPACE/crates/sats/src/ser.rs diff --git a/crates/cli/src/subcommands/call.rs b/crates/cli/src/subcommands/call.rs index 0bd8ad75e88..7c5b3ff45f3 100644 --- a/crates/cli/src/subcommands/call.rs +++ b/crates/cli/src/subcommands/call.rs @@ -333,7 +333,7 @@ mod write_type { ) -> fmt::Result { match ty { p if p.is_identity() => write!(out, "Identity")?, - p if p.is_address() => write!(out, "Address")?, + p if p.is_connection_id() => write!(out, "ConnectionId")?, p if p.is_schedule_at() => write!(out, "ScheduleAt")?, AlgebraicType::Sum(sum_type) => { if let Some(inner_ty) = sum_type.as_option() { diff --git a/crates/cli/src/subcommands/generate/csharp.rs b/crates/cli/src/subcommands/generate/csharp.rs index f4562e6d8d8..b9071fa5143 100644 --- a/crates/cli/src/subcommands/generate/csharp.rs +++ b/crates/cli/src/subcommands/generate/csharp.rs @@ -543,7 +543,7 @@ impl Lang for Csharp<'_> { fn ty_fmt<'a>(module: &'a ModuleDef, ty: &'a AlgebraicTypeUse) -> impl fmt::Display + 'a { fmt_fn(move |f| match ty { AlgebraicTypeUse::Identity => f.write_str("SpacetimeDB.Identity"), - AlgebraicTypeUse::Address => f.write_str("SpacetimeDB.Address"), + AlgebraicTypeUse::ConnectionId => f.write_str("SpacetimeDB.ConnectionId"), AlgebraicTypeUse::ScheduleAt => f.write_str("SpacetimeDB.ScheduleAt"), AlgebraicTypeUse::Timestamp => f.write_str("SpacetimeDB.Timestamp"), AlgebraicTypeUse::TimeDuration => f.write_str("SpacetimeDB.TimeDuration"), @@ -594,7 +594,7 @@ fn default_init(ctx: &TypespaceForGenerate, ty: &AlgebraicTypeUse) -> Option<&'s // these are structs, they are initialized to zero-filled automatically AlgebraicTypeUse::Unit | AlgebraicTypeUse::Identity - | AlgebraicTypeUse::Address + | AlgebraicTypeUse::ConnectionId | AlgebraicTypeUse::Timestamp | AlgebraicTypeUse::TimeDuration => None, AlgebraicTypeUse::Never => unimplemented!("never types are not yet supported in C# output"), diff --git a/crates/cli/src/subcommands/generate/rust.rs b/crates/cli/src/subcommands/generate/rust.rs index 18002ad3a83..288b48b02df 100644 --- a/crates/cli/src/subcommands/generate/rust.rs +++ b/crates/cli/src/subcommands/generate/rust.rs @@ -582,7 +582,7 @@ pub fn write_type(module: &ModuleDef, out: &mut W, ty: &AlgebraicTypeU AlgebraicTypeUse::Unit => write!(out, "()")?, AlgebraicTypeUse::Never => write!(out, "std::convert::Infallible")?, AlgebraicTypeUse::Identity => write!(out, "__sdk::Identity")?, - AlgebraicTypeUse::Address => write!(out, "__sdk::Address")?, + AlgebraicTypeUse::ConnectionId => write!(out, "__sdk::ConnectionId")?, AlgebraicTypeUse::Timestamp => write!(out, "__sdk::Timestamp")?, AlgebraicTypeUse::TimeDuration => write!(out, "__sdk::TimeDuration")?, AlgebraicTypeUse::ScheduleAt => write!(out, "__sdk::ScheduleAt")?, @@ -1248,8 +1248,8 @@ impl __sdk::DbContext for DbConnection {{ fn try_identity(&self) -> Option<__sdk::Identity> {{ self.imp.try_identity() }} - fn address(&self) -> __sdk::Address {{ - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId {{ + self.imp.connection_id() }} }} @@ -1564,8 +1564,8 @@ impl __sdk::DbContext for {struct_and_trait_name} {{ fn try_identity(&self) -> Option<__sdk::Identity> {{ self.imp.try_identity() }} - fn address(&self) -> __sdk::Address {{ - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId {{ + self.imp.connection_id() }} }} diff --git a/crates/cli/src/subcommands/generate/typescript.rs b/crates/cli/src/subcommands/generate/typescript.rs index 5816746bb3e..d08cec0500b 100644 --- a/crates/cli/src/subcommands/generate/typescript.rs +++ b/crates/cli/src/subcommands/generate/typescript.rs @@ -617,7 +617,7 @@ fn print_spacetimedb_imports(out: &mut Indenter) { "SumTypeVariant", "AlgebraicValue", "Identity", - "Address", + "ConnectionId", "Timestamp", "TimeDuration", "DBConnectionBuilder", @@ -964,7 +964,7 @@ pub fn write_type( AlgebraicTypeUse::Unit => write!(out, "void")?, AlgebraicTypeUse::Never => write!(out, "never")?, AlgebraicTypeUse::Identity => write!(out, "Identity")?, - AlgebraicTypeUse::Address => write!(out, "Address")?, + AlgebraicTypeUse::ConnectionId => write!(out, "ConnectionId")?, AlgebraicTypeUse::Timestamp => write!(out, "Timestamp")?, AlgebraicTypeUse::TimeDuration => write!(out, "TimeDuration")?, AlgebraicTypeUse::ScheduleAt => write!( @@ -1019,7 +1019,7 @@ fn convert_algebraic_type<'a>( match ty { AlgebraicTypeUse::ScheduleAt => write!(out, "AlgebraicType.createScheduleAtType()"), AlgebraicTypeUse::Identity => write!(out, "AlgebraicType.createIdentityType()"), - AlgebraicTypeUse::Address => write!(out, "AlgebraicType.createAddressType()"), + AlgebraicTypeUse::ConnectionId => write!(out, "AlgebraicType.createConnectionIdType()"), AlgebraicTypeUse::Timestamp => write!(out, "AlgebraicType.createTimestampType()"), AlgebraicTypeUse::TimeDuration => write!(out, "AlgebraicType.createTimeDurationType()"), AlgebraicTypeUse::Option(inner_ty) => { diff --git a/crates/cli/src/subcommands/generate/util.rs b/crates/cli/src/subcommands/generate/util.rs index 8223efd781d..b22edf2404d 100644 --- a/crates/cli/src/subcommands/generate/util.rs +++ b/crates/cli/src/subcommands/generate/util.rs @@ -60,7 +60,7 @@ pub(super) fn type_ref_name(module: &ModuleDef, typeref: AlgebraicTypeRef) -> St pub(super) fn is_type_filterable(ty: &AlgebraicTypeUse) -> bool { match ty { AlgebraicTypeUse::Primitive(prim) => !matches!(prim, PrimitiveType::F32 | PrimitiveType::F64), - AlgebraicTypeUse::String | AlgebraicTypeUse::Identity | AlgebraicTypeUse::Address => true, + AlgebraicTypeUse::String | AlgebraicTypeUse::Identity | AlgebraicTypeUse::ConnectionId => true, _ => false, } } diff --git a/crates/cli/src/subcommands/subscribe.rs b/crates/cli/src/subcommands/subscribe.rs index 4b47adf5962..13ea7d4d4ac 100644 --- a/crates/cli/src/subcommands/subscribe.rs +++ b/crates/cli/src/subcommands/subscribe.rs @@ -29,7 +29,7 @@ pub fn cli() -> clap::Command { .arg( Arg::new("database") .required(true) - .help("The domain or address of the database you would like to query"), + .help("The name or identity of the database you would like to query"), ) .arg( Arg::new("query") diff --git a/crates/cli/tests/snapshots/codegen__codegen_csharp.snap b/crates/cli/tests/snapshots/codegen__codegen_csharp.snap index e3bbf84939b..4a4af323776 100644 --- a/crates/cli/tests/snapshots/codegen__codegen_csharp.snap +++ b/crates/cli/tests/snapshots/codegen__codegen_csharp.snap @@ -1593,16 +1593,16 @@ namespace SpacetimeDB { [DataMember(Name = "identity")] public SpacetimeDB.Identity Identity; - [DataMember(Name = "address")] - public SpacetimeDB.Address Address; + [DataMember(Name = "connection_id")] + public SpacetimeDB.ConnectionId ConnectionId; public HasSpecialStuff( SpacetimeDB.Identity Identity, - SpacetimeDB.Address Address + SpacetimeDB.ConnectionId ConnectionId ) { this.Identity = Identity; - this.Address = Address; + this.ConnectionId = ConnectionId; } public HasSpecialStuff() diff --git a/crates/cli/tests/snapshots/codegen__codegen_rust.snap b/crates/cli/tests/snapshots/codegen__codegen_rust.snap index d12b0e8c744..fc767a66411 100644 --- a/crates/cli/tests/snapshots/codegen__codegen_rust.snap +++ b/crates/cli/tests/snapshots/codegen__codegen_rust.snap @@ -933,7 +933,7 @@ use spacetimedb_sdk::__codegen::{ #[sats(crate = __lib)] pub struct HasSpecialStuff { pub identity: __sdk::Identity, - pub address: __sdk::Address, + pub connection_id: __sdk::ConnectionId, } @@ -1754,8 +1754,8 @@ impl __sdk::DbContext for DbConnection { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } @@ -1967,8 +1967,8 @@ impl __sdk::DbContext for EventContext { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } @@ -2043,8 +2043,8 @@ impl __sdk::DbContext for ReducerEventContext { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } @@ -2115,8 +2115,8 @@ impl __sdk::DbContext for SubscriptionEventContext { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } @@ -2191,8 +2191,8 @@ impl __sdk::DbContext for ErrorContext { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } diff --git a/crates/cli/tests/snapshots/codegen__codegen_typescript.snap b/crates/cli/tests/snapshots/codegen__codegen_typescript.snap index 5ddb7b4c515..fe99e86ec4e 100644 --- a/crates/cli/tests/snapshots/codegen__codegen_typescript.snap +++ b/crates/cli/tests/snapshots/codegen__codegen_typescript.snap @@ -10,12 +10,12 @@ expression: outfiles /* tslint:disable */ // @ts-nocheck import { - Address, AlgebraicType, AlgebraicValue, BinaryReader, BinaryWriter, CallReducerFlags, + ConnectionId, DBConnectionBuilder, DBConnectionImpl, DBContext, @@ -73,12 +73,12 @@ export namespace AddPlayer { /* tslint:disable */ // @ts-nocheck import { - Address, AlgebraicType, AlgebraicValue, BinaryReader, BinaryWriter, CallReducerFlags, + ConnectionId, DBConnectionBuilder, DBConnectionImpl, DBContext, @@ -136,12 +136,12 @@ export namespace AddPrivate { /* tslint:disable */ // @ts-nocheck import { - Address, AlgebraicType, AlgebraicValue, BinaryReader, BinaryWriter, CallReducerFlags, + ConnectionId, DBConnectionBuilder, DBConnectionImpl, DBContext, @@ -201,12 +201,12 @@ export namespace Add { /* tslint:disable */ // @ts-nocheck import { - Address, AlgebraicType, AlgebraicValue, BinaryReader, BinaryWriter, CallReducerFlags, + ConnectionId, DBConnectionBuilder, DBConnectionImpl, DBContext, @@ -261,12 +261,12 @@ export namespace AssertCallerIdentityIsModuleIdentity { /* tslint:disable */ // @ts-nocheck import { - Address, AlgebraicType, AlgebraicValue, BinaryReader, BinaryWriter, CallReducerFlags, + ConnectionId, DBConnectionBuilder, DBConnectionImpl, DBContext, @@ -324,12 +324,12 @@ export namespace Baz { /* tslint:disable */ // @ts-nocheck import { - Address, AlgebraicType, AlgebraicValue, BinaryReader, BinaryWriter, CallReducerFlags, + ConnectionId, DBConnectionBuilder, DBConnectionImpl, DBContext, @@ -384,12 +384,12 @@ export namespace ClientConnected { /* tslint:disable */ // @ts-nocheck import { - Address, AlgebraicType, AlgebraicValue, BinaryReader, BinaryWriter, CallReducerFlags, + ConnectionId, DBConnectionBuilder, DBConnectionImpl, DBContext, @@ -447,12 +447,12 @@ export namespace DeletePlayer { /* tslint:disable */ // @ts-nocheck import { - Address, AlgebraicType, AlgebraicValue, BinaryReader, BinaryWriter, CallReducerFlags, + ConnectionId, DBConnectionBuilder, DBConnectionImpl, DBContext, @@ -510,12 +510,12 @@ export namespace DeletePlayersByName { /* tslint:disable */ // @ts-nocheck import { - Address, AlgebraicType, AlgebraicValue, BinaryReader, BinaryWriter, CallReducerFlags, + ConnectionId, DBConnectionBuilder, DBConnectionImpl, DBContext, @@ -588,12 +588,12 @@ export default Foobar; /* tslint:disable */ // @ts-nocheck import { - Address, AlgebraicType, AlgebraicValue, BinaryReader, BinaryWriter, CallReducerFlags, + ConnectionId, DBConnectionBuilder, DBConnectionImpl, DBContext, @@ -666,12 +666,12 @@ export class HasSpecialStuffTableHandle { /* tslint:disable */ // @ts-nocheck import { - Address, AlgebraicType, AlgebraicValue, BinaryReader, BinaryWriter, CallReducerFlags, + ConnectionId, DBConnectionBuilder, DBConnectionImpl, DBContext, @@ -693,7 +693,7 @@ import { } from "@clockworklabs/spacetimedb-sdk"; export type HasSpecialStuff = { identity: Identity, - address: Address, + connectionId: ConnectionId, }; /** @@ -707,7 +707,7 @@ export namespace HasSpecialStuff { export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ new ProductTypeElement("identity", AlgebraicType.createIdentityType()), - new ProductTypeElement("address", AlgebraicType.createAddressType()), + new ProductTypeElement("connectionId", AlgebraicType.createConnectionIdType()), ]); } @@ -731,12 +731,12 @@ export namespace HasSpecialStuff { /* tslint:disable */ // @ts-nocheck import { - Address, AlgebraicType, AlgebraicValue, BinaryReader, BinaryWriter, CallReducerFlags, + ConnectionId, DBConnectionBuilder, DBConnectionImpl, DBContext, @@ -1349,12 +1349,12 @@ export type ErrorContext = ErrorContextInterface { pub total_host_execution_duration: TimeDuration, } -/// Received by database from client to inform of user's identity, token and client address. +/// Received by database from client to inform of user's identity, token and client connection id. /// /// The database will always send an `IdentityToken` message /// as the first message for a new WebSocket connection. @@ -420,12 +420,9 @@ pub struct InitialSubscription { pub struct IdentityToken { pub identity: Identity, pub token: Box, - pub address: Address, + pub connection_id: ConnectionId, } -// TODO: Evaluate if it makes sense for this to also include the -// address of the database this is calling - /// Received by client from database upon a reducer run. /// /// Clients receive `TransactionUpdate`s only for reducers @@ -443,15 +440,16 @@ pub struct TransactionUpdate { /// The identity of the user who requested the reducer run. For event-driven and /// scheduled reducers, it is the identity of the database owner. pub caller_identity: Identity, - /// The 16-byte address of the user who requested the reducer run. - /// The all-zeros address is a sentinel which denotes no address. - /// `init` and `update` reducers will have a `caller_address` - /// if and only if one was provided to the `publish` HTTP endpoint. - /// Scheduled reducers will never have a `caller_address`. - /// Reducers invoked by HTTP will have a `caller_address` - /// if and only if one was provided to the `call` HTTP endpoint. - /// Reducers invoked by WebSocket will always have a `caller_address`. - pub caller_address: Address, + + /// The 16-byte [`ConnectionId`] of the user who requested the reducer run. + /// + /// The all-zeros id is a sentinel which denotes no meaningful value. + /// This can occur in the following situations: + /// - `init` and `update` reducers will have a `caller_connection_id` + /// if and only if one was provided to the `publish` HTTP endpoint. + /// - Scheduled reducers will never have a `caller_connection_id`. + /// - Reducers invoked by WebSocket or the HTTP API will always have a `caller_connection_id`. + pub caller_connection_id: ConnectionId, /// The original CallReducer request that triggered this reducer. pub reducer_call: ReducerCallInfo, /// The amount of energy credits consumed by running the reducer. diff --git a/crates/client-api/src/lib.rs b/crates/client-api/src/lib.rs index 7ee2d86e6b6..13b7e04ae1c 100644 --- a/crates/client-api/src/lib.rs +++ b/crates/client-api/src/lib.rs @@ -133,8 +133,6 @@ impl Host { /// See [`ControlStateDelegate::publish_database`]. pub struct DatabaseDef { /// The [`Identity`] the database shall have. - /// - /// Addresses are allocated via [`ControlStateDelegate::create_address`]. pub database_identity: Identity, /// The compiled program of the database module. pub program_bytes: Vec, @@ -196,7 +194,7 @@ pub trait ControlStateReadAccess { pub trait ControlStateWriteAccess: Send + Sync { /// Publish a database acc. to [`DatabaseDef`]. /// - /// If the database with the given address was successfully published before, + /// If the database with the given identity was successfully published before, /// it is updated acc. to the module lifecycle conventions. `Some` result is /// returned in that case. /// diff --git a/crates/client-api/src/routes/database.rs b/crates/client-api/src/routes/database.rs index 24be085804c..5f2b4d42f5e 100644 --- a/crates/client-api/src/routes/database.rs +++ b/crates/client-api/src/routes/database.rs @@ -2,7 +2,7 @@ use crate::auth::{ anon_auth_middleware, SpacetimeAuth, SpacetimeAuthHeader, SpacetimeEnergyUsed, SpacetimeExecutionDurationMicros, SpacetimeIdentity, SpacetimeIdentityToken, }; -use crate::routes::subscribe::generate_random_address; +use crate::routes::subscribe::generate_random_connection_id; use crate::util::{ByteStringBody, NameOrIdentity}; use crate::{log_and_500, ControlStateDelegate, DatabaseDef, NodeDelegate}; use axum::body::{Body, Bytes}; @@ -13,7 +13,6 @@ use axum_extra::TypedHeader; use futures::StreamExt; use http::StatusCode; use serde::{Deserialize, Serialize}; -use spacetimedb::address::Address; use spacetimedb::database_logger::DatabaseLogger; use spacetimedb::host::ReducerCallError; use spacetimedb::host::ReducerOutcome; @@ -23,7 +22,6 @@ use spacetimedb::identity::Identity; use spacetimedb::messages::control_db::{Database, HostType}; use spacetimedb_client_api_messages::name::{self, DnsLookupResponse, DomainName, PublishOp, PublishResult}; use spacetimedb_data_structures::map::HashMap; -use spacetimedb_lib::address::AddressForUrl; use spacetimedb_lib::db::raw_def::v9::RawModuleDefV9; use spacetimedb_lib::identity::AuthCtx; use spacetimedb_lib::sats::{self, WithTypespace}; @@ -46,30 +44,26 @@ pub struct CallParams { reducer: String, } -#[derive(Deserialize)] -pub struct CallQueryParams { - client_address: Option, -} - pub async fn call( State(worker_ctx): State, Extension(auth): Extension, Path(CallParams { - name_or_identity: name_or_address, + name_or_identity, reducer, }): Path, - Query(CallQueryParams { client_address }): Query, ByteStringBody(body): ByteStringBody, ) -> axum::response::Result { let caller_identity = auth.identity; let args = ReducerArgs::Json(body); - let address = name_or_address.resolve(&worker_ctx).await?.into(); - let database = worker_ctx_find_database(&worker_ctx, &address).await?.ok_or_else(|| { - log::error!("Could not find database: {}", address.to_hex()); - (StatusCode::NOT_FOUND, "No such database.") - })?; + let db_identity = name_or_identity.resolve(&worker_ctx).await?.into(); + let database = worker_ctx_find_database(&worker_ctx, &db_identity) + .await? + .ok_or_else(|| { + log::error!("Could not find database: {}", db_identity.to_hex()); + (StatusCode::NOT_FOUND, "No such database.") + })?; let identity = database.owner_identity; let leader = worker_ctx @@ -79,20 +73,18 @@ pub async fn call( .ok_or(StatusCode::NOT_FOUND)?; let module = leader.module().await.map_err(log_and_500)?; - // HTTP callers always need an address to provide to connect/disconnect, - // so generate one if none was provided. - let client_address = client_address - .map(Address::from) - .unwrap_or_else(generate_random_address); + // HTTP callers always need a connection ID to provide to connect/disconnect, + // so generate one. + let connection_id = generate_random_connection_id(); if let Err(e) = module - .call_identity_connected_disconnected(caller_identity, client_address, true) + .call_identity_connected_disconnected(caller_identity, connection_id, true) .await { return Err((StatusCode::NOT_FOUND, format!("{:#}", anyhow::anyhow!(e))).into()); } let result = match module - .call_reducer(caller_identity, Some(client_address), None, None, None, &reducer, args) + .call_reducer(caller_identity, Some(connection_id), None, None, None, &reducer, args) .await { Ok(rcr) => Ok(rcr), @@ -119,7 +111,7 @@ pub async fn call( }; if let Err(e) = module - .call_identity_connected_disconnected(caller_identity, client_address, false) + .call_identity_connected_disconnected(caller_identity, connection_id, false) .await { return Err((StatusCode::NOT_FOUND, format!("{:#}", anyhow::anyhow!(e))).into()); @@ -257,8 +249,8 @@ pub async fn describe( where S: ControlStateDelegate + NodeDelegate, { - let address = name_or_identity.resolve(&worker_ctx).await?.into(); - let database = worker_ctx_find_database(&worker_ctx, &address) + let db_identity = name_or_identity.resolve(&worker_ctx).await?.into(); + let database = worker_ctx_find_database(&worker_ctx, &db_identity) .await? .ok_or((StatusCode::NOT_FOUND, "No such database."))?; @@ -332,8 +324,8 @@ pub async fn catalog( where S: ControlStateDelegate + NodeDelegate, { - let address = name_or_identity.resolve(&worker_ctx).await?.into(); - let database = worker_ctx_find_database(&worker_ctx, &address) + let db_identity = name_or_identity.resolve(&worker_ctx).await?.into(); + let database = worker_ctx_find_database(&worker_ctx, &db_identity) .await? .ok_or((StatusCode::NOT_FOUND, "No such database."))?; @@ -398,7 +390,7 @@ pub async fn info( let database = worker_ctx_find_database(&worker_ctx, &database_identity) .await? .ok_or((StatusCode::NOT_FOUND, "No such database."))?; - log::trace!("Fetched database from the worker db for address: {database_identity:?}"); + log::trace!("Fetched database from the worker db for database identity: {database_identity:?}"); let response = InfoResponse::from(database); Ok(axum::Json(response)) @@ -530,8 +522,8 @@ where // Anyone is authorized to execute SQL queries. The SQL engine will determine // which queries this identity is allowed to execute against the database. - let address = name_or_identity.resolve(&worker_ctx).await?.into(); - let database = worker_ctx_find_database(&worker_ctx, &address) + let db_identity = name_or_identity.resolve(&worker_ctx).await?.into(); + let database = worker_ctx_find_database(&worker_ctx, &db_identity) .await? .ok_or((StatusCode::NOT_FOUND, "No such database."))?; @@ -584,9 +576,9 @@ pub async fn reverse_dns( State(ctx): State, Path(ReverseDNSParams { database_identity }): Path, ) -> axum::response::Result { - let database_address = Identity::from(database_identity); + let database_identity = Identity::from(database_identity); - let names = ctx.reverse_lookup(&database_address).map_err(log_and_500)?; + let names = ctx.reverse_lookup(&database_identity).map_err(log_and_500)?; let response = name::ReverseDNSResponse { names }; Ok(axum::Json(response)) @@ -621,7 +613,7 @@ pub struct PublishDatabaseQueryParams { } impl PublishDatabaseQueryParams { - pub fn name_or_address(&self) -> Option<&NameOrIdentity> { + pub fn name_or_identity(&self) -> Option<&NameOrIdentity> { self.name_or_identity.as_ref() } } @@ -645,8 +637,8 @@ pub async fn publish( Some(noa) => match noa.try_resolve(&ctx).await? { Ok(resolved) => resolved.into(), Err(domain) => { - // `name_or_address` was a `NameOrAddress::Name`, but no record - // exists yet. Create it now with a fresh address. + // `name_or_identity` was a `NameOrIdentity::Name`, but no record + // exists yet. Create it now with a fresh identity. let database_auth = SpacetimeAuth::alloc(&ctx).await?; let database_identity = database_auth.identity; ctx.create_dns_record(&auth.identity, &domain, &database_identity) @@ -662,7 +654,7 @@ pub async fn publish( } }; - log::trace!("Publishing to the address: {}", database_identity.to_hex()); + log::trace!("Publishing to the identity: {}", database_identity.to_hex()); let op = { let exists = ctx @@ -726,14 +718,12 @@ pub struct DeleteDatabaseParams { pub async fn delete_database( State(ctx): State, - Path(DeleteDatabaseParams { - database_identity: address, - }): Path, + Path(DeleteDatabaseParams { database_identity }): Path, Extension(auth): Extension, ) -> axum::response::Result { - let address = Identity::from(address); + let database_identity = Identity::from(database_identity); - ctx.delete_database(&auth.identity, &address) + ctx.delete_database(&auth.identity, &database_identity) .await .map_err(log_and_500)?; diff --git a/crates/client-api/src/routes/identity.rs b/crates/client-api/src/routes/identity.rs index 998ba7cd381..e8842155f1f 100644 --- a/crates/client-api/src/routes/identity.rs +++ b/crates/client-api/src/routes/identity.rs @@ -77,7 +77,7 @@ pub async fn get_databases( Path(GetDatabasesParams { identity }): Path, ) -> axum::response::Result { let identity = identity.into(); - // Linear scan for all databases that have this identity, and return their addresses + // Linear scan for all databases that have this owner, and return their identities let all_dbs = ctx.get_databases().map_err(|e| { log::error!("Failure when retrieving databases for search: {}", e); StatusCode::INTERNAL_SERVER_ERROR diff --git a/crates/client-api/src/routes/subscribe.rs b/crates/client-api/src/routes/subscribe.rs index 66137476078..1d4033cefc8 100644 --- a/crates/client-api/src/routes/subscribe.rs +++ b/crates/client-api/src/routes/subscribe.rs @@ -18,8 +18,7 @@ use spacetimedb::host::NoSuchModule; use spacetimedb::util::also_poll; use spacetimedb::worker_metrics::WORKER_METRICS; use spacetimedb_client_api_messages::websocket::{self as ws_api, Compression}; -use spacetimedb_lib::address::AddressForUrl; -use spacetimedb_lib::Address; +use spacetimedb_lib::connection_id::{ConnectionId, ConnectionIdForUrl}; use std::time::Instant; use tokio::sync::mpsc; @@ -42,7 +41,7 @@ pub struct SubscribeParams { #[derive(Deserialize)] pub struct SubscribeQueryParams { - pub client_address: Option, + pub connection_id: Option, #[serde(default)] pub compression: Compression, /// Whether we want "light" responses, tailored to network bandwidth constrained clients. @@ -51,19 +50,15 @@ pub struct SubscribeQueryParams { pub light: bool, } -// TODO: is this a reasonable way to generate client addresses? -// For DB addresses, [`ControlDb::alloc_spacetime_address`] -// maintains a global counter, and hashes the next value from that counter -// with some constant salt. -pub fn generate_random_address() -> Address { - Address::from_byte_array(rand::random()) +pub fn generate_random_connection_id() -> ConnectionId { + ConnectionId::from_le_byte_array(rand::random()) } pub async fn handle_websocket( State(ctx): State, Path(SubscribeParams { name_or_identity }): Path, Query(SubscribeQueryParams { - client_address, + connection_id, compression, light, }): Query, @@ -74,18 +69,23 @@ pub async fn handle_websocket( where S: NodeDelegate + ControlStateDelegate, { - let client_address = client_address - .map(Address::from) - .unwrap_or_else(generate_random_address); + if connection_id.is_some() { + // TODO: Bump this up to `log::warn!` after removing the client SDKs' uses of that parameter. + log::debug!("The connection_id query parameter to the subscribe HTTP endpoint is internal and will be removed in a future version of SpacetimeDB."); + } + + let connection_id = connection_id + .map(ConnectionId::from) + .unwrap_or_else(generate_random_connection_id); - if client_address == Address::__DUMMY { + if connection_id == ConnectionId::ZERO { Err(( StatusCode::BAD_REQUEST, - "Invalid client address: the all-zeros Address is reserved.", + "Invalid connection ID: the all-zeros ConnectionId is reserved.", ))?; } - let db_address = name_or_identity.resolve(&ctx).await?.into(); + let db_identity = name_or_identity.resolve(&ctx).await?.into(); let (res, ws_upgrade, protocol) = ws.select_protocol([(BIN_PROTOCOL, Protocol::Binary), (TEXT_PROTOCOL, Protocol::Text)]); @@ -101,7 +101,7 @@ where // to connect to multiple modules let database = ctx - .get_database_by_identity(&db_address) + .get_database_by_identity(&db_identity) .unwrap() .ok_or(StatusCode::NOT_FOUND)?; @@ -117,7 +117,7 @@ where let client_id = ClientActorId { identity: auth.identity, - address: client_address, + connection_id, name: ctx.client_actor_index().next_client_name(), }; @@ -162,7 +162,7 @@ where let message = IdentityTokenMessage { identity: auth.identity, token: identity_token, - address: client_address, + connection_id, }; if let Err(e) = client.send_message(message) { log::warn!("{e}, before identity token was sent") diff --git a/crates/client-api/src/routes/tracelog.rs b/crates/client-api/src/routes/tracelog.rs deleted file mode 100644 index 1caf935f34d..00000000000 --- a/crates/client-api/src/routes/tracelog.rs +++ /dev/null @@ -1,107 +0,0 @@ -use axum::body::Bytes; -use axum::extract::{Path, State}; -use axum::response::IntoResponse; -use http::StatusCode; -use serde::Deserialize; -use tempfile::TempDir; - -use spacetimedb::address::Address; -use spacetimedb::db::Storage; -use spacetimedb::hash::hash_bytes; -use spacetimedb::host::instance_env::InstanceEnv; -use spacetimedb::host::tracelog::replay::replay_report; -use spacetimedb::host::Scheduler; -use spacetimedb::replica_context::ReplicaContext; -use spacetimedb_lib::Identity; - -use crate::{log_and_500, ControlStateReadAccess, NodeDelegate}; - -#[derive(Deserialize)] -pub struct GetTraceParams { - address: Address, -} -pub async fn get_tracelog( - State(ctx): State, - Path(GetTraceParams { address }): Path, -) -> axum::response::Result { - let database = ctx - .get_database_by_address(&address) - .map_err(log_and_500)? - .ok_or((StatusCode::NOT_FOUND, "No such database."))?; - let replica = ctx.get_leader_replica_by_database(database.id); - let replica_id = replica.unwrap().id; - - let host = ctx.host_controller(); - let trace = host.get_trace(replica_id).await.map_err(|e| { - log::error!("Unable to retrieve tracelog {}", e); - (StatusCode::SERVICE_UNAVAILABLE, "Replica not ready.") - })?; - - let trace = trace.ok_or(StatusCode::NOT_FOUND)?; - - Ok(trace) -} - -#[derive(Deserialize)] -pub struct StopTraceParams { - address: Address, -} -pub async fn stop_tracelog( - State(ctx): State, - Path(StopTraceParams { address }): Path, -) -> axum::response::Result { - let database = ctx - .get_database_by_address(&address) - .map_err(log_and_500)? - .ok_or((StatusCode::NOT_FOUND, "No such database."))?; - let replica = ctx.get_leader_replica_by_database(database.id); - let replica_id = replica.unwrap().id; - - let host = ctx.host_controller(); - host.stop_trace(replica_id).await.map_err(|e| { - log::error!("Unable to retrieve tracelog {}", e); - (StatusCode::SERVICE_UNAVAILABLE, "Replica not ready.") - })?; - - Ok(()) -} - -pub async fn perform_tracelog_replay(body: Bytes) -> axum::response::Result { - // Build out a temporary database - let storage = Storage::Disk; - let tmp_dir = TempDir::with_prefix("stdb_test").expect("establish tmpdir"); - let db_path = tmp_dir.path(); - let logger_path = tmp_dir.path(); - let identity = Identity::from_byte_array(hash_bytes(b"This is a fake identity.").data); - let address = Address::from_slice(&identity.as_bytes()[0..16]); - let replica_ctx = ReplicaContext::new( - storage, - 0, - 0, - false, - identity, - address, - db_path.to_path_buf(), - logger_path, - ); - let iv = InstanceEnv::new(replica_ctx, Scheduler::dummy(&tmp_dir.path().join("scheduler")), None); - - let tx = iv.replica_ctx.relational_db.begin_mut_tx(IsolationLevel::Serializable); - - let (_, resp_body) = iv.tx.set(tx, || replay_report(&iv, &mut &body[..])); - - let resp_body = resp_body.map_err(log_and_500)?; - - Ok(axum::Json(resp_body)) -} - -pub fn router() -> axum::Router -where - S: ControlStateReadAccess + NodeDelegate + Clone + 'static, -{ - use axum::routing::{get, post}; - axum::Router::new() - .route("/database/:address", get(get_tracelog::)) - .route("/database/:address/stop", post(stop_tracelog::)) - .route("/replay", post(perform_tracelog_replay)) -} diff --git a/crates/client-api/src/util.rs b/crates/client-api/src/util.rs index 652906a2c74..97ece50c68d 100644 --- a/crates/client-api/src/util.rs +++ b/crates/client-api/src/util.rs @@ -73,19 +73,19 @@ impl NameOrIdentity { /// Resolve this [`NameOrIdentity`]. /// - /// If `self` is a [`NameOrIdentity::Address`], the inner [`Address`] is - /// returned in a [`ResolvedAddress`] without a [`DomainName`]. + /// If `self` is a [`NameOrIdentity::Identity`], the inner [`Identity`] is + /// returned in a [`ResolvedIdentity`] without a [`DomainName`]. /// - /// Otherwise, if `self` is a [`NameOrIdentity::Name`], the [`Address`] is + /// Otherwise, if `self` is a [`NameOrIdentity::Name`], the [`Identity`] is /// looked up by that name in the SpacetimeDB DNS and returned in a - /// [`ResolvedAddress`] alongside `Some` [`DomainName`]. + /// [`ResolvedIdentity`] alongside `Some` [`DomainName`]. /// /// Errors are returned if [`NameOrIdentity::Name`] cannot be parsed into a /// [`DomainName`], or the DNS lookup fails. /// /// An `Ok` result is itself a [`Result`], which is `Err(DomainName)` if the /// given [`NameOrIdentity::Name`] is not registered in the SpacetimeDB DNS, - /// i.e. no corresponding [`Address`] exists. + /// i.e. no corresponding [`Identity`] exists. pub async fn try_resolve( &self, ctx: &(impl ControlStateReadAccess + ?Sized), @@ -169,12 +169,7 @@ impl From for Identity { } impl From for (Identity, Option) { - fn from( - ResolvedIdentity { - identity: address, - domain, - }: ResolvedIdentity, - ) -> Self { - (address, domain) + fn from(ResolvedIdentity { identity, domain }: ResolvedIdentity) -> Self { + (identity, domain) } } diff --git a/crates/core/src/client.rs b/crates/core/src/client.rs index dc86c99a907..89c479c6bca 100644 --- a/crates/core/src/client.rs +++ b/crates/core/src/client.rs @@ -11,12 +11,12 @@ pub use client_connection::{ }; pub use client_connection_index::ClientActorIndex; pub use message_handlers::MessageHandleError; -use spacetimedb_lib::Address; +use spacetimedb_lib::ConnectionId; #[derive(PartialEq, Eq, Clone, Copy, Hash, Debug)] pub struct ClientActorId { pub identity: Identity, - pub address: Address, + pub connection_id: ConnectionId, pub name: ClientName, } @@ -25,7 +25,7 @@ impl ClientActorId { pub fn for_test(identity: Identity) -> Self { ClientActorId { identity, - address: Address::ZERO, + connection_id: ConnectionId::ZERO, name: ClientName(0), } } @@ -40,7 +40,7 @@ impl fmt::Display for ClientActorId { f, "ClientActorId({}@{}/{})", self.identity.to_hex(), - self.address.to_hex(), + self.connection_id.to_hex(), self.name.0 ) } diff --git a/crates/core/src/client/client_connection.rs b/crates/core/src/client/client_connection.rs index 04528129bdd..d3851152fe1 100644 --- a/crates/core/src/client/client_connection.rs +++ b/crates/core/src/client/client_connection.rs @@ -109,7 +109,7 @@ impl ClientConnectionSender { mpsc::error::TrySendError::Full(_) => { // we've hit CLIENT_CHANNEL_CAPACITY messages backed up in // the channel, so forcibly kick the client - tracing::warn!(identity = %self.id.identity, address = %self.id.address, "client channel capacity exceeded"); + tracing::warn!(identity = %self.id.identity, connection_id = %self.id.connection_id, "client channel capacity exceeded"); self.abort_handle.abort(); self.cancelled.store(true, Relaxed); ClientSendError::Cancelled @@ -180,7 +180,7 @@ impl ClientConnection { // them and stuff. Not right now though. let module = module_rx.borrow_and_update().clone(); module - .call_identity_connected_disconnected(id.identity, id.address, true) + .call_identity_connected_disconnected(id.identity, id.connection_id, true) .await?; let (sendtx, sendrx) = mpsc::channel::(CLIENT_CHANNEL_CAPACITY); @@ -268,14 +268,14 @@ impl ClientConnection { let caller = match flags { CallReducerFlags::FullUpdate => Some(self.sender()), // Setting `sender = None` causes `eval_updates` to skip sending to the caller - // as it has no access to the caller other than by id/addr. + // as it has no access to the caller other than by id/connection id. CallReducerFlags::NoSuccessNotify => None, }; self.module .call_reducer( self.id.identity, - Some(self.id.address), + Some(self.id.connection_id), caller, Some(request_id), Some(timer), diff --git a/crates/core/src/client/message_handlers.rs b/crates/core/src/client/message_handlers.rs index e31d4e1ec63..3235a569571 100644 --- a/crates/core/src/client/message_handlers.rs +++ b/crates/core/src/client/message_handlers.rs @@ -11,8 +11,7 @@ use bytes::Bytes; use bytestring::ByteString; use spacetimedb_lib::de::serde::DeserializeWrapper; use spacetimedb_lib::identity::RequestId; -use spacetimedb_lib::Timestamp; -use spacetimedb_lib::{bsatn, Address}; +use spacetimedb_lib::{bsatn, ConnectionId, Timestamp}; use std::sync::Arc; use std::time::{Duration, Instant}; @@ -59,7 +58,7 @@ pub async fn handle(client: &ClientConnection, message: DataMessage, timer: Inst } }; - let address = client.module.info().database_identity; + let database_identity = client.module.info().database_identity; let res = match message { ClientMessage::CallReducer(CallReducer { ref reducer, @@ -70,7 +69,7 @@ pub async fn handle(client: &ClientConnection, message: DataMessage, timer: Inst let res = client.call_reducer(reducer, args, request_id, timer, flags).await; WORKER_METRICS .request_round_trip - .with_label_values(&WorkloadType::Reducer, &address, reducer) + .with_label_values(&WorkloadType::Reducer, &database_identity, reducer) .observe(timer.elapsed().as_secs_f64()); res.map(drop).map_err(|e| { ( @@ -89,7 +88,7 @@ pub async fn handle(client: &ClientConnection, message: DataMessage, timer: Inst let res = client.subscribe_single(subscription, timer).await; WORKER_METRICS .request_round_trip - .with_label_values(&WorkloadType::Subscribe, &address, "") + .with_label_values(&WorkloadType::Subscribe, &database_identity, "") .observe(timer.elapsed().as_secs_f64()); res.map_err(|e| (None, None, e.into())) } @@ -97,7 +96,7 @@ pub async fn handle(client: &ClientConnection, message: DataMessage, timer: Inst let res = client.unsubscribe(request, timer).await; WORKER_METRICS .request_round_trip - .with_label_values(&WorkloadType::Unsubscribe, &address, "") + .with_label_values(&WorkloadType::Unsubscribe, &database_identity, "") .observe(timer.elapsed().as_secs_f64()); res.map_err(|e| (None, None, e.into())) } @@ -105,7 +104,7 @@ pub async fn handle(client: &ClientConnection, message: DataMessage, timer: Inst let res = client.subscribe(subscription, timer).await; WORKER_METRICS .request_round_trip - .with_label_values(&WorkloadType::Subscribe, &address, "") + .with_label_values(&WorkloadType::Subscribe, &database_identity, "") .observe(timer.elapsed().as_secs_f64()); res.map_err(|e| (None, None, e.into())) } @@ -119,7 +118,7 @@ pub async fn handle(client: &ClientConnection, message: DataMessage, timer: Inst }; WORKER_METRICS .request_round_trip - .with_label_values(&WorkloadType::Sql, &address, "") + .with_label_values(&WorkloadType::Sql, &database_identity, "") .observe(timer.elapsed().as_secs_f64()); res.map_err(|err| (None, None, err)) } @@ -128,7 +127,7 @@ pub async fn handle(client: &ClientConnection, message: DataMessage, timer: Inst reducer: reducer.cloned(), reducer_id, caller_identity: client.id.identity, - caller_address: Some(client.id.address), + caller_connection_id: Some(client.id.connection_id), err, })?; @@ -141,7 +140,7 @@ pub struct MessageExecutionError { pub reducer: Option>, pub reducer_id: Option, pub caller_identity: Identity, - pub caller_address: Option
, + pub caller_connection_id: Option, #[source] pub err: anyhow::Error, } @@ -151,7 +150,7 @@ impl MessageExecutionError { ModuleEvent { timestamp: Timestamp::now(), caller_identity: self.caller_identity, - caller_address: self.caller_address, + caller_connection_id: self.caller_connection_id, function_call: ModuleFunctionCall { reducer: self.reducer.unwrap_or_else(|| "".into()).into(), reducer_id: self.reducer_id.unwrap_or(u32::MAX.into()), diff --git a/crates/core/src/client/messages.rs b/crates/core/src/client/messages.rs index a7b1cb5e11b..519c618402b 100644 --- a/crates/core/src/client/messages.rs +++ b/crates/core/src/client/messages.rs @@ -10,7 +10,7 @@ use spacetimedb_client_api_messages::websocket::{ }; use spacetimedb_lib::identity::RequestId; use spacetimedb_lib::ser::serde::SerializeWrapper; -use spacetimedb_lib::{Address, TimeDuration}; +use spacetimedb_lib::{ConnectionId, TimeDuration}; use spacetimedb_primitives::TableId; use spacetimedb_sats::bsatn; use std::sync::Arc; @@ -171,7 +171,7 @@ impl ToProtocol for TransactionUpdateMessage { }, energy_quanta_used: event.energy_quanta_used, total_host_execution_duration: event.host_execution_duration.into(), - caller_address: event.caller_address.unwrap_or(Address::ZERO), + caller_connection_id: event.caller_connection_id.unwrap_or(ConnectionId::ZERO), }; ws::ServerMessage::TransactionUpdate(tx_update) diff --git a/crates/core/src/config.rs b/crates/core/src/config.rs index 79a6c311b42..a89d7087f49 100644 --- a/crates/core/src/config.rs +++ b/crates/core/src/config.rs @@ -4,7 +4,7 @@ use std::{fmt, io}; use toml; use toml_edit; -use spacetimedb_lib::Address; +use spacetimedb_lib::ConnectionId; use spacetimedb_paths::cli::{ConfigDir, PrivKeyPath, PubKeyPath}; use spacetimedb_paths::server::{ConfigToml, MetadataTomlPath}; @@ -27,8 +27,11 @@ pub fn parse_config(path: &Path) -> anyhow::Resu pub struct MetadataFile { pub version: semver::Version, pub edition: String, + #[serde(skip_serializing_if = "Option::is_none")] - pub client_address: Option
, + /// Unused and always `None` in SpacetimeDB-standalone, + /// but used by SpacetimeDB-cloud. + pub client_connection_id: Option, } impl MetadataFile { diff --git a/crates/core/src/db/datastore/locking_tx_datastore/datastore.rs b/crates/core/src/db/datastore/locking_tx_datastore/datastore.rs index 168d862dde3..2edddc570ae 100644 --- a/crates/core/src/db/datastore/locking_tx_datastore/datastore.rs +++ b/crates/core/src/db/datastore/locking_tx_datastore/datastore.rs @@ -18,9 +18,8 @@ use crate::{ db::{ datastore::{ system_tables::{ - read_addr_from_col, read_bytes_from_col, read_hash_from_col, read_identity_from_col, - system_table_schema, ModuleKind, StClientRow, StModuleFields, StModuleRow, StTableFields, ST_CLIENT_ID, - ST_MODULE_ID, ST_TABLE_ID, + read_bytes_from_col, read_hash_from_col, read_identity_from_col, system_table_schema, ModuleKind, + StClientRow, StModuleFields, StModuleRow, StTableFields, ST_CLIENT_ID, ST_MODULE_ID, ST_TABLE_ID, }, traits::{ DataRow, IsolationLevel, Metadata, MutTx, MutTxDatastore, Program, RowTypeForTable, Tx, TxData, @@ -38,7 +37,7 @@ use parking_lot::{Mutex, RwLock}; use spacetimedb_commitlog::payload::{txdata, Txdata}; use spacetimedb_durability::TxOffset; use spacetimedb_lib::{db::auth::StAccess, metrics::ExecutionMetrics}; -use spacetimedb_lib::{Address, Identity}; +use spacetimedb_lib::{ConnectionId, Identity}; use spacetimedb_paths::server::SnapshotDirPath; use spacetimedb_primitives::{ColList, ConstraintId, IndexId, SequenceId, TableId}; use spacetimedb_sats::{bsatn, buffer::BufReader, AlgebraicValue, ProductValue}; @@ -72,7 +71,7 @@ pub struct Locking { pub(crate) committed_state: Arc>, /// The state of sequence generation in this database. sequence_state: Arc>, - /// The address of this database. + /// The identity of this database. pub(crate) database_identity: Identity, } @@ -282,10 +281,10 @@ impl Locking { pub fn connected_clients<'a>( &'a self, tx: &'a TxId, - ) -> Result> + 'a> { + ) -> Result> + 'a> { let iter = self.iter_tx(tx, ST_CLIENT_ID)?.map(|row_ref| { let row = StClientRow::try_from(row_ref)?; - Ok((row.identity.0, row.address.0)) + Ok((row.identity.0, row.connection_id.0)) }); Ok(iter) @@ -998,7 +997,7 @@ impl spacetimedb_commitlog::payload::txdata::Visitor for ReplayVi /// reading only the columns necessary to construct the value. fn metadata_from_row(row: RowRef<'_>) -> Result { Ok(Metadata { - database_identity: read_addr_from_col(row, StModuleFields::DatabaseIdentity)?, + database_identity: read_identity_from_col(row, StModuleFields::DatabaseIdentity)?, owner_identity: read_identity_from_col(row, StModuleFields::OwnerIdentity)?, program_hash: read_hash_from_col(row, StModuleFields::ProgramHash)?, }) @@ -1507,7 +1506,7 @@ mod tests { ColRow { table: ST_MODULE_ID.into(), pos: 5, name: "module_version", ty: AlgebraicType::String }, ColRow { table: ST_CLIENT_ID.into(), pos: 0, name: "identity", ty: AlgebraicType::U256}, - ColRow { table: ST_CLIENT_ID.into(), pos: 1, name: "address", ty: AlgebraicType::U128}, + ColRow { table: ST_CLIENT_ID.into(), pos: 1, name: "connection_id", ty: AlgebraicType::U128}, ColRow { table: ST_VAR_ID.into(), pos: 0, name: "name", ty: AlgebraicType::String }, ColRow { table: ST_VAR_ID.into(), pos: 1, name: "value", ty: resolved_type_via_v9::() }, @@ -1529,7 +1528,7 @@ mod tests { IndexRow { id: 4, table: ST_SEQUENCE_ID.into(), col: col(0), name: "st_sequence_sequence_id_idx_btree", }, IndexRow { id: 5, table: ST_INDEX_ID.into(), col: col(0), name: "st_index_index_id_idx_btree", }, IndexRow { id: 6, table: ST_CONSTRAINT_ID.into(), col: col(0), name: "st_constraint_constraint_id_idx_btree", }, - IndexRow { id: 7, table: ST_CLIENT_ID.into(), col: col_list![0, 1], name: "st_client_identity_address_idx_btree", }, + IndexRow { id: 7, table: ST_CLIENT_ID.into(), col: col_list![0, 1], name: "st_client_identity_connection_id_idx_btree", }, IndexRow { id: 8, table: ST_VAR_ID.into(), col: col(0), name: "st_var_name_idx_btree", }, IndexRow { id: 9, table: ST_SCHEDULED_ID.into(), col: col(0), name: "st_scheduled_schedule_id_idx_btree", }, IndexRow { id: 10, table: ST_SCHEDULED_ID.into(), col: col(1), name: "st_scheduled_table_id_idx_btree", }, @@ -1559,7 +1558,7 @@ mod tests { ConstraintRow { constraint_id: 4, table_id: ST_SEQUENCE_ID.into(), unique_columns: col(0), constraint_name: "st_sequence_sequence_id_key", }, ConstraintRow { constraint_id: 5, table_id: ST_INDEX_ID.into(), unique_columns: col(0), constraint_name: "st_index_index_id_key", }, ConstraintRow { constraint_id: 6, table_id: ST_CONSTRAINT_ID.into(), unique_columns: col(0), constraint_name: "st_constraint_constraint_id_key", }, - ConstraintRow { constraint_id: 7, table_id: ST_CLIENT_ID.into(), unique_columns: col_list![0, 1], constraint_name: "st_client_identity_address_key", }, + ConstraintRow { constraint_id: 7, table_id: ST_CLIENT_ID.into(), unique_columns: col_list![0, 1], constraint_name: "st_client_identity_connection_id_key", }, ConstraintRow { constraint_id: 8, table_id: ST_VAR_ID.into(), unique_columns: col(0), constraint_name: "st_var_name_key", }, ConstraintRow { constraint_id: 9, table_id: ST_SCHEDULED_ID.into(), unique_columns: col(0), constraint_name: "st_scheduled_schedule_id_key", }, ConstraintRow { constraint_id: 10, table_id: ST_SCHEDULED_ID.into(), unique_columns: col(1), constraint_name: "st_scheduled_table_id_key", }, @@ -1966,7 +1965,7 @@ mod tests { IndexRow { id: 4, table: ST_SEQUENCE_ID.into(), col: col(0), name: "st_sequence_sequence_id_idx_btree", }, IndexRow { id: 5, table: ST_INDEX_ID.into(), col: col(0), name: "st_index_index_id_idx_btree", }, IndexRow { id: 6, table: ST_CONSTRAINT_ID.into(), col: col(0), name: "st_constraint_constraint_id_idx_btree", }, - IndexRow { id: 7, table: ST_CLIENT_ID.into(), col: col_list![0, 1], name: "st_client_identity_address_idx_btree", }, + IndexRow { id: 7, table: ST_CLIENT_ID.into(), col: col_list![0, 1], name: "st_client_identity_connection_id_idx_btree", }, IndexRow { id: 8, table: ST_VAR_ID.into(), col: col(0), name: "st_var_name_idx_btree", }, IndexRow { id: 9, table: ST_SCHEDULED_ID.into(), col: col(0), name: "st_scheduled_schedule_id_idx_btree", }, IndexRow { id: 10, table: ST_SCHEDULED_ID.into(), col: col(1), name: "st_scheduled_table_id_idx_btree", }, @@ -2020,7 +2019,7 @@ mod tests { IndexRow { id: 4, table: ST_SEQUENCE_ID.into(), col: col(0), name: "st_sequence_sequence_id_idx_btree", }, IndexRow { id: 5, table: ST_INDEX_ID.into(), col: col(0), name: "st_index_index_id_idx_btree", }, IndexRow { id: 6, table: ST_CONSTRAINT_ID.into(), col: col(0), name: "st_constraint_constraint_id_idx_btree", }, - IndexRow { id: 7, table: ST_CLIENT_ID.into(), col: col_list![0, 1], name: "st_client_identity_address_idx_btree", }, + IndexRow { id: 7, table: ST_CLIENT_ID.into(), col: col_list![0, 1], name: "st_client_identity_connection_id_idx_btree", }, IndexRow { id: 8, table: ST_VAR_ID.into(), col: col(0), name: "st_var_name_idx_btree", }, IndexRow { id: 9, table: ST_SCHEDULED_ID.into(), col: col(0), name: "st_scheduled_schedule_id_idx_btree", }, IndexRow { id: 10, table: ST_SCHEDULED_ID.into(), col: col(1), name: "st_scheduled_table_id_idx_btree", }, @@ -2075,7 +2074,7 @@ mod tests { IndexRow { id: 4, table: ST_SEQUENCE_ID.into(), col: col(0), name: "st_sequence_sequence_id_idx_btree", }, IndexRow { id: 5, table: ST_INDEX_ID.into(), col: col(0), name: "st_index_index_id_idx_btree", }, IndexRow { id: 6, table: ST_CONSTRAINT_ID.into(), col: col(0), name: "st_constraint_constraint_id_idx_btree", }, - IndexRow { id: 7, table: ST_CLIENT_ID.into(), col: col_list![0, 1], name: "st_client_identity_address_idx_btree", }, + IndexRow { id: 7, table: ST_CLIENT_ID.into(), col: col_list![0, 1], name: "st_client_identity_connection_id_idx_btree", }, IndexRow { id: 8, table: ST_VAR_ID.into(), col: col(0), name: "st_var_name_idx_btree", }, IndexRow { id: 9, table: ST_SCHEDULED_ID.into(), col: col(0), name: "st_scheduled_schedule_id_idx_btree", }, IndexRow { id: 10, table: ST_SCHEDULED_ID.into(), col: col(1), name: "st_scheduled_table_id_idx_btree", }, diff --git a/crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs b/crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs index d14a497e5a1..42bf40a30ec 100644 --- a/crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs +++ b/crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs @@ -1252,7 +1252,7 @@ impl MutTxId { /// This method is called with `GENERATE` false when updating the `st_sequence` system table. /// /// Requires: - /// - `table_id` must refer to a valid table for the database at `database_address`. + /// - `table_id` must refer to a valid table for the database at `database_identity`. /// - `row` must be a valid row for the table at `table_id`. /// /// Returns: @@ -1439,7 +1439,7 @@ impl MutTxId { /// The old row is found by projecting `row` to the columns of `index_id`. /// /// Requires: - /// - `table_id` must refer to a valid table for the database at `database_address`. + /// - `table_id` must refer to a valid table for the database at `database_identity`. /// - `index_id` must refer to a valid index in the table. /// - `row` must be a valid row for the table at `table_id`. /// diff --git a/crates/core/src/db/datastore/system_tables.rs b/crates/core/src/db/datastore/system_tables.rs index 2ae30c0fe9e..4c3d008ec41 100644 --- a/crates/core/src/db/datastore/system_tables.rs +++ b/crates/core/src/db/datastore/system_tables.rs @@ -19,7 +19,7 @@ use spacetimedb_lib::db::raw_def::*; use spacetimedb_lib::de::{Deserialize, DeserializeOwned, Error}; use spacetimedb_lib::ser::Serialize; use spacetimedb_lib::st_var::StVarValue; -use spacetimedb_lib::{Address, Identity, ProductValue, SpacetimeType}; +use spacetimedb_lib::{ConnectionId, Identity, ProductValue, SpacetimeType}; use spacetimedb_primitives::*; use spacetimedb_sats::algebraic_type::fmt::fmt_algebraic_type; use spacetimedb_sats::algebraic_value::ser::value_serialize; @@ -252,7 +252,7 @@ st_fields_enum!(enum StModuleFields { // WARNING: For a stable schema, don't change the field names and discriminants. st_fields_enum!(enum StClientFields { "identity", Identity = 0, - "address", Address = 1, + "connection_id", ConnectionId = 1, }); // WARNING: For a stable schema, don't change the field names and discriminants. st_fields_enum!(enum StVarFields { @@ -348,7 +348,7 @@ fn system_module_def() -> ModuleDef { // TODO: add empty unique constraint here, once we've implemented those. let st_client_type = builder.add_type::(); - let st_client_unique_cols = [StClientFields::Identity, StClientFields::Address]; + let st_client_unique_cols = [StClientFields::Identity, StClientFields::ConnectionId]; builder .build_table(ST_CLIENT_NAME, *st_client_type.as_ref().expect("should be ref")) .with_type(TableType::System) @@ -828,19 +828,19 @@ impl_serialize!([] ModuleKind, (self, ser) => self.0.serialize(ser)); impl_deserialize!([] ModuleKind, de => u8::deserialize(de).map(Self)); impl_st!([] ModuleKind, AlgebraicType::U8); -/// A wrapper for `Address` that acts like `AlgebraicType::bytes()` for serialization purposes. +/// A wrapper for [`ConnectionId`] that acts like [`AlgebraicType::U128`] for serialization purposes. #[derive(Clone, Copy, Debug, Eq, PartialEq)] -pub struct AddressViaU128(pub Address); -impl_serialize!([] AddressViaU128, (self, ser) => self.0.to_u128().serialize(ser)); -impl_deserialize!([] AddressViaU128, de => ::deserialize(de).map(Address::from_u128).map(AddressViaU128)); -impl_st!([] AddressViaU128, AlgebraicType::U128); -impl From
for AddressViaU128 { - fn from(addr: Address) -> Self { - Self(addr) +pub struct ConnectionIdViaU128(pub ConnectionId); +impl_serialize!([] ConnectionIdViaU128, (self, ser) => self.0.to_u128().serialize(ser)); +impl_deserialize!([] ConnectionIdViaU128, de => ::deserialize(de).map(ConnectionId::from_u128).map(ConnectionIdViaU128)); +impl_st!([] ConnectionIdViaU128, AlgebraicType::U128); +impl From for ConnectionIdViaU128 { + fn from(id: ConnectionId) -> Self { + Self(id) } } -/// A wrapper for `Identity` that acts like `AlgebraicType::bytes()` for serialization purposes. +/// A wrapper for [`Identity`] that acts like [`AlgebraicType::U256`] for serialization purposes. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct IdentityViaU256(pub Identity); impl_serialize!([] IdentityViaU256, (self, ser) => self.0.to_u256().serialize(ser)); @@ -891,14 +891,6 @@ pub fn read_bytes_from_col(row: RowRef<'_>, col: impl StFields) -> Result, col: impl StFields) -> Result { - let val: u256 = row.read_col(col.col_id())?; - Ok(Identity::from_u256(val)) -} - /// Read an [`Identity`] directly from the column `col` in `row`. /// /// The [`Identity`] is assumed to be stored as a flat byte array. @@ -929,14 +921,14 @@ impl From for ProductValue { /// System table [ST_CLIENT_NAME] /// -/// identity | address -/// -----------------------------------------------------------------------------------------+-------------------------------------------------------- -/// (__identity_bytes = 0x7452047061ea2502003412941d85a42f89b0702588b823ab55fc4f12e9ea8363) | (__address_bytes = 0x6bdea3ab517f5857dc9b1b5fe99e1b14) +/// | identity | connection_id | +/// |--------------------------------------------------------------------+------------------------------------| +/// | 0x7452047061ea2502003412941d85a42f89b0702588b823ab55fc4f12e9ea8363 | 0x6bdea3ab517f5857dc9b1b5fe99e1b14 | #[derive(Clone, Copy, Debug, Eq, PartialEq, SpacetimeType)] #[sats(crate = spacetimedb_lib)] pub struct StClientRow { pub(crate) identity: IdentityViaU256, - pub(crate) address: AddressViaU128, + pub(crate) connection_id: ConnectionIdViaU128, } impl From for ProductValue { diff --git a/crates/core/src/db/datastore/traits.rs b/crates/core/src/db/datastore/traits.rs index d12df909471..1f8b456f21a 100644 --- a/crates/core/src/db/datastore/traits.rs +++ b/crates/core/src/db/datastore/traits.rs @@ -312,9 +312,9 @@ pub trait MutTx { /// Standard metadata associated with a database. #[derive(Debug)] pub struct Metadata { - /// The stable address of the database. + /// The stable [`Identity`] of the database. pub database_identity: Identity, - /// The identity of the database's owner . + /// The identity of the database's owner. pub owner_identity: Identity, /// The hash of the binary module set for the database. pub program_hash: Hash, diff --git a/crates/core/src/db/db_metrics/mod.rs b/crates/core/src/db/db_metrics/mod.rs index 85ad4fe9853..6f375e65f13 100644 --- a/crates/core/src/db/db_metrics/mod.rs +++ b/crates/core/src/db/db_metrics/mod.rs @@ -110,7 +110,7 @@ metrics_group!( pub static DB_METRICS: Lazy = Lazy::new(DbMetrics::new); -/// Returns the number of committed rows in the table named by `table_name` and identified by `table_id` in the database `db_address`. +/// Returns the number of committed rows in the table named by `table_name` and identified by `table_id` in the database `db_identity`. pub fn table_num_rows(db_identity: Identity, table_id: TableId, table_name: &str) -> u64 { DB_METRICS .rdb_num_table_rows diff --git a/crates/core/src/db/relational_db.rs b/crates/core/src/db/relational_db.rs index fae0a3d8ec1..96afa932824 100644 --- a/crates/core/src/db/relational_db.rs +++ b/crates/core/src/db/relational_db.rs @@ -28,9 +28,9 @@ use parking_lot::RwLock; use spacetimedb_commitlog as commitlog; pub use spacetimedb_durability::Durability; use spacetimedb_durability::{self as durability, TxOffset}; -use spacetimedb_lib::address::Address; use spacetimedb_lib::db::auth::StAccess; use spacetimedb_lib::db::raw_def::v9::{btree, RawModuleDefV9Builder, RawSql}; +use spacetimedb_lib::ConnectionId; use spacetimedb_lib::Identity; use spacetimedb_paths::server::{CommitLogDir, ReplicaDir, SnapshotsPath}; use spacetimedb_primitives::*; @@ -81,7 +81,7 @@ pub const ONLY_MODULE_VERSION: &str = "0.0.1"; /// not shut down gracefully. Such "dangling" clients should be removed by /// calling [`crate::host::ModuleHost::call_identity_connected_disconnected`] /// for each entry in [`ConnectedClients`]. -pub type ConnectedClients = HashSet<(Identity, Address)>; +pub type ConnectedClients = HashSet<(Identity, ConnectionId)>; #[derive(Clone)] pub struct RelationalDB { @@ -178,7 +178,7 @@ pub const SNAPSHOT_FREQUENCY: u64 = 1_000_000; impl std::fmt::Debug for RelationalDB { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("RelationalDB") - .field("address", &self.database_identity) + .field("identity", &self.database_identity) .finish() } } @@ -239,13 +239,13 @@ impl RelationalDB { /// Note that, even if no `durability` is supplied, the directory will be /// created and equipped with an advisory lock file. /// - /// - `address` + /// - `database_identity` /// - /// The [`Address`] of the database. + /// The [`Identity`] of the database. /// /// An error is returned if the database already exists, but has a - /// different address. - /// If it is a new database, the address is stored in the database's + /// different identity. + /// If it is a new database, the identity is stored in the database's /// system tables upon calling [`Self::set_initialized`]. /// /// - `owner_identity` @@ -348,7 +348,7 @@ impl RelationalDB { /// Mark the database as initialized with the given module parameters. /// - /// Records the database's address, owner and module parameters in the + /// Records the database's identity, owner and module parameters in the /// system tables. The transactional context is supplied by the caller. /// /// It is an error to call this method on an alread-initialized database. @@ -446,7 +446,7 @@ impl RelationalDB { if snapshot.database_identity != database_identity { // TODO: return a proper typed error return Err(anyhow::anyhow!( - "Snapshot has incorrect database_address: expected {database_identity} but found {}", + "Snapshot has incorrect database_identity: expected {database_identity} but found {}", snapshot.database_identity, ) .into()); @@ -1285,7 +1285,7 @@ pub async fn local_durability(commitlog_dir: CommitLogDir) -> io::Result<(LocalD } /// Open a [`SnapshotRepository`] at `db_path/snapshots`, -/// configured to store snapshots of the database `database_address`/`replica_id`. +/// configured to store snapshots of the database `database_identity`/`replica_id`. pub fn open_snapshot_repo( path: SnapshotsPath, database_identity: Identity, @@ -2288,7 +2288,7 @@ mod tests { let ctx = ReducerContext { name: "abstract_concrete_proxy_factory_impl".into(), caller_identity: Identity::__dummy(), - caller_address: Address::__DUMMY, + caller_connection_id: ConnectionId::ZERO, timestamp, arg_bsatn: Bytes::new(), }; @@ -2310,7 +2310,7 @@ mod tests { Workload::Reducer(ReducerContext { name: "__identity_connected__".into(), caller_identity: Identity::__dummy(), - caller_address: Address::__DUMMY, + caller_connection_id: ConnectionId::ZERO, timestamp, arg_bsatn: Bytes::new(), }), @@ -2481,7 +2481,7 @@ mod tests { let ReducerContext { name: reducer_name, caller_identity, - caller_address, + caller_connection_id, timestamp: reducer_timestamp, arg_bsatn, } = ReducerContext::try_from(&input).unwrap(); @@ -2495,7 +2495,7 @@ mod tests { "expected args to be exhausted because nullary args were given" ); assert_eq!(caller_identity, Identity::ZERO); - assert_eq!(caller_address, Address::ZERO); + assert_eq!(caller_connection_id, ConnectionId::ZERO); assert_eq!(reducer_timestamp, timestamp); } } @@ -2511,11 +2511,11 @@ mod tests { let row_0 = StClientRow { identity: Identity::ZERO.into(), - address: Address::ZERO.into(), + connection_id: ConnectionId::ZERO.into(), }; let row_1 = StClientRow { identity: Identity::ZERO.into(), - address: Address::from_u128(1).into(), + connection_id: ConnectionId::from_u128(1).into(), }; let history = TestHistory::from_txes([ diff --git a/crates/core/src/execution_context.rs b/crates/core/src/execution_context.rs index 2d75d16550a..2e5a7570f04 100644 --- a/crates/core/src/execution_context.rs +++ b/crates/core/src/execution_context.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use bytes::Bytes; use derive_more::Display; use spacetimedb_commitlog::{payload::txdata, Varchar}; -use spacetimedb_lib::{Address, Identity, Timestamp}; +use spacetimedb_lib::{ConnectionId, Identity, Timestamp}; use spacetimedb_sats::bsatn; /// Represents the context under which a database runtime method is executed. @@ -28,8 +28,8 @@ pub struct ReducerContext { pub name: String, /// The [`Identity`] of the caller. pub caller_identity: Identity, - /// The [`Address`] of the caller. - pub caller_address: Address, + /// The [`ConnectionId`] of the caller. + pub caller_connection_id: ConnectionId, /// The timestamp of the reducer invocation. pub timestamp: Timestamp, /// The BSATN-encoded arguments given to the reducer. @@ -44,7 +44,7 @@ impl From<&ReducerContext> for txdata::Inputs { ReducerContext { name, caller_identity, - caller_address, + caller_connection_id, timestamp, arg_bsatn, }: &ReducerContext, @@ -53,13 +53,13 @@ impl From<&ReducerContext> for txdata::Inputs { let cap = arg_bsatn.len() /* caller_identity */ + 32 - /* caller_address */ + /* caller_connection_id */ + 16 /* timestamp */ + 8; let mut buf = Vec::with_capacity(cap); bsatn::to_writer(&mut buf, caller_identity).unwrap(); - bsatn::to_writer(&mut buf, caller_address).unwrap(); + bsatn::to_writer(&mut buf, caller_connection_id).unwrap(); bsatn::to_writer(&mut buf, timestamp).unwrap(); buf.extend_from_slice(arg_bsatn); @@ -76,13 +76,13 @@ impl TryFrom<&txdata::Inputs> for ReducerContext { fn try_from(inputs: &txdata::Inputs) -> Result { let args = &mut inputs.reducer_args.as_ref(); let caller_identity = bsatn::from_reader(args)?; - let caller_address = bsatn::from_reader(args)?; + let caller_connection_id = bsatn::from_reader(args)?; let timestamp = bsatn::from_reader(args)?; Ok(Self { name: inputs.reducer_name.to_string(), caller_identity, - caller_address, + caller_connection_id, timestamp, arg_bsatn: Bytes::from(args.to_owned()), }) @@ -199,7 +199,7 @@ impl ExecutionContext { Self::new(database_identity, None, WorkloadType::Internal) } - /// Returns the address of the database on which we are operating. + /// Returns the identity of the database on which we are operating. #[inline] pub fn database_identity(&self) -> Identity { self.database_identity diff --git a/crates/core/src/host/host_controller.rs b/crates/core/src/host/host_controller.rs index a6c1c45af05..db1301bebf0 100644 --- a/crates/core/src/host/host_controller.rs +++ b/crates/core/src/host/host_controller.rs @@ -620,7 +620,7 @@ async fn launch_module( replica_dir: ReplicaDir, runtimes: Arc, ) -> anyhow::Result<(Program, LaunchedModule)> { - let address = database.database_identity; + let db_identity = database.database_identity; let host_type = database.host_type; let replica_ctx = make_replica_ctx(replica_dir, database, replica_id, relational_db) @@ -638,7 +638,7 @@ async fn launch_module( ) .await?; - trace!("launched database {} with program {}", address, program.hash); + trace!("launched database {} with program {}", db_identity, program.hash); Ok(( program, @@ -788,14 +788,14 @@ impl Host { } = launched; // Disconnect dangling clients. - for (identity, address) in connected_clients { + for (identity, connection_id) in connected_clients { module_host - .call_identity_connected_disconnected(identity, address, false) + .call_identity_connected_disconnected(identity, connection_id, false) .await .with_context(|| { format!( "Error calling disconnect for {} {} on {}", - identity, address, replica_ctx.database_identity + identity, connection_id, replica_ctx.database_identity ) })?; } diff --git a/crates/core/src/host/module_host.rs b/crates/core/src/host/module_host.rs index 16c56d11a5e..d9641b3942b 100644 --- a/crates/core/src/host/module_host.rs +++ b/crates/core/src/host/module_host.rs @@ -31,7 +31,7 @@ use spacetimedb_data_structures::error_stream::ErrorStream; use spacetimedb_data_structures::map::{HashCollectionExt as _, IntMap}; use spacetimedb_lib::db::raw_def::v9::Lifecycle; use spacetimedb_lib::identity::{AuthCtx, RequestId}; -use spacetimedb_lib::Address; +use spacetimedb_lib::ConnectionId; use spacetimedb_lib::Timestamp; use spacetimedb_primitives::{col_list, TableId}; use spacetimedb_query::compile_subscription; @@ -167,7 +167,7 @@ pub struct ModuleFunctionCall { pub struct ModuleEvent { pub timestamp: Timestamp, pub caller_identity: Identity, - pub caller_address: Option
, + pub caller_connection_id: Option, pub function_call: ModuleFunctionCall, pub status: EventStatus, pub energy_quanta_used: EnergyQuanta, @@ -275,7 +275,7 @@ pub trait ModuleInstance: Send + 'static { pub struct CallReducerParams { pub timestamp: Timestamp, pub caller_identity: Identity, - pub caller_address: Address, + pub caller_connection_id: ConnectionId, pub client: Option>, pub request_id: Option, pub timer: Option, @@ -522,7 +522,7 @@ impl ModuleHost { .await; // ignore NoSuchModule; if the module's already closed, that's fine let _ = self - .call_identity_connected_disconnected(client_id.identity, client_id.address, false) + .call_identity_connected_disconnected(client_id.identity, client_id.connection_id, false) .await; } @@ -534,7 +534,7 @@ impl ModuleHost { pub async fn call_identity_connected_disconnected( &self, caller_identity: Identity, - caller_address: Address, + caller_connection_id: ConnectionId, connected: bool, ) -> Result<(), ReducerCallError> { let (lifecycle, fake_name) = if connected { @@ -551,7 +551,7 @@ impl ModuleHost { Workload::Reducer(ReducerContext { name: reducer_name.to_owned(), caller_identity, - caller_address, + caller_connection_id, timestamp: Timestamp::now(), arg_bsatn: Bytes::new(), }) @@ -560,7 +560,7 @@ impl ModuleHost { let result = if let Some((reducer_id, reducer_def)) = reducer_lookup { self.call_reducer_inner( caller_identity, - Some(caller_address), + Some(caller_connection_id), None, None, None, @@ -579,7 +579,7 @@ impl ModuleHost { // crash. db.with_auto_commit(workload(), |mut_tx| { if connected { - self.update_st_clients(mut_tx, caller_identity, caller_address, connected) + self.update_st_clients(mut_tx, caller_identity, caller_connection_id, connected) } else { Ok(()) } @@ -597,7 +597,7 @@ impl ModuleHost { if !connected { let _ = db .with_auto_commit(workload(), |mut_tx| { - self.update_st_clients(mut_tx, caller_identity, caller_address, connected) + self.update_st_clients(mut_tx, caller_identity, caller_connection_id, connected) }) .map_err(|e| { log::error!("st_clients table update failed with params with error: {:?}", e); @@ -610,14 +610,14 @@ impl ModuleHost { &self, mut_tx: &mut MutTxId, caller_identity: Identity, - caller_address: Address, + caller_connection_id: ConnectionId, connected: bool, ) -> Result<(), DBError> { let db = &*self.inner.replica_ctx().relational_db; let row = &StClientRow { identity: caller_identity.into(), - address: caller_address.into(), + connection_id: caller_connection_id.into(), }; if connected { @@ -627,7 +627,7 @@ impl ModuleHost { .iter_by_col_eq_mut( mut_tx, ST_CLIENT_ID, - col_list![StClientFields::Identity, StClientFields::Address], + col_list![StClientFields::Identity, StClientFields::ConnectionId], &algebraic_value::AlgebraicValue::product(row), )? .map(|row_ref| row_ref.pointer()) @@ -640,7 +640,7 @@ impl ModuleHost { async fn call_reducer_inner( &self, caller_identity: Identity, - caller_address: Option
, + caller_connection_id: Option, client: Option>, request_id: Option, timer: Option, @@ -650,7 +650,7 @@ impl ModuleHost { ) -> Result { let reducer_seed = ReducerArgsDeserializeSeed(self.info.module_def.typespace().with_type(reducer_def)); let args = args.into_tuple(reducer_seed)?; - let caller_address = caller_address.unwrap_or(Address::__DUMMY); + let caller_connection_id = caller_connection_id.unwrap_or(ConnectionId::ZERO); self.call(&reducer_def.name, move |inst| { inst.call_reducer( @@ -658,7 +658,7 @@ impl ModuleHost { CallReducerParams { timestamp: Timestamp::now(), caller_identity, - caller_address, + caller_connection_id, client, request_id, timer, @@ -674,7 +674,7 @@ impl ModuleHost { pub async fn call_reducer( &self, caller_identity: Identity, - caller_address: Option
, + caller_connection_id: Option, client: Option>, request_id: Option, timer: Option, @@ -692,7 +692,7 @@ impl ModuleHost { } self.call_reducer_inner( caller_identity, - caller_address, + caller_connection_id, client, request_id, timer, @@ -751,7 +751,7 @@ impl ModuleHost { Workload::Reducer(ReducerContext { name: reducer.into(), caller_identity: params.caller_identity, - caller_address: params.caller_address, + caller_connection_id: params.caller_connection_id, timestamp: Timestamp::now(), arg_bsatn: params.args.get_bsatn().clone(), }), diff --git a/crates/core/src/host/scheduler.rs b/crates/core/src/host/scheduler.rs index b188e0cd16f..4c128de7af9 100644 --- a/crates/core/src/host/scheduler.rs +++ b/crates/core/src/host/scheduler.rs @@ -6,7 +6,7 @@ use futures::StreamExt; use rustc_hash::FxHashMap; use spacetimedb_client_api_messages::energy::EnergyQuanta; use spacetimedb_lib::scheduler::ScheduleAt; -use spacetimedb_lib::Address; +use spacetimedb_lib::ConnectionId; use spacetimedb_lib::Timestamp; use spacetimedb_primitives::{ColId, TableId}; use spacetimedb_sats::{bsatn::ToBsatn as _, AlgebraicValue}; @@ -313,7 +313,7 @@ impl SchedulerActor { return Ok(Some(CallReducerParams { timestamp: Timestamp::now(), caller_identity, - caller_address: Address::default(), + caller_connection_id: ConnectionId::ZERO, client: None, request_id: None, timer: None, @@ -345,7 +345,7 @@ impl SchedulerActor { Ok(Some(CallReducerParams { timestamp: Timestamp::now(), caller_identity, - caller_address: Address::default(), + caller_connection_id: ConnectionId::ZERO, client: None, request_id: None, timer: None, @@ -435,7 +435,7 @@ fn commit_and_broadcast_deletion_event(tx: MutTxId, module_host: ModuleHost) { let event = ModuleEvent { timestamp: Timestamp::now(), caller_identity, - caller_address: None, + caller_connection_id: None, function_call: ModuleFunctionCall::default(), status: EventStatus::Committed(DatabaseUpdate::default()), //Keeping them 0 as it is internal transaction, not by reducer diff --git a/crates/core/src/host/wasm_common.rs b/crates/core/src/host/wasm_common.rs index af88a576139..0f7c69db5de 100644 --- a/crates/core/src/host/wasm_common.rs +++ b/crates/core/src/host/wasm_common.rs @@ -145,10 +145,10 @@ const CALL_REDUCER_SIG: StaticFuncSig = FuncSig::new( WasmType::I64, // `sender_1` contains bytes `[16..24]`. WasmType::I64, // `sender_1` contains bytes `[24..32]`. // ---------------------------------------------------- - // Caller's `Address` broken into 2 u64s. + // Caller's `ConnectionId` broken into 2 u64s. // ---------------------------------------------------- - WasmType::I64, // `address_0` contains bytes `[0..8 ]`. - WasmType::I64, // `address_1` contains bytes `[8..16]`. + WasmType::I64, // `conn_id_0` contains bytes `[0..8 ]`. + WasmType::I64, // `conn_id_1` contains bytes `[8..16]`. // ---------------------------------------------------- WasmType::I64, // Timestamp WasmType::I32, // Args source buffer diff --git a/crates/core/src/host/wasm_common/module_host_actor.rs b/crates/core/src/host/wasm_common/module_host_actor.rs index 6e89c21e181..1d106a6afc5 100644 --- a/crates/core/src/host/wasm_common/module_host_actor.rs +++ b/crates/core/src/host/wasm_common/module_host_actor.rs @@ -31,8 +31,7 @@ use crate::util::prometheus_handle::HistogramExt; use crate::worker_metrics::WORKER_METRICS; use spacetimedb_lib::buffer::DecodeError; use spacetimedb_lib::identity::AuthCtx; -use spacetimedb_lib::Timestamp; -use spacetimedb_lib::{bsatn, Address, RawModuleDef}; +use spacetimedb_lib::{bsatn, ConnectionId, RawModuleDef, Timestamp}; use super::*; @@ -322,7 +321,7 @@ impl ModuleInstance for WasmModuleInstance { CallReducerParams { timestamp, caller_identity, - caller_address: Address::__DUMMY, + caller_connection_id: ConnectionId::ZERO, client: None, request_id: None, timer: None, @@ -404,14 +403,14 @@ impl WasmModuleInstance { let CallReducerParams { timestamp, caller_identity, - caller_address, + caller_connection_id, client, request_id, reducer_id, args, timer, } = params; - let caller_address_opt = (caller_address != Address::__DUMMY).then_some(caller_address); + let caller_connection_id_opt = (caller_connection_id != ConnectionId::ZERO).then_some(caller_connection_id); let replica_ctx = self.replica_context(); let stdb = &*replica_ctx.relational_db.clone(); @@ -422,7 +421,7 @@ impl WasmModuleInstance { let _outer_span = tracing::trace_span!("call_reducer", reducer_name, %caller_identity, - caller_address = caller_address_opt.map(tracing::field::debug), + caller_connection_id = caller_connection_id_opt.map(tracing::field::debug), ) .entered(); @@ -438,7 +437,7 @@ impl WasmModuleInstance { id: reducer_id, name: reducer_name, caller_identity: &caller_identity, - caller_address: &caller_address, + caller_connection_id: &caller_connection_id, timestamp, arg_bytes: args.get_bsatn().clone(), }; @@ -519,7 +518,12 @@ impl WasmModuleInstance { WORKER_METRICS .wasm_instance_errors - .with_label_values(&caller_identity, &self.info.module_hash, &caller_address, reducer_name) + .with_label_values( + &caller_identity, + &self.info.module_hash, + &caller_connection_id, + reducer_name, + ) .inc(); // discard this instance @@ -553,7 +557,7 @@ impl WasmModuleInstance { // Detecing a new client, and inserting it in `st_clients` // Disconnect logic is written in module_host.rs, due to different transacationality requirements. if reducer_def.lifecycle == Some(Lifecycle::OnConnect) { - match self.insert_st_client(&mut tx, caller_identity, caller_address) { + match self.insert_st_client(&mut tx, caller_identity, caller_connection_id) { Ok(_) => EventStatus::Committed(DatabaseUpdate::default()), Err(err) => EventStatus::Failed(err.to_string()), } @@ -566,7 +570,7 @@ impl WasmModuleInstance { let event = ModuleEvent { timestamp, caller_identity, - caller_address: caller_address_opt, + caller_connection_id: caller_connection_id_opt, function_call: ModuleFunctionCall { reducer: reducer_name.to_owned(), reducer_id, @@ -600,10 +604,15 @@ impl WasmModuleInstance { self.replica_context().logger.system_logger() } - fn insert_st_client(&self, tx: &mut MutTxId, identity: Identity, address: Address) -> Result<(), DBError> { + fn insert_st_client( + &self, + tx: &mut MutTxId, + identity: Identity, + connection_id: ConnectionId, + ) -> Result<(), DBError> { let row = &StClientRow { identity: identity.into(), - address: address.into(), + connection_id: connection_id.into(), }; tx.insert_via_serialize_bsatn(ST_CLIENT_ID, row).map(|_| ()) } @@ -615,7 +624,7 @@ pub struct ReducerOp<'a> { pub id: ReducerId, pub name: &'a str, pub caller_identity: &'a Identity, - pub caller_address: &'a Address, + pub caller_connection_id: &'a ConnectionId, pub timestamp: Timestamp, /// The BSATN-serialized arguments passed to the reducer. pub arg_bytes: Bytes, @@ -627,7 +636,7 @@ impl From> for execution_context::ReducerContext { id: _, name, caller_identity, - caller_address, + caller_connection_id, timestamp, arg_bytes, }: ReducerOp<'_>, @@ -635,7 +644,7 @@ impl From> for execution_context::ReducerContext { Self { name: name.to_owned(), caller_identity: *caller_identity, - caller_address: *caller_address, + caller_connection_id: *caller_connection_id, timestamp, arg_bsatn: arg_bytes.clone(), } diff --git a/crates/core/src/host/wasmtime/wasmtime_module.rs b/crates/core/src/host/wasmtime/wasmtime_module.rs index 9a470704a78..c728177d63e 100644 --- a/crates/core/src/host/wasmtime/wasmtime_module.rs +++ b/crates/core/src/host/wasmtime/wasmtime_module.rs @@ -194,9 +194,9 @@ impl module_host_actor::WasmInstance for WasmtimeInstance { set_store_fuel(store, budget.into()); let original_fuel = get_store_fuel(store); - // Prepare sender identity and address, as LITTLE-ENDIAN byte arrays. + // Prepare sender identity and connection ID, as LITTLE-ENDIAN byte arrays. let [sender_0, sender_1, sender_2, sender_3] = bytemuck::must_cast(op.caller_identity.to_byte_array()); - let [address_0, address_1] = bytemuck::must_cast(op.caller_address.as_byte_array()); + let [conn_id_0, conn_id_1] = bytemuck::must_cast(op.caller_connection_id.as_le_byte_array()); // Prepare arguments to the reducer + the error sink & start timings. let (args_source, errors_sink) = store.data_mut().start_reducer(op.name, op.arg_bytes); @@ -209,8 +209,8 @@ impl module_host_actor::WasmInstance for WasmtimeInstance { sender_1, sender_2, sender_3, - address_0, - address_1, + conn_id_0, + conn_id_1, op.timestamp.to_micros_since_unix_epoch() as u64, args_source, errors_sink, diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 941c99a6e36..e9b1b95bf33 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -4,9 +4,6 @@ pub mod energy; pub mod json; pub mod sql; -pub mod address { - pub use spacetimedb_lib::Address; -} pub mod auth; pub mod db; pub mod messages; diff --git a/crates/core/src/sql/compiler.rs b/crates/core/src/sql/compiler.rs index 2404114f708..b0f7f598da5 100644 --- a/crates/core/src/sql/compiler.rs +++ b/crates/core/src/sql/compiler.rs @@ -235,7 +235,7 @@ mod tests { use crate::execution_context::Workload; use crate::sql::execute::tests::run_for_testing; use spacetimedb_lib::error::{ResultTest, TestError}; - use spacetimedb_lib::{Address, Identity}; + use spacetimedb_lib::{ConnectionId, Identity}; use spacetimedb_primitives::{col_list, ColList, TableId}; use spacetimedb_sats::{ product, satn, AlgebraicType, AlgebraicValue, GroundSpacetimeType as _, ProductType, Typespace, ValueWithType, @@ -341,14 +341,14 @@ mod tests { } #[test] - fn compile_eq_identity_address() -> ResultTest<()> { + fn compile_eq_identity_connection_id() -> ResultTest<()> { let db = TestDB::durable()?; // Create table [test] without any indexes let schema = &[ ("identity", Identity::get_type()), ("identity_mix", Identity::get_type()), - ("address", Address::get_type()), + ("connection_id", ConnectionId::get_type()), ]; let indexes = &[]; let table_id = db.create_table_for_test("test", schema, indexes)?; @@ -356,7 +356,7 @@ mod tests { let row = product![ Identity::__dummy(), Identity::from_hex("93dda09db9a56d8fa6c024d843e805d8262191db3b4ba84c5efcd1ad451fed4e").unwrap(), - Address::__DUMMY + ConnectionId::ZERO, ]; db.with_auto_commit(Workload::ForTests, |tx| { @@ -366,18 +366,18 @@ mod tests { // Check can be used by CRUD ops: let sql = &format!( - "INSERT INTO test (identity, identity_mix, address) VALUES ({}, x'91DDA09DB9A56D8FA6C024D843E805D8262191DB3B4BA84C5EFCD1AD451FED4E', {})", + "INSERT INTO test (identity, identity_mix, connection_id) VALUES ({}, x'91DDA09DB9A56D8FA6C024D843E805D8262191DB3B4BA84C5EFCD1AD451FED4E', {})", Identity::__dummy(), - Address::__DUMMY, + ConnectionId::ZERO, ); run_for_testing(&db, sql)?; // Compile query, check for both hex formats and it to be case-insensitive... let sql = &format!( - "select * from test where identity = {} AND identity_mix = x'93dda09db9a56d8fa6c024d843e805D8262191db3b4bA84c5efcd1ad451fed4e' AND address = x'{}' AND address = {}", + "select * from test where identity = {} AND identity_mix = x'93dda09db9a56d8fa6c024d843e805D8262191db3b4bA84c5efcd1ad451fed4e' AND connection_id = x'{}' AND connection_id = {}", Identity::__dummy(), - Address::__DUMMY, - Address::__DUMMY, + ConnectionId::ZERO, + ConnectionId::ZERO, ); let rows = run_for_testing(&db, sql)?; @@ -403,9 +403,9 @@ mod tests { Ok(()) } - // Verify the output of `sql` matches the inputs for `Identity`, 'Address' & binary data. + // Verify the output of `sql` matches the inputs for `Identity`, 'ConnectionId' & binary data. #[test] - fn output_identity_address() -> ResultTest<()> { + fn output_identity_connection_id() -> ResultTest<()> { let row = product![AlgebraicValue::from(Identity::__dummy())]; let kind: ProductType = [("i", Identity::get_type())].into(); let ty = Typespace::EMPTY.with_type(&kind); @@ -421,7 +421,7 @@ mod tests { ("a", AlgebraicType::String), ("b", AlgebraicType::U256), ("o", Identity::get_type()), - ("p", Address::get_type()), + ("p", ConnectionId::get_type()), ] .into(); @@ -429,7 +429,7 @@ mod tests { AlgebraicValue::String("a".into()), Identity::ZERO.to_u256().into(), Identity::ZERO.to_u256().into(), - Address::__DUMMY.to_u128().into(), + ConnectionId::ZERO.to_u128().into(), ]); assert_eq!( @@ -444,7 +444,7 @@ mod tests { "a", Identity::ZERO.to_u256(), AlgebraicValue::product([Identity::ZERO.to_u256().into()]), - AlgebraicValue::product([Address::__DUMMY.to_u128().into()]), + AlgebraicValue::product([ConnectionId::ZERO.to_u128().into()]), ]; let value = ValueWithType::new(ty, &value); diff --git a/crates/core/src/sql/execute.rs b/crates/core/src/sql/execute.rs index 390d8ad1234..3a566e117fd 100644 --- a/crates/core/src/sql/execute.rs +++ b/crates/core/src/sql/execute.rs @@ -129,7 +129,7 @@ pub fn execute_sql( let event = ModuleEvent { timestamp: Timestamp::now(), caller_identity: auth.caller, - caller_address: None, + caller_connection_id: None, function_call: ModuleFunctionCall { reducer: String::new(), reducer_id: u32::MAX.into(), @@ -242,7 +242,7 @@ pub fn run( ModuleEvent { timestamp: Timestamp::now(), caller_identity: auth.caller, - caller_address: None, + caller_connection_id: None, function_call: ModuleFunctionCall { reducer: String::new(), reducer_id: u32::MAX.into(), diff --git a/crates/core/src/sql/type_check.rs b/crates/core/src/sql/type_check.rs index 29cb5799a48..6922cb8da6e 100644 --- a/crates/core/src/sql/type_check.rs +++ b/crates/core/src/sql/type_check.rs @@ -145,7 +145,7 @@ fn check_both(op: OpQuery, lhs: &Typed, rhs: &Typed) -> Result<(), PlanError> { Ok(()) } -/// Patch the type of the field if the type is an `Identity`, `Address` or `Enum` +/// Patch the type of the field if the type is an `Identity`, `ConnectionId` or `Enum` fn patch_type(lhs: &FieldOp, ty_lhs: &mut Typed, ty_rhs: &Typed) -> Result<(), PlanError> { if let FieldOp::Field(lhs_field) = lhs { if let Some(ty) = ty_rhs.ty() { @@ -178,7 +178,7 @@ fn type_check(of: QueryFragment) -> Result { let mut ty_lhs = type_check(QueryFragment { from: of.from, q: lhs })?; let mut ty_rhs = type_check(QueryFragment { from: of.from, q: rhs })?; - // TODO: For the cases of `Identity, Address, Enum` we need to resolve the type from the value we are comparing, + // TODO: For the cases of `Identity, ConnectionId, Enum` we need to resolve the type from the value we are comparing, // because the type is not lifted when we parse the query on `spacetimedb_vm::ops::parse`. // // This is a temporary solution until we have a better way to resolve the type of the field. diff --git a/crates/core/src/subscription/module_subscription_actor.rs b/crates/core/src/subscription/module_subscription_actor.rs index b8e10139db5..c4fdeb39e1d 100644 --- a/crates/core/src/subscription/module_subscription_actor.rs +++ b/crates/core/src/subscription/module_subscription_actor.rs @@ -199,14 +199,16 @@ impl ModuleSubscriptions { }; let mut subscriptions = self.subscriptions.write(); - let query = match subscriptions.remove_subscription((sender.id.identity, sender.id.address), request.query_id) { - Ok(query) => query, - Err(error) => { - // Apparently we ignore errors sending messages. - let _ = send_err_msg(error.to_string().into()); - return Ok(()); - } - }; + + let query = + match subscriptions.remove_subscription((sender.id.identity, sender.id.connection_id), request.query_id) { + Ok(query) => query, + Err(error) => { + // Apparently we ignore errors sending messages. + let _ = send_err_msg(error.to_string().into()); + return Ok(()); + } + }; let tx = scopeguard::guard(self.relational_db.begin_tx(Workload::Unsubscribe), |tx| { self.relational_db.release_tx(tx); @@ -353,7 +355,7 @@ impl ModuleSubscriptions { pub fn remove_subscriber(&self, client_id: ClientActorId) { let mut subscriptions = self.subscriptions.write(); - subscriptions.remove_all_subscriptions(&(client_id.identity, client_id.address)); + subscriptions.remove_all_subscriptions(&(client_id.identity, client_id.connection_id)); WORKER_METRICS .subscription_queries .with_label_values(&self.relational_db.database_identity()) @@ -505,7 +507,7 @@ mod tests { ModuleEvent { timestamp: Timestamp::now(), caller_identity: Identity::ZERO, - caller_address: None, + caller_connection_id: None, function_call: ModuleFunctionCall::default(), status: EventStatus::Committed(DatabaseUpdate::default()), energy_quanta_used: EnergyQuanta { quanta: 0 }, diff --git a/crates/core/src/subscription/module_subscription_manager.rs b/crates/core/src/subscription/module_subscription_manager.rs index f51aa231c68..b6329ff036a 100644 --- a/crates/core/src/subscription/module_subscription_manager.rs +++ b/crates/core/src/subscription/module_subscription_manager.rs @@ -19,17 +19,17 @@ use spacetimedb_client_api_messages::websocket::{ }; use spacetimedb_data_structures::map::{Entry, IntMap}; use spacetimedb_lib::metrics::ExecutionMetrics; -use spacetimedb_lib::{Address, Identity}; +use spacetimedb_lib::{ConnectionId, Identity}; use spacetimedb_primitives::TableId; use spacetimedb_subscription::SubscriptionPlan; use std::ops::Deref; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; -/// Clients are uniquely identified by their Identity and Address. -/// Identity is insufficient because different Addresses can use the same Identity. -/// TODO: Determine if Address is sufficient for uniquely identifying a client. -type ClientId = (Identity, Address); +/// Clients are uniquely identified by their Identity and ConnectionId. +/// Identity is insufficient because different ConnectionIds can use the same Identity. +/// TODO: Determine if ConnectionId is sufficient for uniquely identifying a client. +type ClientId = (Identity, ConnectionId); type Query = Arc; type Client = Arc; type SwitchedDbUpdate = FormatSwitch, ws::DatabaseUpdate>; @@ -247,7 +247,7 @@ impl SubscriptionManager { /// Adds a single subscription for a client. pub fn add_subscription(&mut self, client: Client, query: Query, query_id: ClientQueryId) -> Result<(), DBError> { - let client_id = (client.id.identity, client.id.address); + let client_id = (client.id.identity, client.id.connection_id); // Clean up any dropped subscriptions if self @@ -298,7 +298,7 @@ impl SubscriptionManager { /// its table ids added to the inverted index. // #[tracing::instrument(level = "trace", skip_all)] pub fn set_legacy_subscription(&mut self, client: Client, queries: impl IntoIterator) { - let client_id = (client.id.identity, client.id.address); + let client_id = (client.id.identity, client.id.connection_id); // First, remove any existing legacy subscriptions. self.remove_legacy_subscriptions(&client_id); @@ -553,9 +553,9 @@ impl SubscriptionManager { // Regardless, the update that we send to the caller, if we send any, // is a full tx update, rather than a light one. // That is, in the case of the caller, we don't respect the light setting. - if let Some((caller, addr)) = caller.zip(event.caller_address) { + if let Some((caller, conn_id)) = caller.zip(event.caller_connection_id) { let database_update = eval - .remove(&(event.caller_identity, addr)) + .remove(&(event.caller_identity, conn_id)) .map(|update| SubscriptionUpdateMessage::from_event_and_update(&event, update)) .unwrap_or_else(|| { SubscriptionUpdateMessage::default_for_protocol(caller.config.protocol, event.request_id) @@ -610,8 +610,7 @@ mod tests { use std::{sync::Arc, time::Duration}; use spacetimedb_client_api_messages::websocket::QueryId; - use spacetimedb_lib::Timestamp; - use spacetimedb_lib::{error::ResultTest, identity::AuthCtx, Address, AlgebraicType, Identity}; + use spacetimedb_lib::{error::ResultTest, identity::AuthCtx, AlgebraicType, ConnectionId, Identity, Timestamp}; use spacetimedb_primitives::TableId; use spacetimedb_subscription::SubscriptionPlan; @@ -644,16 +643,16 @@ mod tests { }) } - fn id(address: u128) -> (Identity, Address) { - (Identity::ZERO, Address::from_u128(address)) + fn id(connection_id: u128) -> (Identity, ConnectionId) { + (Identity::ZERO, ConnectionId::from_u128(connection_id)) } - fn client(address: u128) -> ClientConnectionSender { - let (identity, address) = id(address); + fn client(connection_id: u128) -> ClientConnectionSender { + let (identity, connection_id) = id(connection_id); ClientConnectionSender::dummy( ClientActorId { identity, - address, + connection_id, name: ClientName(0), }, ClientConfig::for_test(), @@ -717,7 +716,7 @@ mod tests { subscriptions.add_subscription(client.clone(), plan.clone(), query_id)?; assert!(subscriptions.query_reads_from_table(&hash, &table_id)); - let client_id = (client.id.identity, client.id.address); + let client_id = (client.id.identity, client.id.connection_id); subscriptions.remove_subscription(client_id, query_id)?; assert!(!subscriptions.query_reads_from_table(&hash, &table_id)); @@ -738,7 +737,7 @@ mod tests { let mut subscriptions = SubscriptionManager::default(); subscriptions.add_subscription(client.clone(), plan.clone(), query_id)?; - let client_id = (client.id.identity, client.id.address); + let client_id = (client.id.identity, client.id.connection_id); assert!(subscriptions.remove_subscription(client_id, QueryId::new(2)).is_err()); Ok(()) @@ -760,7 +759,7 @@ mod tests { subscriptions.add_subscription(client.clone(), plan.clone(), query_id)?; subscriptions.add_subscription(client.clone(), plan.clone(), QueryId::new(2))?; - let client_id = (client.id.identity, client.id.address); + let client_id = (client.id.identity, client.id.connection_id); subscriptions.remove_subscription(client_id, query_id)?; assert!(subscriptions.query_reads_from_table(&hash, &table_id)); @@ -790,7 +789,7 @@ mod tests { let client_ids = clients .iter() - .map(|client| (client.id.identity, client.id.address)) + .map(|client| (client.id.identity, client.id.connection_id)) .collect::>(); subscriptions.remove_subscription(client_ids[0], query_id)?; // There are still two left. @@ -827,7 +826,7 @@ mod tests { let client_ids = clients .iter() - .map(|client| (client.id.identity, client.id.address)) + .map(|client| (client.id.identity, client.id.connection_id)) .collect::>(); subscriptions.remove_all_subscriptions(&client_ids[0]); assert!(!subscriptions.contains_client(&client_ids[0])); @@ -870,7 +869,7 @@ mod tests { assert!(subscriptions.query_reads_from_table(&queries[i].hash(), &table_ids[i])); } - let client_id = (client.id.identity, client.id.address); + let client_id = (client.id.identity, client.id.connection_id); subscriptions.remove_subscription(client_id, QueryId::new(1))?; assert!(!subscriptions.query_reads_from_table(&queries[0].hash(), &table_ids[0])); // Assert that the rest are there. @@ -1079,7 +1078,7 @@ mod tests { let event = Arc::new(ModuleEvent { timestamp: Timestamp::now(), caller_identity: id0, - caller_address: Some(client0.id.address), + caller_connection_id: Some(client0.id.connection_id), function_call: ModuleFunctionCall { reducer: "DummyReducer".into(), reducer_id: u32::MAX.into(), diff --git a/crates/core/src/worker_metrics/mod.rs b/crates/core/src/worker_metrics/mod.rs index 666353fff06..953b1d0f8a1 100644 --- a/crates/core/src/worker_metrics/mod.rs +++ b/crates/core/src/worker_metrics/mod.rs @@ -2,7 +2,7 @@ use crate::execution_context::WorkloadType; use crate::hash::Hash; use once_cell::sync::Lazy; use prometheus::{HistogramVec, IntCounterVec, IntGaugeVec}; -use spacetimedb_lib::{Address, Identity}; +use spacetimedb_lib::{ConnectionId, Identity}; use spacetimedb_metrics::metrics_group; metrics_group!( @@ -82,7 +82,7 @@ metrics_group!( #[name = spacetime_worker_wasm_instance_errors_total] #[help = "The number of fatal WASM instance errors, such as reducer panics."] - #[labels(caller_identity: Identity, module_hash: Hash, caller_address: Address, reducer_symbol: str)] + #[labels(caller_identity: Identity, module_hash: Hash, caller_connection_id: ConnectionId, reducer_symbol: str)] pub wasm_instance_errors: IntCounterVec, #[name = spacetime_worker_wasm_memory_bytes] diff --git a/crates/expr/src/lib.rs b/crates/expr/src/lib.rs index 25ae6696297..3a45221db47 100644 --- a/crates/expr/src/lib.rs +++ b/crates/expr/src/lib.rs @@ -11,7 +11,7 @@ use errors::{DuplicateName, InvalidLiteral, InvalidOp, InvalidWildcard, Unexpect use ethnum::i256; use ethnum::u256; use expr::{Expr, FieldProject, ProjectList, ProjectName, RelExpr}; -use spacetimedb_lib::{from_hex_pad, Address, AlgebraicType, AlgebraicValue, Identity}; +use spacetimedb_lib::{from_hex_pad, AlgebraicType, AlgebraicValue, ConnectionId, Identity}; use spacetimedb_sats::algebraic_type::fmt::fmt_algebraic_type; use spacetimedb_schema::schema::ColumnSchema; use spacetimedb_sql_parser::ast::{self, BinOp, ProjectElem, SqlExpr, SqlIdent, SqlLiteral}; @@ -117,7 +117,13 @@ pub(crate) fn type_expr(vars: &Relvars, expr: SqlExpr, expected: Option<&Algebra /// Is this type compatible with this binary operator? fn op_supports_type(_op: BinOp, t: &AlgebraicType) -> bool { - t.is_bool() || t.is_integer() || t.is_float() || t.is_string() || t.is_bytes() || t.is_identity() || t.is_address() + t.is_bool() + || t.is_integer() + || t.is_float() + || t.is_string() + || t.is_bytes() + || t.is_identity() + || t.is_connection_id() } /// Parse an integer literal into an [AlgebraicValue] @@ -176,10 +182,10 @@ pub(crate) fn parse(value: &str, ty: &AlgebraicType) -> anyhow::Result anyhow::Result Ok(AlgebraicValue::String(value.into())), t if t.is_bytes() => to_bytes(), t if t.is_identity() => to_identity(), - t if t.is_address() => to_address(), + t if t.is_connection_id() => to_connection_id(), t => bail!("Literal values for type {} are not supported", fmt_algebraic_type(t)), } } diff --git a/crates/lib/src/address.rs b/crates/lib/src/connection_id.rs similarity index 50% rename from crates/lib/src/address.rs rename to crates/lib/src/connection_id.rs index 4eaec6e5401..42527d49f2e 100644 --- a/crates/lib/src/address.rs +++ b/crates/lib/src/connection_id.rs @@ -5,86 +5,77 @@ use spacetimedb_lib::from_hex_pad; use spacetimedb_sats::hex::HexString; use spacetimedb_sats::{impl_deserialize, impl_serialize, impl_st, AlgebraicType, AlgebraicValue}; -/// This is the address for a SpacetimeDB database or client connection. -/// -/// TODO: This is wrong; the address can change, but the Identity cannot. -/// It is a unique identifier for a particular database and once set for a database, -/// does not change. +/// A unique identifier for a client connection to a SpacetimeDB database. /// /// This is a special type. /// -/// An `Address` is a 128-bit unsigned integer. This can be serialized in various ways. -/// - In JSON, an `Address` is represented as a BARE DECIMAL number. This requires some care when deserializing: -/// see https://stackoverflow.com/questions/69644298/how-to-make-json-parse-to-treat-all-the-numbers-as-bigint -/// - In BSATN, an `Address` is represented as a LITTLE-ENDIAN number 16 bytes long. -/// - In memory, an `Address` is stored as a 128-bit number with the endianness of the host system. -/// -/// If you are manually converting a hexadecimal string to a byte array like so: -/// ```ignore -/// "0xb0b1b2..." -/// -> -/// [0xb0, 0xb1, 0xb2, ...] -/// ``` -/// Make sure you call `Address::from_be_byte_array` and NOT `Address::from_byte_array`. -/// The standard way of writing hexadecimal numbers follows a big-endian convention, if you -/// index the characters in written text in increasing order from left to right. -// TODO: Evaluate other possible names: `DatabaseAddress`, `SPAddress` -// TODO: Evaluate replacing this with a literal Ipv6Address -// which is assigned permanently to a database. -// This is likely +/// A `ConnectionId` is a 128-bit unsigned integer. This can be serialized in various ways. +/// - In JSON, an `ConnectionId` is represented as a BARE DECIMAL number. +/// This requires some care when deserializing; see +/// [https://stackoverflow.com/questions/69644298/how-to-make-json-parse-to-treat-all-the-numbers-as-bigint] +/// - In BSATN, a `ConnectionId` is represented as a LITTLE-ENDIAN number 16 bytes long. +/// - In memory, a `ConnectionId` is stored as a 128-bit number with the endianness of the host system. +// +// If you are manually converting a hexadecimal string to a byte array like so: +// ```ignore +// "0xb0b1b2..." +// -> +// [0xb0, 0xb1, 0xb2, ...] +// ``` +// Make sure you call `ConnectionId::from_be_byte_array` and NOT `ConnectionId::from_le_byte_array`. +// The standard way of writing hexadecimal numbers follows a big-endian convention, if you +// index the characters in written text in increasing order from left to right. #[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)] -pub struct Address { - __address__: u128, +pub struct ConnectionId { + __connection_id__: u128, } -impl_st!([] Address, AlgebraicType::address()); +impl_st!([] ConnectionId, AlgebraicType::connection_id()); #[cfg(feature = "metrics_impls")] -impl spacetimedb_metrics::typed_prometheus::AsPrometheusLabel for Address { +impl spacetimedb_metrics::typed_prometheus::AsPrometheusLabel for ConnectionId { fn as_prometheus_str(&self) -> impl AsRef + '_ { self.to_hex() } } -impl Default for Address { - fn default() -> Self { - Self::ZERO - } -} - -impl fmt::Display for Address { +impl fmt::Display for ConnectionId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad(&self.to_hex()) } } -impl fmt::Debug for Address { +impl fmt::Debug for ConnectionId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_tuple("Address").field(&format_args!("{self}")).finish() + f.debug_tuple("ConnectionId").field(&format_args!("{self}")).finish() } } -impl Address { +impl ConnectionId { pub const ZERO: Self = Self::from_u128(0); - pub const fn from_u128(__address__: u128) -> Self { - Self { __address__ } + pub const fn from_u128(__connection_id__: u128) -> Self { + Self { __connection_id__ } } pub const fn to_u128(&self) -> u128 { - self.__address__ + self.__connection_id__ } - /// Create an `Address` from a LITTLE-ENDIAN byte array. + /// Create an `ConnectionId` from a little-endian byte array. /// - /// If you are parsing an `Address` from a string, you probably want `from_be_byte_array` instead. - pub const fn from_byte_array(arr: [u8; 16]) -> Self { + /// If you are parsing an `ConnectionId` from a string, + /// you probably want [`Self::from_be_byte_array`] instead. + /// But if you need to convert a hexadecimal string to a `ConnectionId`, + /// just use [`Self::from_hex`]. + pub const fn from_le_byte_array(arr: [u8; 16]) -> Self { Self::from_u128(u128::from_le_bytes(arr)) } - /// Create an `Address` from a BIG-ENDIAN byte array. + /// Create an `ConnectionId` from a big-endian byte array. /// - /// This method is the correct choice if you have converted the bytes of a hexadecimal-formatted `Address` + /// This method is the correct choice + /// if you have converted the bytes of a hexadecimal-formatted `ConnectionId` /// to a byte array in the following way: /// /// ```ignore @@ -92,46 +83,52 @@ impl Address { /// -> /// [0xb0, 0xb1, 0xb2, ...] /// ``` + /// + /// But if you need to convert a hexadecimal string to a `ConnectionId`, + /// just use [`Self::from_hex`]. pub const fn from_be_byte_array(arr: [u8; 16]) -> Self { Self::from_u128(u128::from_be_bytes(arr)) } - /// Convert an address to a LITTLE-ENDIAN byte array. - /// If you are converting to a hexadecimal string, use `as_be_byte_array` instead. - pub const fn as_byte_array(&self) -> [u8; 16] { - self.__address__.to_le_bytes() + /// Convert a `ConnectionId` to a little-endian byte array. + pub const fn as_le_byte_array(&self) -> [u8; 16] { + self.__connection_id__.to_le_bytes() } - /// Convert an address to a BIG-ENDIAN byte array. + /// Convert a `ConnectionId` to a big-endian byte array. + /// /// This is a format suitable for printing as a hexadecimal string. + /// But if you need to convert a `ConnectionId` to a hexadecimal string, + /// just use [`Self::to_hex`]. pub const fn as_be_byte_array(&self) -> [u8; 16] { - self.__address__.to_be_bytes() + self.__connection_id__.to_be_bytes() } + /// Parse a hexadecimal string into a `ConnectionId`. pub fn from_hex(hex: &str) -> Result { from_hex_pad::<[u8; 16], _>(hex) - .context("Addresses must be 32 hex characters (16 bytes) in length.") + .context("ConnectionIds must be 32 hex characters (16 bytes) in length.") .map(Self::from_be_byte_array) } - /// Convert this `Address` to a hexadecimal string. + /// Convert this `ConnectionId` to a hexadecimal string. pub fn to_hex(self) -> HexString<16> { spacetimedb_sats::hex::encode(&self.as_be_byte_array()) } - /// Extract the first 8 bytes of this `Address` as if it was stored in BIG-ENDIAN + /// Extract the first 8 bytes of this `ConnectionId` as if it was stored in big-endian /// format. (That is, the most significant bytes.) pub fn abbreviate(&self) -> [u8; 8] { self.as_be_byte_array()[..8].try_into().unwrap() } - /// Extract the first 16 characters of this `Address`'s hexadecimal representation. + /// Extract the first 16 characters of this `ConnectionId`'s hexadecimal representation. pub fn to_abbreviated_hex(self) -> HexString<8> { spacetimedb_sats::hex::encode(&self.abbreviate()) } - /// Create an `Address` from a slice, assumed to be in big-endian format. - pub fn from_slice(slice: impl AsRef<[u8]>) -> Self { + /// Create an `ConnectionId` from a slice, assumed to be in big-endian format. + pub fn from_be_slice(slice: impl AsRef<[u8]>) -> Self { let slice = slice.as_ref(); let mut dst = [0u8; 16]; dst.copy_from_slice(slice); @@ -139,7 +136,7 @@ impl Address { } pub fn to_ipv6(self) -> Ipv6Addr { - Ipv6Addr::from(self.__address__) + Ipv6Addr::from(self.__connection_id__) } #[allow(dead_code)] @@ -147,68 +144,65 @@ impl Address { self.to_ipv6().to_string() } - #[doc(hidden)] - pub const __DUMMY: Self = Self::ZERO; - pub fn none_if_zero(self) -> Option { (self != Self::ZERO).then_some(self) } } -impl From for Address { +impl From for ConnectionId { fn from(value: u128) -> Self { Self::from_u128(value) } } -impl From
for AlgebraicValue { - fn from(value: Address) -> Self { +impl From for AlgebraicValue { + fn from(value: ConnectionId) -> Self { AlgebraicValue::product([value.to_u128().into()]) } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct AddressForUrl(u128); +pub struct ConnectionIdForUrl(u128); -impl From
for AddressForUrl { - fn from(addr: Address) -> Self { - AddressForUrl(addr.to_u128()) +impl From for ConnectionIdForUrl { + fn from(addr: ConnectionId) -> Self { + ConnectionIdForUrl(addr.to_u128()) } } -impl From for Address { - fn from(addr: AddressForUrl) -> Self { - Address::from_u128(addr.0) +impl From for ConnectionId { + fn from(addr: ConnectionIdForUrl) -> Self { + ConnectionId::from_u128(addr.0) } } -impl_serialize!([] AddressForUrl, (self, ser) => self.0.serialize(ser)); -impl_deserialize!([] AddressForUrl, de => u128::deserialize(de).map(Self)); -impl_st!([] AddressForUrl, AlgebraicType::U128); +impl_serialize!([] ConnectionIdForUrl, (self, ser) => self.0.serialize(ser)); +impl_deserialize!([] ConnectionIdForUrl, de => u128::deserialize(de).map(Self)); +impl_st!([] ConnectionIdForUrl, AlgebraicType::U128); #[cfg(feature = "serde")] -impl serde::Serialize for AddressForUrl { +impl serde::Serialize for ConnectionIdForUrl { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, { - spacetimedb_sats::ser::serde::serialize_to(&Address::from(*self).as_be_byte_array(), serializer) + spacetimedb_sats::ser::serde::serialize_to(&ConnectionId::from(*self).as_be_byte_array(), serializer) } } #[cfg(feature = "serde")] -impl<'de> serde::Deserialize<'de> for AddressForUrl { +impl<'de> serde::Deserialize<'de> for ConnectionIdForUrl { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { let arr = spacetimedb_sats::de::serde::deserialize_from(deserializer)?; - Ok(Address::from_be_byte_array(arr).into()) + Ok(ConnectionId::from_be_byte_array(arr).into()) } } #[cfg(feature = "serde")] -impl serde::Serialize for Address { +impl serde::Serialize for ConnectionId { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, @@ -218,13 +212,13 @@ impl serde::Serialize for Address { } #[cfg(feature = "serde")] -impl<'de> serde::Deserialize<'de> for Address { +impl<'de> serde::Deserialize<'de> for ConnectionId { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { let arr = spacetimedb_sats::de::serde::deserialize_from(deserializer)?; - Ok(Address::from_be_byte_array(arr)) + Ok(ConnectionId::from_be_byte_array(arr)) } } @@ -237,17 +231,17 @@ mod tests { use spacetimedb_sats::GroundSpacetimeType as _; #[test] - fn address_json_serialization_big_endian() { - let addr = Address::from_be_byte_array([0xff, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]); + fn connection_id_json_serialization_big_endian() { + let conn_id = ConnectionId::from_be_byte_array([0xff, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]); - let hex = addr.to_hex(); + let hex = conn_id.to_hex(); assert!( hex.as_str().starts_with("ff01"), "expected {hex:?} to start with \"ff01\"" ); - let json1 = serde_json::to_string(&addr).unwrap(); - let json2 = serde_json::to_string(&AddressForUrl::from(addr)).unwrap(); + let json1 = serde_json::to_string(&conn_id).unwrap(); + let json2 = serde_json::to_string(&ConnectionIdForUrl::from(conn_id)).unwrap(); assert!( json1.contains(hex.as_str()), @@ -262,9 +256,9 @@ mod tests { // So we have an incompatibility between our formats here :/ // The implementation of serialization for `sats` types via `SerializeWrapper` just calls // the `serde` implementation to serialize primitives, so we can't fix this - // unless we make a custom implementation of `Serialize` and `Deserialize` for `Address`. - let decimal = addr.to_u128().to_string(); - let json3 = serde_json::to_string(SerializeWrapper::from_ref(&addr)).unwrap(); + // unless we make a custom implementation of `Serialize` and `Deserialize` for `ConnectionId`. + let decimal = conn_id.to_u128().to_string(); + let json3 = serde_json::to_string(SerializeWrapper::from_ref(&conn_id)).unwrap(); assert!( json3.contains(decimal.as_str()), "expected {json3} to contain {decimal} but it didn't" @@ -274,25 +268,25 @@ mod tests { proptest! { #[test] fn test_bsatn_roundtrip(val: u128) { - let addr = Address::from_u128(val); - let ser = bsatn::to_vec(&addr).unwrap(); + let conn_id = ConnectionId::from_u128(val); + let ser = bsatn::to_vec(&conn_id).unwrap(); let de = bsatn::from_slice(&ser).unwrap(); - assert_eq!(addr, de); + assert_eq!(conn_id, de); } #[test] - fn address_conversions(a: u128) { - let v = Address::from_u128(a); + fn connection_id_conversions(a: u128) { + let v = ConnectionId::from_u128(a); - prop_assert_eq!(Address::from_byte_array(v.as_byte_array()), v); - prop_assert_eq!(Address::from_be_byte_array(v.as_be_byte_array()), v); - prop_assert_eq!(Address::from_hex(v.to_hex().as_str()).unwrap(), v); + prop_assert_eq!(ConnectionId::from_le_byte_array(v.as_le_byte_array()), v); + prop_assert_eq!(ConnectionId::from_be_byte_array(v.as_be_byte_array()), v); + prop_assert_eq!(ConnectionId::from_hex(v.to_hex().as_str()).unwrap(), v); } } #[test] - fn address_is_special() { - assert!(Address::get_type().is_special()); + fn connection_id_is_special() { + assert!(ConnectionId::get_type().is_special()); } #[cfg(feature = "serde")] @@ -309,33 +303,33 @@ mod tests { /// in `test_serde_roundtrip`. #[test] fn test_wrapper_roundtrip(val: u128) { - let addr = Address::from_u128(val); - let wrapped = SerializeWrapper::new(&addr); + let conn_id = ConnectionId::from_u128(val); + let wrapped = SerializeWrapper::new(&conn_id); let ser = serde_json::to_string(&wrapped).unwrap(); let empty = Typespace::default(); - let address_ty = Address::get_type(); - let address_ty = WithTypespace::new(&empty, &address_ty); + let conn_id_ty = ConnectionId::get_type(); + let conn_id_ty = WithTypespace::new(&empty, &conn_id_ty); let row = serde_json::from_str::(&ser[..])?; let de = ::serde::de::DeserializeSeed::deserialize( crate::de::serde::SeedWrapper( - address_ty + conn_id_ty ), row)?; - let de = Address::deserialize(ValueDeserializer::new(de)).unwrap(); - prop_assert_eq!(addr, de); + let de = ConnectionId::deserialize(ValueDeserializer::new(de)).unwrap(); + prop_assert_eq!(conn_id, de); } } proptest! { #[test] fn test_serde_roundtrip(val: u128) { - let addr = Address::from_u128(val); - let to_url = AddressForUrl::from(addr); + let conn_id = ConnectionId::from_u128(val); + let to_url = ConnectionIdForUrl::from(conn_id); let ser = serde_json::to_vec(&to_url).unwrap(); - let de = serde_json::from_slice::(&ser).unwrap(); - let from_url = Address::from(de); - prop_assert_eq!(addr, from_url); + let de = serde_json::from_slice::(&ser).unwrap(); + let from_url = ConnectionId::from(de); + prop_assert_eq!(conn_id, from_url); } } } diff --git a/crates/lib/src/lib.rs b/crates/lib/src/lib.rs index 032aa330813..84d69312aca 100644 --- a/crates/lib/src/lib.rs +++ b/crates/lib/src/lib.rs @@ -6,7 +6,7 @@ use spacetimedb_sats::{impl_serialize, WithTypespace}; use std::any::TypeId; use std::collections::{btree_map, BTreeMap}; -pub mod address; +pub mod connection_id; pub mod db; pub mod error; pub mod identity; @@ -25,7 +25,7 @@ pub mod type_value { pub use spacetimedb_sats::{AlgebraicValue, ProductValue}; } -pub use address::Address; +pub use connection_id::ConnectionId; pub use identity::Identity; pub use scheduler::ScheduleAt; pub use spacetimedb_sats::hash::{self, hash_bytes, Hash}; diff --git a/crates/sats/src/algebraic_type.rs b/crates/sats/src/algebraic_type.rs index cff0b0ef6cd..15c740ecfe0 100644 --- a/crates/sats/src/algebraic_type.rs +++ b/crates/sats/src/algebraic_type.rs @@ -5,7 +5,7 @@ use crate::algebraic_value::de::{ValueDeserializeError, ValueDeserializer}; use crate::algebraic_value::ser::value_serialize; use crate::de::Deserialize; use crate::meta_type::MetaType; -use crate::product_type::{ADDRESS_TAG, IDENTITY_TAG, TIMESTAMP_TAG, TIME_DURATION_TAG}; +use crate::product_type::{CONNECTION_ID_TAG, IDENTITY_TAG, TIMESTAMP_TAG, TIME_DURATION_TAG}; use crate::sum_type::{OPTION_NONE_TAG, OPTION_SOME_TAG}; use crate::{i256, u256}; use crate::{AlgebraicTypeRef, AlgebraicValue, ArrayType, ProductType, SpacetimeType, SumType, SumTypeVariant}; @@ -160,9 +160,11 @@ impl AlgebraicType { /// The first type in the typespace. pub const ZERO_REF: Self = Self::Ref(AlgebraicTypeRef(0)); - /// Returns whether this type is the conventional address type. - pub fn is_address(&self) -> bool { - matches!(self, Self::Product(p) if p.is_address()) + /// Returns whether this type is the `ConnectionId` type. + /// + /// Construct an instance of this type with [`Self::connection_id`] + pub fn is_connection_id(&self) -> bool { + matches!(self, Self::Product(p) if p.is_connection_id()) } /// Returns whether this type is the conventional identity type. @@ -304,9 +306,9 @@ impl AlgebraicType { AlgebraicType::product([(IDENTITY_TAG, AlgebraicType::U256)]) } - /// Construct a copy of the `Address` type. - pub fn address() -> Self { - AlgebraicType::product([(ADDRESS_TAG, AlgebraicType::U128)]) + /// Construct a copy of the `ConnectionId` type. + pub fn connection_id() -> Self { + AlgebraicType::product([(CONNECTION_ID_TAG, AlgebraicType::U128)]) } /// Construct a copy of the point-in-time `Timestamp` type. @@ -689,8 +691,8 @@ mod tests { fn special_types_are_special() { assert!(AlgebraicType::identity().is_identity()); assert!(AlgebraicType::identity().is_special()); - assert!(AlgebraicType::address().is_address()); - assert!(AlgebraicType::address().is_special()); + assert!(AlgebraicType::connection_id().is_connection_id()); + assert!(AlgebraicType::connection_id().is_special()); assert!(AlgebraicType::timestamp().is_timestamp()); assert!(AlgebraicType::timestamp().is_special()); assert!(AlgebraicType::time_duration().is_special()); diff --git a/crates/sats/src/hex.rs b/crates/sats/src/hex.rs index 0fe2fa3862d..69515ed057a 100644 --- a/crates/sats/src/hex.rs +++ b/crates/sats/src/hex.rs @@ -1,7 +1,7 @@ //! Allocation-free hex formatting. //! //! Given that most, if not all, of the types that we hex-format are of constant byte size (Hash, -//! Address, Identity), this hex implementation lets you format to hex without needing to allocate +//! ConnectionId, Identity), this hex implementation lets you format to hex without needing to allocate //! a `String` on the heap. use core::{fmt, ops, str}; diff --git a/crates/sats/src/product_type.rs b/crates/sats/src/product_type.rs index 42a0fe31ae8..55e82f45578 100644 --- a/crates/sats/src/product_type.rs +++ b/crates/sats/src/product_type.rs @@ -9,8 +9,8 @@ use crate::{AlgebraicType, AlgebraicValue, ProductTypeElement, SpacetimeType, Va /// The tag used inside the special `Identity` product type. pub const IDENTITY_TAG: &str = "__identity__"; -/// The tag used inside the special `Address` product type. -pub const ADDRESS_TAG: &str = "__address__"; +/// The tag used inside the special `ConnectionId` product type. +pub const CONNECTION_ID_TAG: &str = "__connection_id__"; /// The tag used inside the special `Timestamp` product type. pub const TIMESTAMP_TAG: &str = "__timestamp_micros_since_unix_epoch__"; /// The tag used inside the special `TimeDuration` product type. @@ -91,10 +91,10 @@ impl ProductType { self.is_newtype(IDENTITY_TAG, |i| i.is_u256()) } - /// Returns whether this is the special case of `spacetimedb_lib::Address`. + /// Returns whether this is the special case of `spacetimedb_lib::ConnectionId`. /// Does not follow `Ref`s. - pub fn is_address(&self) -> bool { - self.is_newtype(ADDRESS_TAG, |i| i.is_u128()) + pub fn is_connection_id(&self) -> bool { + self.is_newtype(CONNECTION_ID_TAG, |i| i.is_u128()) } fn is_i64_newtype(&self, expected_tag: &str) -> bool { @@ -122,13 +122,13 @@ impl ProductType { /// Returns whether this is a special known `tag`, /// currently `Address`, `Identity`, `Timestamp` or `TimeDuration`. pub fn is_special_tag(tag_name: &str) -> bool { - [IDENTITY_TAG, ADDRESS_TAG, TIMESTAMP_TAG, TIME_DURATION_TAG].contains(&tag_name) + [IDENTITY_TAG, CONNECTION_ID_TAG, TIMESTAMP_TAG, TIME_DURATION_TAG].contains(&tag_name) } - /// Returns whether this is a special known type, currently `Address` or `Identity`. + /// Returns whether this is a special known type, currently `ConnectionId` or `Identity`. /// Does not follow `Ref`s. pub fn is_special(&self) -> bool { - self.is_identity() || self.is_address() || self.is_timestamp() || self.is_time_duration() + self.is_identity() || self.is_connection_id() || self.is_timestamp() || self.is_time_duration() } /// Returns whether this is a unit type, that is, has no elements. diff --git a/crates/sats/src/proptest.rs b/crates/sats/src/proptest.rs index 11f09aca2bc..0ede86ed136 100644 --- a/crates/sats/src/proptest.rs +++ b/crates/sats/src/proptest.rs @@ -235,7 +235,7 @@ fn generate_type_valid_for_client_use() -> impl Strategy let leaf = prop_oneof![ generate_non_compound_algebraic_type(), Just(AlgebraicType::identity()), - Just(AlgebraicType::address()), + Just(AlgebraicType::connection_id()), ]; let size = 3; diff --git a/crates/schema/src/type_for_generate.rs b/crates/schema/src/type_for_generate.rs index 40a14f9808a..8ebb5ee2db0 100644 --- a/crates/schema/src/type_for_generate.rs +++ b/crates/schema/src/type_for_generate.rs @@ -317,8 +317,8 @@ pub enum AlgebraicTypeUse { /// The special `Identity` type. Identity, - /// The special `Address` type. - Address, + /// The special `ConnectionId` type. + ConnectionId, /// The special `Timestamp` type. Timestamp, @@ -412,8 +412,8 @@ impl TypespaceForGenerateBuilder<'_> { /// Use the `TypespaceForGenerateBuilder` to validate an `AlgebraicTypeUse`. /// Does not actually add anything to the `TypespaceForGenerate`. pub fn parse_use(&mut self, ty: &AlgebraicType) -> Result { - if ty.is_address() { - Ok(AlgebraicTypeUse::Address) + if ty.is_connection_id() { + Ok(AlgebraicTypeUse::ConnectionId) } else if ty.is_identity() { Ok(AlgebraicTypeUse::Identity) } else if ty.is_timestamp() { diff --git a/crates/sdk/examples/quickstart-chat/module_bindings/mod.rs b/crates/sdk/examples/quickstart-chat/module_bindings/mod.rs index eca295918ec..36b70afada9 100644 --- a/crates/sdk/examples/quickstart-chat/module_bindings/mod.rs +++ b/crates/sdk/examples/quickstart-chat/module_bindings/mod.rs @@ -231,8 +231,8 @@ impl __sdk::DbContext for DbConnection { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } @@ -449,8 +449,8 @@ impl __sdk::DbContext for EventContext { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } @@ -525,8 +525,8 @@ impl __sdk::DbContext for ReducerEventContext { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } @@ -597,8 +597,8 @@ impl __sdk::DbContext for SubscriptionEventContext { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } @@ -673,8 +673,8 @@ impl __sdk::DbContext for ErrorContext { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } diff --git a/crates/sdk/src/db_connection.rs b/crates/sdk/src/db_connection.rs index bd1929229af..9482d2f1a66 100644 --- a/crates/sdk/src/db_connection.rs +++ b/crates/sdk/src/db_connection.rs @@ -35,7 +35,7 @@ use futures_channel::mpsc; use http::Uri; use spacetimedb_client_api_messages::websocket as ws; use spacetimedb_client_api_messages::websocket::{BsatnFormat, CallReducerFlags, Compression}; -use spacetimedb_lib::{bsatn, ser::Serialize, Address, Identity}; +use spacetimedb_lib::{bsatn, ser::Serialize, ConnectionId, Identity}; use std::{ collections::HashMap, sync::{atomic::AtomicU32, Arc, Mutex as StdMutex, OnceLock}, @@ -116,10 +116,10 @@ impl DbContextImpl { } // Initial `IdentityToken` message: - // confirm that the received identity and address are what we expect, + // confirm that the received identity and connection ID are what we expect, // store them, // then invoke the on_connect callback. - ParsedMessage::IdentityToken(identity, token, addr) => { + ParsedMessage::IdentityToken(identity, token, conn_id) => { { // Don't hold the `self.identity` lock while running callbacks. // Callbacks can (will) call [`DbContext::identity`], which acquires that lock, @@ -130,7 +130,7 @@ impl DbContextImpl { } *ident_store = Some(identity); } - assert_eq!(get_client_address(), addr); + assert_eq!(get_connection_id(), conn_id); let mut inner = self.inner.lock().unwrap(); if let Some(on_connect) = inner.on_connect.take() { let ctx = ::new(self.clone()); @@ -680,8 +680,8 @@ impl DbContextImpl { } /// Called by the autogenerated `DbConnection` method of the same name. - pub fn address(&self) -> Address { - get_client_address() + pub fn connection_id(&self) -> ConnectionId { + get_connection_id() } } @@ -755,30 +755,31 @@ pub struct DbConnectionBuilder { params: WsParams, } -/// This process's global client address, which will be attacked to all connections it makes. -static CLIENT_ADDRESS: OnceLock
= OnceLock::new(); +/// This process's global connection ID, which will be attacked to all connections it makes. +// TODO: rip this out. Make the connection id a property of the `DbConnection`. Cloud can supply it to the builder. +static CONNECTION_ID: OnceLock = OnceLock::new(); -fn get_client_address() -> Address { - *CLIENT_ADDRESS.get_or_init(|| Address::from_byte_array(rand::random())) +fn get_connection_id() -> ConnectionId { + *CONNECTION_ID.get_or_init(|| ConnectionId::from_le_byte_array(rand::random())) } #[doc(hidden)] -/// Attempt to set this process's client address to a known value. +/// Attempt to set this process's connection ID to a known value. /// /// This functionality is exposed for use in SpacetimeDB-cloud. /// It is unstable, and will be removed without warning in a future version. /// -/// Clients which want a particular client address must call this method +/// Clients which want a particular connection ID must call this method /// before constructing any connection. -/// Once any connection is constructed, the per-process client address value is locked in, +/// Once any connection is constructed, the per-process connection ID value is locked in, /// and cannot be overwritten. /// -/// Returns `Err` if this process's client address has already been initialized to a random value. -pub fn set_client_address(addr: Address) -> crate::Result<()> { - let stored = *CLIENT_ADDRESS.get_or_init(|| addr); - if stored != addr { +/// Returns `Err` if this process's connection ID has already been initialized to a random value. +pub fn set_connection_id(id: ConnectionId) -> crate::Result<()> { + let stored = *CONNECTION_ID.get_or_init(|| id); + if stored != id { return Err(InternalError::new( - "Call to set_client_address after CLIENT_ADDRESS was initialized to a different value ", + "Call to set_connection_id after CONNECTION_ID was initialized to a different value ", ) .into()); } @@ -843,7 +844,7 @@ but you must call one of them, or else the connection will never progress. self.uri.unwrap(), self.module_name.as_ref().unwrap(), self.token.as_deref(), - get_client_address(), + get_connection_id(), self.params, )) }) @@ -1019,7 +1020,7 @@ fn enter_or_create_runtime() -> crate::Result<(Option, runtime::Handle) enum ParsedMessage { InitialSubscription { db_update: M::DbUpdate, sub_id: u32 }, TransactionUpdate(Event, Option), - IdentityToken(Identity, Box, Address), + IdentityToken(Identity, Box, ConnectionId), SubscribeApplied { query_id: u32, initial_update: M::DbUpdate }, UnsubscribeApplied { query_id: u32, initial_update: M::DbUpdate }, SubscriptionError { query_id: Option, error: String }, @@ -1059,7 +1060,7 @@ async fn parse_loop( status, timestamp, caller_identity, - caller_address, + caller_connection_id, reducer_call, energy_quanta_used, .. @@ -1073,7 +1074,7 @@ async fn parse_loop( let event = M::Reducer::try_from(reducer_call) .map(|reducer| { Event::Reducer(ReducerEvent { - caller_address: caller_address.none_if_zero(), + caller_connection_id: caller_connection_id.none_if_zero(), caller_identity, energy_consumed: Some(energy_quanta_used.quanta), timestamp, @@ -1098,8 +1099,8 @@ async fn parse_loop( ws::ServerMessage::IdentityToken(ws::IdentityToken { identity, token, - address, - }) => ParsedMessage::IdentityToken(identity, token, address), + connection_id, + }) => ParsedMessage::IdentityToken(identity, token, connection_id), ws::ServerMessage::OneOffQueryResponse(_) => { unreachable!("The Rust SDK does not implement one-off queries") } diff --git a/crates/sdk/src/db_context.rs b/crates/sdk/src/db_context.rs index a6ea348b078..061d6ea1b7f 100644 --- a/crates/sdk/src/db_context.rs +++ b/crates/sdk/src/db_context.rs @@ -3,7 +3,7 @@ //! [`DbContext`] is implemented by `DbConnection` and `EventContext`, //! both defined in your module-specific codegen. -use crate::{Address, Identity}; +use crate::{ConnectionId, Identity}; pub trait DbContext { type DbView; @@ -65,9 +65,10 @@ pub trait DbContext { /// For a panicking version, see [`Self::identity`]. fn try_identity(&self) -> Option; - /// Get this connection's client [`Address`]. - /// - /// All connections opened by the same process will have the same [`Address`], - /// including connections to different modules. - fn address(&self) -> Address; + /// Get this connection's [`ConnectionId`]. + // Currently, all connections opened by the same process will have the same [`ConnectionId`], + // including connections to different modules. + // TODO: fix this. + // TODO: add `Self::try_connection_id`, for the same reason as `Self::try_identity`. + fn connection_id(&self) -> ConnectionId; } diff --git a/crates/sdk/src/event.rs b/crates/sdk/src/event.rs index f7d72eb9a97..8765de6aa1f 100644 --- a/crates/sdk/src/event.rs +++ b/crates/sdk/src/event.rs @@ -12,7 +12,7 @@ use crate::spacetime_module::{DbUpdate as _, SpacetimeModule}; use spacetimedb_client_api_messages::websocket as ws; -use spacetimedb_lib::{Address, Identity, Timestamp}; +use spacetimedb_lib::{ConnectionId, Identity, Timestamp}; #[non_exhaustive] #[derive(Debug, Clone)] @@ -69,9 +69,9 @@ pub struct ReducerEvent { /// The `Identity` of the SpacetimeDB actor which invoked the reducer. pub caller_identity: Identity, - /// The `Address` of the SpacetimeDB actor which invoked the reducer, - /// or `None` if the actor did not supply an address. - pub caller_address: Option
, + /// The [`ConnectionId`] of the SpacetimeDB actor which invoked the reducer, + /// or `None` for scheduled reducers. + pub caller_connection_id: Option, /// The amount of energy consumed by the reducer run, in eV. /// (Not literal eV, but our SpacetimeDB energy unit eV.) diff --git a/crates/sdk/src/lib.rs b/crates/sdk/src/lib.rs index 3d2653ec378..f9c8847a684 100644 --- a/crates/sdk/src/lib.rs +++ b/crates/sdk/src/lib.rs @@ -30,7 +30,7 @@ pub use event::{Event, ReducerEvent, Status}; pub use table::{Table, TableWithPrimaryKey}; pub use spacetime_module::SubscriptionHandle; -pub use spacetimedb_lib::{Address, Identity, ScheduleAt, TimeDuration, Timestamp}; +pub use spacetimedb_lib::{ConnectionId, Identity, ScheduleAt, TimeDuration, Timestamp}; pub use spacetimedb_sats::{i256, u256}; #[doc(hidden)] @@ -55,8 +55,8 @@ pub mod __codegen { }; pub use crate::subscription::{OnEndedCallback, SubscriptionBuilder, SubscriptionHandleImpl}; pub use crate::{ - Address, DbConnectionBuilder, DbContext, Event, Identity, ReducerEvent, ScheduleAt, Table, TableWithPrimaryKey, - TimeDuration, Timestamp, + ConnectionId, DbConnectionBuilder, DbContext, Event, Identity, ReducerEvent, ScheduleAt, Table, + TableWithPrimaryKey, TimeDuration, Timestamp, }; } @@ -65,6 +65,6 @@ pub mod unstable { //! Unstable interfaces not ready for the prime time. //! //! These may change incompatibly without a major version bump. - pub use crate::db_connection::set_client_address; + pub use crate::db_connection::set_connection_id; pub use spacetimedb_client_api_messages::websocket::CallReducerFlags; } diff --git a/crates/sdk/src/reducer.rs b/crates/sdk/src/reducer.rs deleted file mode 100644 index e6e2c3ad512..00000000000 --- a/crates/sdk/src/reducer.rs +++ /dev/null @@ -1,81 +0,0 @@ -use crate::callbacks::CallbackId; -use crate::global_connection::{with_connection, with_reducer_callbacks}; -use crate::identity::Identity; -use crate::Address; -use spacetimedb_client_api_messages::websocket::BsatnFormat; -use spacetimedb_sats::{de::DeserializeOwned, ser::Serialize}; -use std::any::Any; - -#[derive(Clone, PartialEq, Eq, Hash, Debug)] -pub enum Status { - Committed, - Failed(Box), - OutOfEnergy, -} - -impl Status { - pub(crate) fn from_update_status(status: &crate::ws_messages::UpdateStatus) -> Self { - match status { - crate::ws_messages::UpdateStatus::Committed(_) => Self::Committed, - crate::ws_messages::UpdateStatus::Failed(errmsg) => Self::Failed(errmsg.clone()), - crate::ws_messages::UpdateStatus::OutOfEnergy => Self::OutOfEnergy, - } - } -} - -#[derive(Copy, Clone)] -pub struct ReducerCallbackId { - id: CallbackId<(Identity, Option
, Status, R)>, -} - -// Any bound so these can be keys in an `AnyMap` to store callbacks. -/// A type representing a reducer. The type itself will hold the reducer's arguments. -/// -/// Types which implement `Reducer` autogenerated by the SpacetimeDB CLI's -/// `generate` command. Users should not `impl Reducer`. -pub trait Reducer: DeserializeOwned + Serialize + Any + Send + Sync + Clone { - const REDUCER_NAME: &'static str; - - fn invoke(self) -> crate::Result<()> { - with_connection(|conn| conn.invoke_reducer(self)) - } - - /// Register a callback to run after the reducer runs. - /// - // TODO: the cli should generate a more convenient function `on_{REDUCER_NAME}` for - // each reducer, whose callback accepts the reducer args unpacked, rather than - // an instance of `Self`. Make sure to document that it uses the same shared - // resource, so an `on_{REDUCER_NAME}` followed by a - // `{REDUCER_TYPE}::on_reducer` will overwrite the first callback. - // - /// The returned `ReducerCallbackId` can be passed to `remove_on_reducer` to - /// unregister the callback. - fn on_reducer( - callback: impl FnMut(&Identity, Option
, &Status, &Self) + Send + 'static, - ) -> ReducerCallbackId { - let id = with_reducer_callbacks(|callbacks| callbacks.register_on_reducer::(callback)); - ReducerCallbackId { id } - } - - /// Register a callback to run once after the reducer runs. - /// - /// The `callback` will run at most once, then unregister itself. - /// It can also be unregistered by passing the returned `ReducerCallbackId` - /// to `remove_on_reducer`. - fn once_on_reducer( - callback: impl FnOnce(&Identity, Option
, &Status, &Self) + Send + 'static, - ) -> ReducerCallbackId { - let id = with_reducer_callbacks(|callbacks| callbacks.register_on_reducer_oneshot::(callback)); - ReducerCallbackId { id } - } - - /// Unregister a previously-registered `on_reducer` callback. - /// - /// If `id` does not refer to a currently-registered callback, this operation will do - /// nothing. - fn remove_on_reducer(id: ReducerCallbackId) { - with_reducer_callbacks(|callbacks| callbacks.unregister_on_reducer::(id.id)); - } -} - -pub type AnyReducerEvent = dyn Any + Send + Sync; diff --git a/crates/sdk/src/websocket.rs b/crates/sdk/src/websocket.rs index db76a3490bd..7c6c56ae2dd 100644 --- a/crates/sdk/src/websocket.rs +++ b/crates/sdk/src/websocket.rs @@ -13,7 +13,7 @@ use spacetimedb_client_api_messages::websocket::{ SERVER_MSG_COMPRESSION_TAG_GZIP, SERVER_MSG_COMPRESSION_TAG_NONE, }; use spacetimedb_client_api_messages::websocket::{ClientMessage, ServerMessage}; -use spacetimedb_lib::{bsatn, Address}; +use spacetimedb_lib::{bsatn, ConnectionId}; use thiserror::Error; use tokio::task::JoinHandle; use tokio::{net::TcpStream, runtime}; @@ -105,7 +105,7 @@ pub(crate) struct WsParams { pub light: bool, } -fn make_uri(host: Uri, db_name: &str, client_address: Address, params: WsParams) -> Result { +fn make_uri(host: Uri, db_name: &str, connection_id: ConnectionId, params: WsParams) -> Result { let mut parts = host.into_parts(); let scheme = parse_scheme(parts.scheme.take())?; parts.scheme = Some(scheme); @@ -126,9 +126,9 @@ fn make_uri(host: Uri, db_name: &str, client_address: Address, params: WsParams) path.push_str("database/subscribe/"); path.push_str(db_name); - // Provide the client address. - path.push_str("?client_address="); - path.push_str(&client_address.to_hex()); + // Provide the connection ID. + path.push_str("?connection_id="); + path.push_str(&connection_id.to_hex()); // Specify the desired compression for host->client replies. match params.compression { @@ -165,10 +165,10 @@ fn make_request( host: Uri, db_name: &str, token: Option<&str>, - client_address: Address, + connection_id: ConnectionId, params: WsParams, ) -> Result, WsError> { - let uri = make_uri(host, db_name, client_address, params)?; + let uri = make_uri(host, db_name, connection_id, params)?; let mut req = IntoClientRequest::into_client_request(uri.clone()).map_err(|source| WsError::Tungstenite { uri, source: Arc::new(source), @@ -219,10 +219,10 @@ impl WsConnection { host: Uri, db_name: &str, token: Option<&str>, - client_address: Address, + connection_id: ConnectionId, params: WsParams, ) -> Result { - let req = make_request(host, db_name, token, client_address, params)?; + let req = make_request(host, db_name, token, connection_id, params)?; // Grab the URI for error-reporting. let uri = req.uri().clone(); diff --git a/crates/sdk/tests/connect_disconnect_client/src/module_bindings/mod.rs b/crates/sdk/tests/connect_disconnect_client/src/module_bindings/mod.rs index d360efee974..dbe8f3b1102 100644 --- a/crates/sdk/tests/connect_disconnect_client/src/module_bindings/mod.rs +++ b/crates/sdk/tests/connect_disconnect_client/src/module_bindings/mod.rs @@ -215,8 +215,8 @@ impl __sdk::DbContext for DbConnection { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } @@ -433,8 +433,8 @@ impl __sdk::DbContext for EventContext { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } @@ -509,8 +509,8 @@ impl __sdk::DbContext for ReducerEventContext { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } @@ -581,8 +581,8 @@ impl __sdk::DbContext for SubscriptionEventContext { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } @@ -657,8 +657,8 @@ impl __sdk::DbContext for ErrorContext { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } diff --git a/crates/sdk/tests/test-client/src/main.rs b/crates/sdk/tests/test-client/src/main.rs index 2f57758c5c9..9f3eef35fc2 100644 --- a/crates/sdk/tests/test-client/src/main.rs +++ b/crates/sdk/tests/test-client/src/main.rs @@ -8,7 +8,7 @@ use std::sync::{atomic::AtomicUsize, Arc, Mutex}; use module_bindings::*; use spacetimedb_sdk::{ - credentials, i256, u256, unstable::CallReducerFlags, Address, DbConnectionBuilder, DbContext, Error, Event, + credentials, i256, u256, unstable::CallReducerFlags, ConnectionId, DbConnectionBuilder, DbContext, Error, Event, Identity, ReducerEvent, Status, SubscriptionHandle, Table, TimeDuration, Timestamp, }; use test_counter::TestCounter; @@ -81,10 +81,10 @@ fn main() { "delete_identity" => exec_delete_identity(), "update_identity" => exec_update_identity(), - "insert_address" => exec_insert_address(), - "insert_caller_address" => exec_insert_caller_address(), - "delete_address" => exec_delete_address(), - "update_address" => exec_update_address(), + "insert_connection_id" => exec_insert_connection_id(), + "insert_caller_connection_id" => exec_insert_caller_connection_id(), + "delete_connection_id" => exec_delete_connection_id(), + "update_connection_id" => exec_update_connection_id(), "insert_timestamp" => exec_insert_timestamp(), "insert_call_timestamp" => exec_insert_call_timestamp(), @@ -110,7 +110,7 @@ fn main() { "should_fail" => exec_should_fail(), - "reconnect_same_address" => exec_reconnect_same_address(), + "reconnect_same_connection_id" => exec_reconnect_same_connection_id(), "caller_always_notified" => exec_caller_always_notified(), "subscribe_all_select_star" => exec_subscribe_all_select_star(), @@ -158,7 +158,7 @@ fn assert_all_tables_empty(ctx: &impl RemoteDbContext) -> anyhow::Result<()> { assert_table_empty(ctx.db().one_string())?; assert_table_empty(ctx.db().one_identity())?; - assert_table_empty(ctx.db().one_address())?; + assert_table_empty(ctx.db().one_connection_id())?; assert_table_empty(ctx.db().one_timestamp())?; @@ -191,7 +191,7 @@ fn assert_all_tables_empty(ctx: &impl RemoteDbContext) -> anyhow::Result<()> { assert_table_empty(ctx.db().vec_string())?; assert_table_empty(ctx.db().vec_identity())?; - assert_table_empty(ctx.db().vec_address())?; + assert_table_empty(ctx.db().vec_connection_id())?; assert_table_empty(ctx.db().vec_timestamp())?; @@ -228,7 +228,7 @@ fn assert_all_tables_empty(ctx: &impl RemoteDbContext) -> anyhow::Result<()> { assert_table_empty(ctx.db().unique_string())?; assert_table_empty(ctx.db().unique_identity())?; - assert_table_empty(ctx.db().unique_address())?; + assert_table_empty(ctx.db().unique_connection_id())?; assert_table_empty(ctx.db().pk_u_8())?; assert_table_empty(ctx.db().pk_u_16())?; @@ -248,7 +248,7 @@ fn assert_all_tables_empty(ctx: &impl RemoteDbContext) -> anyhow::Result<()> { assert_table_empty(ctx.db().pk_string())?; assert_table_empty(ctx.db().pk_identity())?; - assert_table_empty(ctx.db().pk_address())?; + assert_table_empty(ctx.db().pk_connection_id())?; assert_table_empty(ctx.db().large_table())?; @@ -276,7 +276,7 @@ const SUBSCRIBE_ALL: &[&str] = &[ "SELECT * FROM one_f64;", "SELECT * FROM one_string;", "SELECT * FROM one_identity;", - "SELECT * FROM one_address;", + "SELECT * FROM one_connection_id;", "SELECT * FROM one_timestamp;", "SELECT * FROM one_simple_enum;", "SELECT * FROM one_enum_with_payload;", @@ -301,7 +301,7 @@ const SUBSCRIBE_ALL: &[&str] = &[ "SELECT * FROM vec_f64;", "SELECT * FROM vec_string;", "SELECT * FROM vec_identity;", - "SELECT * FROM vec_address;", + "SELECT * FROM vec_connection_id;", "SELECT * FROM vec_timestamp;", "SELECT * FROM vec_simple_enum;", "SELECT * FROM vec_enum_with_payload;", @@ -330,7 +330,7 @@ const SUBSCRIBE_ALL: &[&str] = &[ "SELECT * FROM unique_bool;", "SELECT * FROM unique_string;", "SELECT * FROM unique_identity;", - "SELECT * FROM unique_address;", + "SELECT * FROM unique_connection_id;", "SELECT * FROM pk_u8;", "SELECT * FROM pk_u16;", "SELECT * FROM pk_u32;", @@ -346,7 +346,7 @@ const SUBSCRIBE_ALL: &[&str] = &[ "SELECT * FROM pk_bool;", "SELECT * FROM pk_string;", "SELECT * FROM pk_identity;", - "SELECT * FROM pk_address;", + "SELECT * FROM pk_connection_id;", "SELECT * FROM large_table;", "SELECT * FROM table_holds_table;", ]; @@ -691,8 +691,8 @@ fn exec_update_identity() { assert_all_tables_empty(&connection).unwrap(); } -/// This tests that we can serialize and deserialize `Address` in various contexts. -fn exec_insert_address() { +/// This tests that we can serialize and deserialize `ConnectionId` in various contexts. +fn exec_insert_connection_id() { let test_counter = TestCounter::new(); let sub_applied_nothing_result = test_counter.add_test("on_subscription_applied_nothing"); @@ -700,7 +700,7 @@ fn exec_insert_address() { let test_counter = test_counter.clone(); move |ctx| { subscribe_all_then(ctx, move |ctx| { - insert_one::(ctx, &test_counter, ctx.address()); + insert_one::(ctx, &test_counter, ctx.connection_id()); sub_applied_nothing_result(assert_all_tables_empty(ctx)); }); @@ -710,8 +710,8 @@ fn exec_insert_address() { test_counter.wait_for_all(); } -/// This tests that we can serialize and deserialize `Address` in various contexts. -fn exec_insert_caller_address() { +/// This tests that we can serialize and deserialize `ConnectionId` in various contexts. +fn exec_insert_caller_connection_id() { let test_counter = TestCounter::new(); let sub_applied_nothing_result = test_counter.add_test("on_subscription_applied_nothing"); @@ -719,10 +719,10 @@ fn exec_insert_caller_address() { let test_counter = test_counter.clone(); move |ctx| { subscribe_all_then(ctx, move |ctx| { - on_insert_one::(ctx, &test_counter, ctx.address(), |event| { - matches!(event, Reducer::InsertCallerOneAddress) + on_insert_one::(ctx, &test_counter, ctx.connection_id(), |event| { + matches!(event, Reducer::InsertCallerOneConnectionId) }); - ctx.reducers.insert_caller_one_address().unwrap(); + ctx.reducers.insert_caller_one_connection_id().unwrap(); sub_applied_nothing_result(assert_all_tables_empty(ctx)); }); } @@ -731,9 +731,9 @@ fn exec_insert_caller_address() { test_counter.wait_for_all(); } -/// This test doesn't add much alongside `exec_insert_address` and `exec_delete_primitive`, +/// This test doesn't add much alongside `exec_insert_connection_id` and `exec_delete_primitive`, /// but it's here for symmetry. -fn exec_delete_address() { +fn exec_delete_connection_id() { let test_counter = TestCounter::new(); let sub_applied_nothing_result = test_counter.add_test("on_subscription_applied_nothing"); @@ -741,7 +741,7 @@ fn exec_delete_address() { let test_counter = test_counter.clone(); move |ctx| { subscribe_all_then(ctx, move |ctx| { - insert_then_delete_one::(ctx, &test_counter, ctx.address(), 0xbeef); + insert_then_delete_one::(ctx, &test_counter, ctx.connection_id(), 0xbeef); sub_applied_nothing_result(assert_all_tables_empty(ctx)); }); @@ -754,8 +754,8 @@ fn exec_delete_address() { } /// This tests that we can distinguish between `on_delete` and `on_update` events -/// for tables with `Address` primary keys. -fn exec_update_address() { +/// for tables with `ConnectionId` primary keys. +fn exec_update_connection_id() { let test_counter = TestCounter::new(); let sub_applied_nothing_result = test_counter.add_test("on_subscription_applied_nothing"); @@ -764,10 +764,10 @@ fn exec_update_address() { subscribe_all_then(&connection, { let test_counter = test_counter.clone(); move |ctx| { - insert_update_delete_one::( + insert_update_delete_one::( ctx, &test_counter, - Address::default(), // connection.address().unwrap(), + ConnectionId::ZERO, // connection.connection_id().unwrap(), 0xbeef, 0xbabe, ); @@ -820,11 +820,11 @@ fn exec_insert_call_timestamp() { reducer_event.caller_identity, ); } - if reducer_event.caller_address != Some(ctx.address()) { + if reducer_event.caller_connection_id != Some(ctx.connection_id()) { anyhow::bail!( - "Expected caller_address to be my own address {:?}, but found {:?}", - ctx.address(), - reducer_event.caller_address, + "Expected caller_connection_id to be my own connection_id {:?}, but found {:?}", + ctx.connection_id(), + reducer_event.caller_connection_id, ) } if !matches!(reducer_event.status, Status::Committed) { @@ -877,11 +877,11 @@ fn exec_on_reducer() { ctx.event.caller_identity, ); } - if ctx.event.caller_address != Some(ctx.address()) { + if ctx.event.caller_connection_id != Some(ctx.connection_id()) { anyhow::bail!( - "Expected caller_address to be my own address {:?}, but found {:?}", - ctx.address(), - ctx.event.caller_address, + "Expected caller_connection_id to be my own connection_id {:?}, but found {:?}", + ctx.connection_id(), + ctx.event.caller_connection_id, ) } if !matches!(ctx.event.status, Status::Committed) { @@ -954,11 +954,11 @@ fn exec_fail_reducer() { ctx.event.caller_identity, ); } - if ctx.event.caller_address != Some(ctx.address()) { + if ctx.event.caller_connection_id != Some(ctx.connection_id()) { anyhow::bail!( - "Expected caller_address to be my own address {:?}, but found {:?}", - ctx.address(), - ctx.event.caller_address, + "Expected caller_connection_id to be my own connection_id {:?}, but found {:?}", + ctx.connection_id(), + ctx.event.caller_connection_id, ) } if !matches!(ctx.event.status, Status::Committed) { @@ -1014,11 +1014,11 @@ fn exec_fail_reducer() { ctx.event.caller_identity, ); } - if ctx.event.caller_address != Some(ctx.address()) { + if ctx.event.caller_connection_id != Some(ctx.connection_id()) { anyhow::bail!( - "Expected caller_address to be my own address {:?}, but found {:?}", - ctx.address(), - ctx.event.caller_address, + "Expected caller_connection_id to be my own connection_id {:?}, but found {:?}", + ctx.connection_id(), + ctx.event.caller_connection_id, ) } if !matches!(ctx.event.status, Status::Failed(_)) { @@ -1095,7 +1095,7 @@ fn exec_insert_vec() { insert_one::(ctx, &test_counter, vec!["zero".to_string(), "one".to_string()]); insert_one::(ctx, &test_counter, vec![ctx.identity()]); - insert_one::(ctx, &test_counter, vec![ctx.address()]); + insert_one::(ctx, &test_counter, vec![ctx.connection_id()]); insert_one::(ctx, &test_counter, vec![Timestamp::now()]); @@ -1134,7 +1134,7 @@ fn every_primitive_struct() -> EveryPrimitiveStruct { o: -1.0, p: "string".to_string(), q: Identity::__dummy(), - r: Address::default(), + r: ConnectionId::ZERO, s: Timestamp::from_micros_since_unix_epoch(9876543210), t: TimeDuration::from_micros(-67_419_000_000_003), } @@ -1159,7 +1159,7 @@ fn every_vec_struct() -> EveryVecStruct { o: vec![0.0, -0.5, 0.5, -1.5, 1.5], p: ["vec", "of", "strings"].into_iter().map(str::to_string).collect(), q: vec![Identity::__dummy()], - r: vec![Address::default()], + r: vec![ConnectionId::ZERO], s: vec![Timestamp::from_micros_since_unix_epoch(9876543210)], t: vec![TimeDuration::from_micros(-67_419_000_000_003)], } @@ -1699,7 +1699,7 @@ fn exec_reauth_part_2() { test_counter.wait_for_all(); } -fn exec_reconnect_same_address() { +fn exec_reconnect_same_connection_id() { let initial_test_counter = TestCounter::new(); let initial_connect_result = initial_test_counter.add_test("connect"); @@ -1724,7 +1724,7 @@ fn exec_reconnect_same_address() { initial_test_counter.wait_for_all(); - let my_address = initial_connection.address(); + let my_connection_id = initial_connection.connection_id(); initial_connection.disconnect().unwrap(); @@ -1741,7 +1741,7 @@ fn exec_reconnect_same_address() { .on_connect(move |ctx, _, _| { reconnect_result(Ok(())); let run_checks = || { - anyhow::ensure!(ctx.address() == my_address); + anyhow::ensure!(ctx.connection_id() == my_connection_id); Ok(()) }; addr_after_reconnect_result(run_checks()); diff --git a/crates/sdk/tests/test-client/src/module_bindings/delete_pk_address_reducer.rs b/crates/sdk/tests/test-client/src/module_bindings/delete_pk_address_reducer.rs deleted file mode 100644 index 92ff7fa681e..00000000000 --- a/crates/sdk/tests/test-client/src/module_bindings/delete_pk_address_reducer.rs +++ /dev/null @@ -1,101 +0,0 @@ -// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. - -#![allow(unused, clippy::all)] -use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; - -#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] -#[sats(crate = __lib)] -pub(super) struct DeletePkAddressArgs { - pub a: __sdk::Address, -} - -impl From for super::Reducer { - fn from(args: DeletePkAddressArgs) -> Self { - Self::DeletePkAddress { a: args.a } - } -} - -impl __sdk::InModule for DeletePkAddressArgs { - type Module = super::RemoteModule; -} - -pub struct DeletePkAddressCallbackId(__sdk::CallbackId); - -#[allow(non_camel_case_types)] -/// Extension trait for access to the reducer `delete_pk_address`. -/// -/// Implemented for [`super::RemoteReducers`]. -pub trait delete_pk_address { - /// Request that the remote module invoke the reducer `delete_pk_address` to run as soon as possible. - /// - /// This method returns immediately, and errors only if we are unable to send the request. - /// The reducer will run asynchronously in the future, - /// and its status can be observed by listening for [`Self::on_delete_pk_address`] callbacks. - fn delete_pk_address(&self, a: __sdk::Address) -> __sdk::Result<()>; - /// Register a callback to run whenever we are notified of an invocation of the reducer `delete_pk_address`. - /// - /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] - /// to determine the reducer's status. - /// - /// The returned [`DeletePkAddressCallbackId`] can be passed to [`Self::remove_on_delete_pk_address`] - /// to cancel the callback. - fn on_delete_pk_address( - &self, - callback: impl FnMut(&super::ReducerEventContext, &__sdk::Address) + Send + 'static, - ) -> DeletePkAddressCallbackId; - /// Cancel a callback previously registered by [`Self::on_delete_pk_address`], - /// causing it not to run in the future. - fn remove_on_delete_pk_address(&self, callback: DeletePkAddressCallbackId); -} - -impl delete_pk_address for super::RemoteReducers { - fn delete_pk_address(&self, a: __sdk::Address) -> __sdk::Result<()> { - self.imp.call_reducer("delete_pk_address", DeletePkAddressArgs { a }) - } - fn on_delete_pk_address( - &self, - mut callback: impl FnMut(&super::ReducerEventContext, &__sdk::Address) + Send + 'static, - ) -> DeletePkAddressCallbackId { - DeletePkAddressCallbackId(self.imp.on_reducer( - "delete_pk_address", - Box::new(move |ctx: &super::ReducerEventContext| { - let super::ReducerEventContext { - event: - __sdk::ReducerEvent { - reducer: super::Reducer::DeletePkAddress { a }, - .. - }, - .. - } = ctx - else { - unreachable!() - }; - callback(ctx, a) - }), - )) - } - fn remove_on_delete_pk_address(&self, callback: DeletePkAddressCallbackId) { - self.imp.remove_on_reducer("delete_pk_address", callback.0) - } -} - -#[allow(non_camel_case_types)] -#[doc(hidden)] -/// Extension trait for setting the call-flags for the reducer `delete_pk_address`. -/// -/// Implemented for [`super::SetReducerFlags`]. -/// -/// This type is currently unstable and may be removed without a major version bump. -pub trait set_flags_for_delete_pk_address { - /// Set the call-reducer flags for the reducer `delete_pk_address` to `flags`. - /// - /// This type is currently unstable and may be removed without a major version bump. - fn delete_pk_address(&self, flags: __ws::CallReducerFlags); -} - -impl set_flags_for_delete_pk_address for super::SetReducerFlags { - fn delete_pk_address(&self, flags: __ws::CallReducerFlags) { - self.imp.set_call_reducer_flags("delete_pk_address", flags); - } -} diff --git a/crates/sdk/tests/test-client/src/module_bindings/delete_pk_connection_id_reducer.rs b/crates/sdk/tests/test-client/src/module_bindings/delete_pk_connection_id_reducer.rs new file mode 100644 index 00000000000..068ba3462ae --- /dev/null +++ b/crates/sdk/tests/test-client/src/module_bindings/delete_pk_connection_id_reducer.rs @@ -0,0 +1,102 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#![allow(unused, clippy::all)] +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] +#[sats(crate = __lib)] +pub(super) struct DeletePkConnectionIdArgs { + pub a: __sdk::ConnectionId, +} + +impl From for super::Reducer { + fn from(args: DeletePkConnectionIdArgs) -> Self { + Self::DeletePkConnectionId { a: args.a } + } +} + +impl __sdk::InModule for DeletePkConnectionIdArgs { + type Module = super::RemoteModule; +} + +pub struct DeletePkConnectionIdCallbackId(__sdk::CallbackId); + +#[allow(non_camel_case_types)] +/// Extension trait for access to the reducer `delete_pk_connection_id`. +/// +/// Implemented for [`super::RemoteReducers`]. +pub trait delete_pk_connection_id { + /// Request that the remote module invoke the reducer `delete_pk_connection_id` to run as soon as possible. + /// + /// This method returns immediately, and errors only if we are unable to send the request. + /// The reducer will run asynchronously in the future, + /// and its status can be observed by listening for [`Self::on_delete_pk_connection_id`] callbacks. + fn delete_pk_connection_id(&self, a: __sdk::ConnectionId) -> __sdk::Result<()>; + /// Register a callback to run whenever we are notified of an invocation of the reducer `delete_pk_connection_id`. + /// + /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] + /// to determine the reducer's status. + /// + /// The returned [`DeletePkConnectionIdCallbackId`] can be passed to [`Self::remove_on_delete_pk_connection_id`] + /// to cancel the callback. + fn on_delete_pk_connection_id( + &self, + callback: impl FnMut(&super::ReducerEventContext, &__sdk::ConnectionId) + Send + 'static, + ) -> DeletePkConnectionIdCallbackId; + /// Cancel a callback previously registered by [`Self::on_delete_pk_connection_id`], + /// causing it not to run in the future. + fn remove_on_delete_pk_connection_id(&self, callback: DeletePkConnectionIdCallbackId); +} + +impl delete_pk_connection_id for super::RemoteReducers { + fn delete_pk_connection_id(&self, a: __sdk::ConnectionId) -> __sdk::Result<()> { + self.imp + .call_reducer("delete_pk_connection_id", DeletePkConnectionIdArgs { a }) + } + fn on_delete_pk_connection_id( + &self, + mut callback: impl FnMut(&super::ReducerEventContext, &__sdk::ConnectionId) + Send + 'static, + ) -> DeletePkConnectionIdCallbackId { + DeletePkConnectionIdCallbackId(self.imp.on_reducer( + "delete_pk_connection_id", + Box::new(move |ctx: &super::ReducerEventContext| { + let super::ReducerEventContext { + event: + __sdk::ReducerEvent { + reducer: super::Reducer::DeletePkConnectionId { a }, + .. + }, + .. + } = ctx + else { + unreachable!() + }; + callback(ctx, a) + }), + )) + } + fn remove_on_delete_pk_connection_id(&self, callback: DeletePkConnectionIdCallbackId) { + self.imp.remove_on_reducer("delete_pk_connection_id", callback.0) + } +} + +#[allow(non_camel_case_types)] +#[doc(hidden)] +/// Extension trait for setting the call-flags for the reducer `delete_pk_connection_id`. +/// +/// Implemented for [`super::SetReducerFlags`]. +/// +/// This type is currently unstable and may be removed without a major version bump. +pub trait set_flags_for_delete_pk_connection_id { + /// Set the call-reducer flags for the reducer `delete_pk_connection_id` to `flags`. + /// + /// This type is currently unstable and may be removed without a major version bump. + fn delete_pk_connection_id(&self, flags: __ws::CallReducerFlags); +} + +impl set_flags_for_delete_pk_connection_id for super::SetReducerFlags { + fn delete_pk_connection_id(&self, flags: __ws::CallReducerFlags) { + self.imp.set_call_reducer_flags("delete_pk_connection_id", flags); + } +} diff --git a/crates/sdk/tests/test-client/src/module_bindings/delete_unique_address_reducer.rs b/crates/sdk/tests/test-client/src/module_bindings/delete_unique_connection_id_reducer.rs similarity index 50% rename from crates/sdk/tests/test-client/src/module_bindings/delete_unique_address_reducer.rs rename to crates/sdk/tests/test-client/src/module_bindings/delete_unique_connection_id_reducer.rs index d4be0408756..abe1da6059b 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/delete_unique_address_reducer.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/delete_unique_connection_id_reducer.rs @@ -6,65 +6,65 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; #[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] #[sats(crate = __lib)] -pub(super) struct DeleteUniqueAddressArgs { - pub a: __sdk::Address, +pub(super) struct DeleteUniqueConnectionIdArgs { + pub a: __sdk::ConnectionId, } -impl From for super::Reducer { - fn from(args: DeleteUniqueAddressArgs) -> Self { - Self::DeleteUniqueAddress { a: args.a } +impl From for super::Reducer { + fn from(args: DeleteUniqueConnectionIdArgs) -> Self { + Self::DeleteUniqueConnectionId { a: args.a } } } -impl __sdk::InModule for DeleteUniqueAddressArgs { +impl __sdk::InModule for DeleteUniqueConnectionIdArgs { type Module = super::RemoteModule; } -pub struct DeleteUniqueAddressCallbackId(__sdk::CallbackId); +pub struct DeleteUniqueConnectionIdCallbackId(__sdk::CallbackId); #[allow(non_camel_case_types)] -/// Extension trait for access to the reducer `delete_unique_address`. +/// Extension trait for access to the reducer `delete_unique_connection_id`. /// /// Implemented for [`super::RemoteReducers`]. -pub trait delete_unique_address { - /// Request that the remote module invoke the reducer `delete_unique_address` to run as soon as possible. +pub trait delete_unique_connection_id { + /// Request that the remote module invoke the reducer `delete_unique_connection_id` to run as soon as possible. /// /// This method returns immediately, and errors only if we are unable to send the request. /// The reducer will run asynchronously in the future, - /// and its status can be observed by listening for [`Self::on_delete_unique_address`] callbacks. - fn delete_unique_address(&self, a: __sdk::Address) -> __sdk::Result<()>; - /// Register a callback to run whenever we are notified of an invocation of the reducer `delete_unique_address`. + /// and its status can be observed by listening for [`Self::on_delete_unique_connection_id`] callbacks. + fn delete_unique_connection_id(&self, a: __sdk::ConnectionId) -> __sdk::Result<()>; + /// Register a callback to run whenever we are notified of an invocation of the reducer `delete_unique_connection_id`. /// /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] /// to determine the reducer's status. /// - /// The returned [`DeleteUniqueAddressCallbackId`] can be passed to [`Self::remove_on_delete_unique_address`] + /// The returned [`DeleteUniqueConnectionIdCallbackId`] can be passed to [`Self::remove_on_delete_unique_connection_id`] /// to cancel the callback. - fn on_delete_unique_address( + fn on_delete_unique_connection_id( &self, - callback: impl FnMut(&super::ReducerEventContext, &__sdk::Address) + Send + 'static, - ) -> DeleteUniqueAddressCallbackId; - /// Cancel a callback previously registered by [`Self::on_delete_unique_address`], + callback: impl FnMut(&super::ReducerEventContext, &__sdk::ConnectionId) + Send + 'static, + ) -> DeleteUniqueConnectionIdCallbackId; + /// Cancel a callback previously registered by [`Self::on_delete_unique_connection_id`], /// causing it not to run in the future. - fn remove_on_delete_unique_address(&self, callback: DeleteUniqueAddressCallbackId); + fn remove_on_delete_unique_connection_id(&self, callback: DeleteUniqueConnectionIdCallbackId); } -impl delete_unique_address for super::RemoteReducers { - fn delete_unique_address(&self, a: __sdk::Address) -> __sdk::Result<()> { +impl delete_unique_connection_id for super::RemoteReducers { + fn delete_unique_connection_id(&self, a: __sdk::ConnectionId) -> __sdk::Result<()> { self.imp - .call_reducer("delete_unique_address", DeleteUniqueAddressArgs { a }) + .call_reducer("delete_unique_connection_id", DeleteUniqueConnectionIdArgs { a }) } - fn on_delete_unique_address( + fn on_delete_unique_connection_id( &self, - mut callback: impl FnMut(&super::ReducerEventContext, &__sdk::Address) + Send + 'static, - ) -> DeleteUniqueAddressCallbackId { - DeleteUniqueAddressCallbackId(self.imp.on_reducer( - "delete_unique_address", + mut callback: impl FnMut(&super::ReducerEventContext, &__sdk::ConnectionId) + Send + 'static, + ) -> DeleteUniqueConnectionIdCallbackId { + DeleteUniqueConnectionIdCallbackId(self.imp.on_reducer( + "delete_unique_connection_id", Box::new(move |ctx: &super::ReducerEventContext| { let super::ReducerEventContext { event: __sdk::ReducerEvent { - reducer: super::Reducer::DeleteUniqueAddress { a }, + reducer: super::Reducer::DeleteUniqueConnectionId { a }, .. }, .. @@ -76,27 +76,27 @@ impl delete_unique_address for super::RemoteReducers { }), )) } - fn remove_on_delete_unique_address(&self, callback: DeleteUniqueAddressCallbackId) { - self.imp.remove_on_reducer("delete_unique_address", callback.0) + fn remove_on_delete_unique_connection_id(&self, callback: DeleteUniqueConnectionIdCallbackId) { + self.imp.remove_on_reducer("delete_unique_connection_id", callback.0) } } #[allow(non_camel_case_types)] #[doc(hidden)] -/// Extension trait for setting the call-flags for the reducer `delete_unique_address`. +/// Extension trait for setting the call-flags for the reducer `delete_unique_connection_id`. /// /// Implemented for [`super::SetReducerFlags`]. /// /// This type is currently unstable and may be removed without a major version bump. -pub trait set_flags_for_delete_unique_address { - /// Set the call-reducer flags for the reducer `delete_unique_address` to `flags`. +pub trait set_flags_for_delete_unique_connection_id { + /// Set the call-reducer flags for the reducer `delete_unique_connection_id` to `flags`. /// /// This type is currently unstable and may be removed without a major version bump. - fn delete_unique_address(&self, flags: __ws::CallReducerFlags); + fn delete_unique_connection_id(&self, flags: __ws::CallReducerFlags); } -impl set_flags_for_delete_unique_address for super::SetReducerFlags { - fn delete_unique_address(&self, flags: __ws::CallReducerFlags) { - self.imp.set_call_reducer_flags("delete_unique_address", flags); +impl set_flags_for_delete_unique_connection_id for super::SetReducerFlags { + fn delete_unique_connection_id(&self, flags: __ws::CallReducerFlags) { + self.imp.set_call_reducer_flags("delete_unique_connection_id", flags); } } diff --git a/crates/sdk/tests/test-client/src/module_bindings/enum_with_payload_type.rs b/crates/sdk/tests/test-client/src/module_bindings/enum_with_payload_type.rs index 5df9498b3a6..f79014a57cb 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/enum_with_payload_type.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/enum_with_payload_type.rs @@ -43,7 +43,7 @@ pub enum EnumWithPayload { Identity(__sdk::Identity), - Address(__sdk::Address), + ConnectionId(__sdk::ConnectionId), Timestamp(__sdk::Timestamp), diff --git a/crates/sdk/tests/test-client/src/module_bindings/every_primitive_struct_type.rs b/crates/sdk/tests/test-client/src/module_bindings/every_primitive_struct_type.rs index b1ea92ac512..4a3e85173c4 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/every_primitive_struct_type.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/every_primitive_struct_type.rs @@ -24,7 +24,7 @@ pub struct EveryPrimitiveStruct { pub o: f64, pub p: String, pub q: __sdk::Identity, - pub r: __sdk::Address, + pub r: __sdk::ConnectionId, pub s: __sdk::Timestamp, pub t: __sdk::TimeDuration, } diff --git a/crates/sdk/tests/test-client/src/module_bindings/every_vec_struct_type.rs b/crates/sdk/tests/test-client/src/module_bindings/every_vec_struct_type.rs index 7062f1e6124..0356089cda9 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/every_vec_struct_type.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/every_vec_struct_type.rs @@ -24,7 +24,7 @@ pub struct EveryVecStruct { pub o: Vec, pub p: Vec, pub q: Vec<__sdk::Identity>, - pub r: Vec<__sdk::Address>, + pub r: Vec<__sdk::ConnectionId>, pub s: Vec<__sdk::Timestamp>, pub t: Vec<__sdk::TimeDuration>, } diff --git a/crates/sdk/tests/test-client/src/module_bindings/insert_caller_one_address_reducer.rs b/crates/sdk/tests/test-client/src/module_bindings/insert_caller_one_connection_id_reducer.rs similarity index 52% rename from crates/sdk/tests/test-client/src/module_bindings/insert_caller_one_address_reducer.rs rename to crates/sdk/tests/test-client/src/module_bindings/insert_caller_one_connection_id_reducer.rs index 563073c7c8a..12ad2f96362 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/insert_caller_one_address_reducer.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/insert_caller_one_connection_id_reducer.rs @@ -6,63 +6,63 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; #[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] #[sats(crate = __lib)] -pub(super) struct InsertCallerOneAddressArgs {} +pub(super) struct InsertCallerOneConnectionIdArgs {} -impl From for super::Reducer { - fn from(args: InsertCallerOneAddressArgs) -> Self { - Self::InsertCallerOneAddress +impl From for super::Reducer { + fn from(args: InsertCallerOneConnectionIdArgs) -> Self { + Self::InsertCallerOneConnectionId } } -impl __sdk::InModule for InsertCallerOneAddressArgs { +impl __sdk::InModule for InsertCallerOneConnectionIdArgs { type Module = super::RemoteModule; } -pub struct InsertCallerOneAddressCallbackId(__sdk::CallbackId); +pub struct InsertCallerOneConnectionIdCallbackId(__sdk::CallbackId); #[allow(non_camel_case_types)] -/// Extension trait for access to the reducer `insert_caller_one_address`. +/// Extension trait for access to the reducer `insert_caller_one_connection_id`. /// /// Implemented for [`super::RemoteReducers`]. -pub trait insert_caller_one_address { - /// Request that the remote module invoke the reducer `insert_caller_one_address` to run as soon as possible. +pub trait insert_caller_one_connection_id { + /// Request that the remote module invoke the reducer `insert_caller_one_connection_id` to run as soon as possible. /// /// This method returns immediately, and errors only if we are unable to send the request. /// The reducer will run asynchronously in the future, - /// and its status can be observed by listening for [`Self::on_insert_caller_one_address`] callbacks. - fn insert_caller_one_address(&self) -> __sdk::Result<()>; - /// Register a callback to run whenever we are notified of an invocation of the reducer `insert_caller_one_address`. + /// and its status can be observed by listening for [`Self::on_insert_caller_one_connection_id`] callbacks. + fn insert_caller_one_connection_id(&self) -> __sdk::Result<()>; + /// Register a callback to run whenever we are notified of an invocation of the reducer `insert_caller_one_connection_id`. /// /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] /// to determine the reducer's status. /// - /// The returned [`InsertCallerOneAddressCallbackId`] can be passed to [`Self::remove_on_insert_caller_one_address`] + /// The returned [`InsertCallerOneConnectionIdCallbackId`] can be passed to [`Self::remove_on_insert_caller_one_connection_id`] /// to cancel the callback. - fn on_insert_caller_one_address( + fn on_insert_caller_one_connection_id( &self, callback: impl FnMut(&super::ReducerEventContext) + Send + 'static, - ) -> InsertCallerOneAddressCallbackId; - /// Cancel a callback previously registered by [`Self::on_insert_caller_one_address`], + ) -> InsertCallerOneConnectionIdCallbackId; + /// Cancel a callback previously registered by [`Self::on_insert_caller_one_connection_id`], /// causing it not to run in the future. - fn remove_on_insert_caller_one_address(&self, callback: InsertCallerOneAddressCallbackId); + fn remove_on_insert_caller_one_connection_id(&self, callback: InsertCallerOneConnectionIdCallbackId); } -impl insert_caller_one_address for super::RemoteReducers { - fn insert_caller_one_address(&self) -> __sdk::Result<()> { +impl insert_caller_one_connection_id for super::RemoteReducers { + fn insert_caller_one_connection_id(&self) -> __sdk::Result<()> { self.imp - .call_reducer("insert_caller_one_address", InsertCallerOneAddressArgs {}) + .call_reducer("insert_caller_one_connection_id", InsertCallerOneConnectionIdArgs {}) } - fn on_insert_caller_one_address( + fn on_insert_caller_one_connection_id( &self, mut callback: impl FnMut(&super::ReducerEventContext) + Send + 'static, - ) -> InsertCallerOneAddressCallbackId { - InsertCallerOneAddressCallbackId(self.imp.on_reducer( - "insert_caller_one_address", + ) -> InsertCallerOneConnectionIdCallbackId { + InsertCallerOneConnectionIdCallbackId(self.imp.on_reducer( + "insert_caller_one_connection_id", Box::new(move |ctx: &super::ReducerEventContext| { let super::ReducerEventContext { event: __sdk::ReducerEvent { - reducer: super::Reducer::InsertCallerOneAddress {}, + reducer: super::Reducer::InsertCallerOneConnectionId {}, .. }, .. @@ -74,27 +74,29 @@ impl insert_caller_one_address for super::RemoteReducers { }), )) } - fn remove_on_insert_caller_one_address(&self, callback: InsertCallerOneAddressCallbackId) { - self.imp.remove_on_reducer("insert_caller_one_address", callback.0) + fn remove_on_insert_caller_one_connection_id(&self, callback: InsertCallerOneConnectionIdCallbackId) { + self.imp + .remove_on_reducer("insert_caller_one_connection_id", callback.0) } } #[allow(non_camel_case_types)] #[doc(hidden)] -/// Extension trait for setting the call-flags for the reducer `insert_caller_one_address`. +/// Extension trait for setting the call-flags for the reducer `insert_caller_one_connection_id`. /// /// Implemented for [`super::SetReducerFlags`]. /// /// This type is currently unstable and may be removed without a major version bump. -pub trait set_flags_for_insert_caller_one_address { - /// Set the call-reducer flags for the reducer `insert_caller_one_address` to `flags`. +pub trait set_flags_for_insert_caller_one_connection_id { + /// Set the call-reducer flags for the reducer `insert_caller_one_connection_id` to `flags`. /// /// This type is currently unstable and may be removed without a major version bump. - fn insert_caller_one_address(&self, flags: __ws::CallReducerFlags); + fn insert_caller_one_connection_id(&self, flags: __ws::CallReducerFlags); } -impl set_flags_for_insert_caller_one_address for super::SetReducerFlags { - fn insert_caller_one_address(&self, flags: __ws::CallReducerFlags) { - self.imp.set_call_reducer_flags("insert_caller_one_address", flags); +impl set_flags_for_insert_caller_one_connection_id for super::SetReducerFlags { + fn insert_caller_one_connection_id(&self, flags: __ws::CallReducerFlags) { + self.imp + .set_call_reducer_flags("insert_caller_one_connection_id", flags); } } diff --git a/crates/sdk/tests/test-client/src/module_bindings/insert_caller_pk_address_reducer.rs b/crates/sdk/tests/test-client/src/module_bindings/insert_caller_pk_connection_id_reducer.rs similarity index 53% rename from crates/sdk/tests/test-client/src/module_bindings/insert_caller_pk_address_reducer.rs rename to crates/sdk/tests/test-client/src/module_bindings/insert_caller_pk_connection_id_reducer.rs index d455aadc041..5e9fd64a6b4 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/insert_caller_pk_address_reducer.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/insert_caller_pk_connection_id_reducer.rs @@ -6,65 +6,67 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; #[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] #[sats(crate = __lib)] -pub(super) struct InsertCallerPkAddressArgs { +pub(super) struct InsertCallerPkConnectionIdArgs { pub data: i32, } -impl From for super::Reducer { - fn from(args: InsertCallerPkAddressArgs) -> Self { - Self::InsertCallerPkAddress { data: args.data } +impl From for super::Reducer { + fn from(args: InsertCallerPkConnectionIdArgs) -> Self { + Self::InsertCallerPkConnectionId { data: args.data } } } -impl __sdk::InModule for InsertCallerPkAddressArgs { +impl __sdk::InModule for InsertCallerPkConnectionIdArgs { type Module = super::RemoteModule; } -pub struct InsertCallerPkAddressCallbackId(__sdk::CallbackId); +pub struct InsertCallerPkConnectionIdCallbackId(__sdk::CallbackId); #[allow(non_camel_case_types)] -/// Extension trait for access to the reducer `insert_caller_pk_address`. +/// Extension trait for access to the reducer `insert_caller_pk_connection_id`. /// /// Implemented for [`super::RemoteReducers`]. -pub trait insert_caller_pk_address { - /// Request that the remote module invoke the reducer `insert_caller_pk_address` to run as soon as possible. +pub trait insert_caller_pk_connection_id { + /// Request that the remote module invoke the reducer `insert_caller_pk_connection_id` to run as soon as possible. /// /// This method returns immediately, and errors only if we are unable to send the request. /// The reducer will run asynchronously in the future, - /// and its status can be observed by listening for [`Self::on_insert_caller_pk_address`] callbacks. - fn insert_caller_pk_address(&self, data: i32) -> __sdk::Result<()>; - /// Register a callback to run whenever we are notified of an invocation of the reducer `insert_caller_pk_address`. + /// and its status can be observed by listening for [`Self::on_insert_caller_pk_connection_id`] callbacks. + fn insert_caller_pk_connection_id(&self, data: i32) -> __sdk::Result<()>; + /// Register a callback to run whenever we are notified of an invocation of the reducer `insert_caller_pk_connection_id`. /// /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] /// to determine the reducer's status. /// - /// The returned [`InsertCallerPkAddressCallbackId`] can be passed to [`Self::remove_on_insert_caller_pk_address`] + /// The returned [`InsertCallerPkConnectionIdCallbackId`] can be passed to [`Self::remove_on_insert_caller_pk_connection_id`] /// to cancel the callback. - fn on_insert_caller_pk_address( + fn on_insert_caller_pk_connection_id( &self, callback: impl FnMut(&super::ReducerEventContext, &i32) + Send + 'static, - ) -> InsertCallerPkAddressCallbackId; - /// Cancel a callback previously registered by [`Self::on_insert_caller_pk_address`], + ) -> InsertCallerPkConnectionIdCallbackId; + /// Cancel a callback previously registered by [`Self::on_insert_caller_pk_connection_id`], /// causing it not to run in the future. - fn remove_on_insert_caller_pk_address(&self, callback: InsertCallerPkAddressCallbackId); + fn remove_on_insert_caller_pk_connection_id(&self, callback: InsertCallerPkConnectionIdCallbackId); } -impl insert_caller_pk_address for super::RemoteReducers { - fn insert_caller_pk_address(&self, data: i32) -> __sdk::Result<()> { - self.imp - .call_reducer("insert_caller_pk_address", InsertCallerPkAddressArgs { data }) +impl insert_caller_pk_connection_id for super::RemoteReducers { + fn insert_caller_pk_connection_id(&self, data: i32) -> __sdk::Result<()> { + self.imp.call_reducer( + "insert_caller_pk_connection_id", + InsertCallerPkConnectionIdArgs { data }, + ) } - fn on_insert_caller_pk_address( + fn on_insert_caller_pk_connection_id( &self, mut callback: impl FnMut(&super::ReducerEventContext, &i32) + Send + 'static, - ) -> InsertCallerPkAddressCallbackId { - InsertCallerPkAddressCallbackId(self.imp.on_reducer( - "insert_caller_pk_address", + ) -> InsertCallerPkConnectionIdCallbackId { + InsertCallerPkConnectionIdCallbackId(self.imp.on_reducer( + "insert_caller_pk_connection_id", Box::new(move |ctx: &super::ReducerEventContext| { let super::ReducerEventContext { event: __sdk::ReducerEvent { - reducer: super::Reducer::InsertCallerPkAddress { data }, + reducer: super::Reducer::InsertCallerPkConnectionId { data }, .. }, .. @@ -76,27 +78,27 @@ impl insert_caller_pk_address for super::RemoteReducers { }), )) } - fn remove_on_insert_caller_pk_address(&self, callback: InsertCallerPkAddressCallbackId) { - self.imp.remove_on_reducer("insert_caller_pk_address", callback.0) + fn remove_on_insert_caller_pk_connection_id(&self, callback: InsertCallerPkConnectionIdCallbackId) { + self.imp.remove_on_reducer("insert_caller_pk_connection_id", callback.0) } } #[allow(non_camel_case_types)] #[doc(hidden)] -/// Extension trait for setting the call-flags for the reducer `insert_caller_pk_address`. +/// Extension trait for setting the call-flags for the reducer `insert_caller_pk_connection_id`. /// /// Implemented for [`super::SetReducerFlags`]. /// /// This type is currently unstable and may be removed without a major version bump. -pub trait set_flags_for_insert_caller_pk_address { - /// Set the call-reducer flags for the reducer `insert_caller_pk_address` to `flags`. +pub trait set_flags_for_insert_caller_pk_connection_id { + /// Set the call-reducer flags for the reducer `insert_caller_pk_connection_id` to `flags`. /// /// This type is currently unstable and may be removed without a major version bump. - fn insert_caller_pk_address(&self, flags: __ws::CallReducerFlags); + fn insert_caller_pk_connection_id(&self, flags: __ws::CallReducerFlags); } -impl set_flags_for_insert_caller_pk_address for super::SetReducerFlags { - fn insert_caller_pk_address(&self, flags: __ws::CallReducerFlags) { - self.imp.set_call_reducer_flags("insert_caller_pk_address", flags); +impl set_flags_for_insert_caller_pk_connection_id for super::SetReducerFlags { + fn insert_caller_pk_connection_id(&self, flags: __ws::CallReducerFlags) { + self.imp.set_call_reducer_flags("insert_caller_pk_connection_id", flags); } } diff --git a/crates/sdk/tests/test-client/src/module_bindings/insert_caller_unique_address_reducer.rs b/crates/sdk/tests/test-client/src/module_bindings/insert_caller_unique_connection_id_reducer.rs similarity index 50% rename from crates/sdk/tests/test-client/src/module_bindings/insert_caller_unique_address_reducer.rs rename to crates/sdk/tests/test-client/src/module_bindings/insert_caller_unique_connection_id_reducer.rs index 660555b532e..99dcd0ea84e 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/insert_caller_unique_address_reducer.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/insert_caller_unique_connection_id_reducer.rs @@ -6,65 +6,67 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; #[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] #[sats(crate = __lib)] -pub(super) struct InsertCallerUniqueAddressArgs { +pub(super) struct InsertCallerUniqueConnectionIdArgs { pub data: i32, } -impl From for super::Reducer { - fn from(args: InsertCallerUniqueAddressArgs) -> Self { - Self::InsertCallerUniqueAddress { data: args.data } +impl From for super::Reducer { + fn from(args: InsertCallerUniqueConnectionIdArgs) -> Self { + Self::InsertCallerUniqueConnectionId { data: args.data } } } -impl __sdk::InModule for InsertCallerUniqueAddressArgs { +impl __sdk::InModule for InsertCallerUniqueConnectionIdArgs { type Module = super::RemoteModule; } -pub struct InsertCallerUniqueAddressCallbackId(__sdk::CallbackId); +pub struct InsertCallerUniqueConnectionIdCallbackId(__sdk::CallbackId); #[allow(non_camel_case_types)] -/// Extension trait for access to the reducer `insert_caller_unique_address`. +/// Extension trait for access to the reducer `insert_caller_unique_connection_id`. /// /// Implemented for [`super::RemoteReducers`]. -pub trait insert_caller_unique_address { - /// Request that the remote module invoke the reducer `insert_caller_unique_address` to run as soon as possible. +pub trait insert_caller_unique_connection_id { + /// Request that the remote module invoke the reducer `insert_caller_unique_connection_id` to run as soon as possible. /// /// This method returns immediately, and errors only if we are unable to send the request. /// The reducer will run asynchronously in the future, - /// and its status can be observed by listening for [`Self::on_insert_caller_unique_address`] callbacks. - fn insert_caller_unique_address(&self, data: i32) -> __sdk::Result<()>; - /// Register a callback to run whenever we are notified of an invocation of the reducer `insert_caller_unique_address`. + /// and its status can be observed by listening for [`Self::on_insert_caller_unique_connection_id`] callbacks. + fn insert_caller_unique_connection_id(&self, data: i32) -> __sdk::Result<()>; + /// Register a callback to run whenever we are notified of an invocation of the reducer `insert_caller_unique_connection_id`. /// /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] /// to determine the reducer's status. /// - /// The returned [`InsertCallerUniqueAddressCallbackId`] can be passed to [`Self::remove_on_insert_caller_unique_address`] + /// The returned [`InsertCallerUniqueConnectionIdCallbackId`] can be passed to [`Self::remove_on_insert_caller_unique_connection_id`] /// to cancel the callback. - fn on_insert_caller_unique_address( + fn on_insert_caller_unique_connection_id( &self, callback: impl FnMut(&super::ReducerEventContext, &i32) + Send + 'static, - ) -> InsertCallerUniqueAddressCallbackId; - /// Cancel a callback previously registered by [`Self::on_insert_caller_unique_address`], + ) -> InsertCallerUniqueConnectionIdCallbackId; + /// Cancel a callback previously registered by [`Self::on_insert_caller_unique_connection_id`], /// causing it not to run in the future. - fn remove_on_insert_caller_unique_address(&self, callback: InsertCallerUniqueAddressCallbackId); + fn remove_on_insert_caller_unique_connection_id(&self, callback: InsertCallerUniqueConnectionIdCallbackId); } -impl insert_caller_unique_address for super::RemoteReducers { - fn insert_caller_unique_address(&self, data: i32) -> __sdk::Result<()> { - self.imp - .call_reducer("insert_caller_unique_address", InsertCallerUniqueAddressArgs { data }) +impl insert_caller_unique_connection_id for super::RemoteReducers { + fn insert_caller_unique_connection_id(&self, data: i32) -> __sdk::Result<()> { + self.imp.call_reducer( + "insert_caller_unique_connection_id", + InsertCallerUniqueConnectionIdArgs { data }, + ) } - fn on_insert_caller_unique_address( + fn on_insert_caller_unique_connection_id( &self, mut callback: impl FnMut(&super::ReducerEventContext, &i32) + Send + 'static, - ) -> InsertCallerUniqueAddressCallbackId { - InsertCallerUniqueAddressCallbackId(self.imp.on_reducer( - "insert_caller_unique_address", + ) -> InsertCallerUniqueConnectionIdCallbackId { + InsertCallerUniqueConnectionIdCallbackId(self.imp.on_reducer( + "insert_caller_unique_connection_id", Box::new(move |ctx: &super::ReducerEventContext| { let super::ReducerEventContext { event: __sdk::ReducerEvent { - reducer: super::Reducer::InsertCallerUniqueAddress { data }, + reducer: super::Reducer::InsertCallerUniqueConnectionId { data }, .. }, .. @@ -76,27 +78,29 @@ impl insert_caller_unique_address for super::RemoteReducers { }), )) } - fn remove_on_insert_caller_unique_address(&self, callback: InsertCallerUniqueAddressCallbackId) { - self.imp.remove_on_reducer("insert_caller_unique_address", callback.0) + fn remove_on_insert_caller_unique_connection_id(&self, callback: InsertCallerUniqueConnectionIdCallbackId) { + self.imp + .remove_on_reducer("insert_caller_unique_connection_id", callback.0) } } #[allow(non_camel_case_types)] #[doc(hidden)] -/// Extension trait for setting the call-flags for the reducer `insert_caller_unique_address`. +/// Extension trait for setting the call-flags for the reducer `insert_caller_unique_connection_id`. /// /// Implemented for [`super::SetReducerFlags`]. /// /// This type is currently unstable and may be removed without a major version bump. -pub trait set_flags_for_insert_caller_unique_address { - /// Set the call-reducer flags for the reducer `insert_caller_unique_address` to `flags`. +pub trait set_flags_for_insert_caller_unique_connection_id { + /// Set the call-reducer flags for the reducer `insert_caller_unique_connection_id` to `flags`. /// /// This type is currently unstable and may be removed without a major version bump. - fn insert_caller_unique_address(&self, flags: __ws::CallReducerFlags); + fn insert_caller_unique_connection_id(&self, flags: __ws::CallReducerFlags); } -impl set_flags_for_insert_caller_unique_address for super::SetReducerFlags { - fn insert_caller_unique_address(&self, flags: __ws::CallReducerFlags) { - self.imp.set_call_reducer_flags("insert_caller_unique_address", flags); +impl set_flags_for_insert_caller_unique_connection_id for super::SetReducerFlags { + fn insert_caller_unique_connection_id(&self, flags: __ws::CallReducerFlags) { + self.imp + .set_call_reducer_flags("insert_caller_unique_connection_id", flags); } } diff --git a/crates/sdk/tests/test-client/src/module_bindings/insert_caller_vec_address_reducer.rs b/crates/sdk/tests/test-client/src/module_bindings/insert_caller_vec_connection_id_reducer.rs similarity index 52% rename from crates/sdk/tests/test-client/src/module_bindings/insert_caller_vec_address_reducer.rs rename to crates/sdk/tests/test-client/src/module_bindings/insert_caller_vec_connection_id_reducer.rs index 82474ec8d00..358fbfe7e37 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/insert_caller_vec_address_reducer.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/insert_caller_vec_connection_id_reducer.rs @@ -6,63 +6,63 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; #[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] #[sats(crate = __lib)] -pub(super) struct InsertCallerVecAddressArgs {} +pub(super) struct InsertCallerVecConnectionIdArgs {} -impl From for super::Reducer { - fn from(args: InsertCallerVecAddressArgs) -> Self { - Self::InsertCallerVecAddress +impl From for super::Reducer { + fn from(args: InsertCallerVecConnectionIdArgs) -> Self { + Self::InsertCallerVecConnectionId } } -impl __sdk::InModule for InsertCallerVecAddressArgs { +impl __sdk::InModule for InsertCallerVecConnectionIdArgs { type Module = super::RemoteModule; } -pub struct InsertCallerVecAddressCallbackId(__sdk::CallbackId); +pub struct InsertCallerVecConnectionIdCallbackId(__sdk::CallbackId); #[allow(non_camel_case_types)] -/// Extension trait for access to the reducer `insert_caller_vec_address`. +/// Extension trait for access to the reducer `insert_caller_vec_connection_id`. /// /// Implemented for [`super::RemoteReducers`]. -pub trait insert_caller_vec_address { - /// Request that the remote module invoke the reducer `insert_caller_vec_address` to run as soon as possible. +pub trait insert_caller_vec_connection_id { + /// Request that the remote module invoke the reducer `insert_caller_vec_connection_id` to run as soon as possible. /// /// This method returns immediately, and errors only if we are unable to send the request. /// The reducer will run asynchronously in the future, - /// and its status can be observed by listening for [`Self::on_insert_caller_vec_address`] callbacks. - fn insert_caller_vec_address(&self) -> __sdk::Result<()>; - /// Register a callback to run whenever we are notified of an invocation of the reducer `insert_caller_vec_address`. + /// and its status can be observed by listening for [`Self::on_insert_caller_vec_connection_id`] callbacks. + fn insert_caller_vec_connection_id(&self) -> __sdk::Result<()>; + /// Register a callback to run whenever we are notified of an invocation of the reducer `insert_caller_vec_connection_id`. /// /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] /// to determine the reducer's status. /// - /// The returned [`InsertCallerVecAddressCallbackId`] can be passed to [`Self::remove_on_insert_caller_vec_address`] + /// The returned [`InsertCallerVecConnectionIdCallbackId`] can be passed to [`Self::remove_on_insert_caller_vec_connection_id`] /// to cancel the callback. - fn on_insert_caller_vec_address( + fn on_insert_caller_vec_connection_id( &self, callback: impl FnMut(&super::ReducerEventContext) + Send + 'static, - ) -> InsertCallerVecAddressCallbackId; - /// Cancel a callback previously registered by [`Self::on_insert_caller_vec_address`], + ) -> InsertCallerVecConnectionIdCallbackId; + /// Cancel a callback previously registered by [`Self::on_insert_caller_vec_connection_id`], /// causing it not to run in the future. - fn remove_on_insert_caller_vec_address(&self, callback: InsertCallerVecAddressCallbackId); + fn remove_on_insert_caller_vec_connection_id(&self, callback: InsertCallerVecConnectionIdCallbackId); } -impl insert_caller_vec_address for super::RemoteReducers { - fn insert_caller_vec_address(&self) -> __sdk::Result<()> { +impl insert_caller_vec_connection_id for super::RemoteReducers { + fn insert_caller_vec_connection_id(&self) -> __sdk::Result<()> { self.imp - .call_reducer("insert_caller_vec_address", InsertCallerVecAddressArgs {}) + .call_reducer("insert_caller_vec_connection_id", InsertCallerVecConnectionIdArgs {}) } - fn on_insert_caller_vec_address( + fn on_insert_caller_vec_connection_id( &self, mut callback: impl FnMut(&super::ReducerEventContext) + Send + 'static, - ) -> InsertCallerVecAddressCallbackId { - InsertCallerVecAddressCallbackId(self.imp.on_reducer( - "insert_caller_vec_address", + ) -> InsertCallerVecConnectionIdCallbackId { + InsertCallerVecConnectionIdCallbackId(self.imp.on_reducer( + "insert_caller_vec_connection_id", Box::new(move |ctx: &super::ReducerEventContext| { let super::ReducerEventContext { event: __sdk::ReducerEvent { - reducer: super::Reducer::InsertCallerVecAddress {}, + reducer: super::Reducer::InsertCallerVecConnectionId {}, .. }, .. @@ -74,27 +74,29 @@ impl insert_caller_vec_address for super::RemoteReducers { }), )) } - fn remove_on_insert_caller_vec_address(&self, callback: InsertCallerVecAddressCallbackId) { - self.imp.remove_on_reducer("insert_caller_vec_address", callback.0) + fn remove_on_insert_caller_vec_connection_id(&self, callback: InsertCallerVecConnectionIdCallbackId) { + self.imp + .remove_on_reducer("insert_caller_vec_connection_id", callback.0) } } #[allow(non_camel_case_types)] #[doc(hidden)] -/// Extension trait for setting the call-flags for the reducer `insert_caller_vec_address`. +/// Extension trait for setting the call-flags for the reducer `insert_caller_vec_connection_id`. /// /// Implemented for [`super::SetReducerFlags`]. /// /// This type is currently unstable and may be removed without a major version bump. -pub trait set_flags_for_insert_caller_vec_address { - /// Set the call-reducer flags for the reducer `insert_caller_vec_address` to `flags`. +pub trait set_flags_for_insert_caller_vec_connection_id { + /// Set the call-reducer flags for the reducer `insert_caller_vec_connection_id` to `flags`. /// /// This type is currently unstable and may be removed without a major version bump. - fn insert_caller_vec_address(&self, flags: __ws::CallReducerFlags); + fn insert_caller_vec_connection_id(&self, flags: __ws::CallReducerFlags); } -impl set_flags_for_insert_caller_vec_address for super::SetReducerFlags { - fn insert_caller_vec_address(&self, flags: __ws::CallReducerFlags) { - self.imp.set_call_reducer_flags("insert_caller_vec_address", flags); +impl set_flags_for_insert_caller_vec_connection_id for super::SetReducerFlags { + fn insert_caller_vec_connection_id(&self, flags: __ws::CallReducerFlags) { + self.imp + .set_call_reducer_flags("insert_caller_vec_connection_id", flags); } } diff --git a/crates/sdk/tests/test-client/src/module_bindings/insert_one_address_reducer.rs b/crates/sdk/tests/test-client/src/module_bindings/insert_one_address_reducer.rs deleted file mode 100644 index 4a500242fc3..00000000000 --- a/crates/sdk/tests/test-client/src/module_bindings/insert_one_address_reducer.rs +++ /dev/null @@ -1,101 +0,0 @@ -// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. - -#![allow(unused, clippy::all)] -use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; - -#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] -#[sats(crate = __lib)] -pub(super) struct InsertOneAddressArgs { - pub a: __sdk::Address, -} - -impl From for super::Reducer { - fn from(args: InsertOneAddressArgs) -> Self { - Self::InsertOneAddress { a: args.a } - } -} - -impl __sdk::InModule for InsertOneAddressArgs { - type Module = super::RemoteModule; -} - -pub struct InsertOneAddressCallbackId(__sdk::CallbackId); - -#[allow(non_camel_case_types)] -/// Extension trait for access to the reducer `insert_one_address`. -/// -/// Implemented for [`super::RemoteReducers`]. -pub trait insert_one_address { - /// Request that the remote module invoke the reducer `insert_one_address` to run as soon as possible. - /// - /// This method returns immediately, and errors only if we are unable to send the request. - /// The reducer will run asynchronously in the future, - /// and its status can be observed by listening for [`Self::on_insert_one_address`] callbacks. - fn insert_one_address(&self, a: __sdk::Address) -> __sdk::Result<()>; - /// Register a callback to run whenever we are notified of an invocation of the reducer `insert_one_address`. - /// - /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] - /// to determine the reducer's status. - /// - /// The returned [`InsertOneAddressCallbackId`] can be passed to [`Self::remove_on_insert_one_address`] - /// to cancel the callback. - fn on_insert_one_address( - &self, - callback: impl FnMut(&super::ReducerEventContext, &__sdk::Address) + Send + 'static, - ) -> InsertOneAddressCallbackId; - /// Cancel a callback previously registered by [`Self::on_insert_one_address`], - /// causing it not to run in the future. - fn remove_on_insert_one_address(&self, callback: InsertOneAddressCallbackId); -} - -impl insert_one_address for super::RemoteReducers { - fn insert_one_address(&self, a: __sdk::Address) -> __sdk::Result<()> { - self.imp.call_reducer("insert_one_address", InsertOneAddressArgs { a }) - } - fn on_insert_one_address( - &self, - mut callback: impl FnMut(&super::ReducerEventContext, &__sdk::Address) + Send + 'static, - ) -> InsertOneAddressCallbackId { - InsertOneAddressCallbackId(self.imp.on_reducer( - "insert_one_address", - Box::new(move |ctx: &super::ReducerEventContext| { - let super::ReducerEventContext { - event: - __sdk::ReducerEvent { - reducer: super::Reducer::InsertOneAddress { a }, - .. - }, - .. - } = ctx - else { - unreachable!() - }; - callback(ctx, a) - }), - )) - } - fn remove_on_insert_one_address(&self, callback: InsertOneAddressCallbackId) { - self.imp.remove_on_reducer("insert_one_address", callback.0) - } -} - -#[allow(non_camel_case_types)] -#[doc(hidden)] -/// Extension trait for setting the call-flags for the reducer `insert_one_address`. -/// -/// Implemented for [`super::SetReducerFlags`]. -/// -/// This type is currently unstable and may be removed without a major version bump. -pub trait set_flags_for_insert_one_address { - /// Set the call-reducer flags for the reducer `insert_one_address` to `flags`. - /// - /// This type is currently unstable and may be removed without a major version bump. - fn insert_one_address(&self, flags: __ws::CallReducerFlags); -} - -impl set_flags_for_insert_one_address for super::SetReducerFlags { - fn insert_one_address(&self, flags: __ws::CallReducerFlags) { - self.imp.set_call_reducer_flags("insert_one_address", flags); - } -} diff --git a/crates/sdk/tests/test-client/src/module_bindings/insert_one_connection_id_reducer.rs b/crates/sdk/tests/test-client/src/module_bindings/insert_one_connection_id_reducer.rs new file mode 100644 index 00000000000..941f07ba299 --- /dev/null +++ b/crates/sdk/tests/test-client/src/module_bindings/insert_one_connection_id_reducer.rs @@ -0,0 +1,102 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#![allow(unused, clippy::all)] +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] +#[sats(crate = __lib)] +pub(super) struct InsertOneConnectionIdArgs { + pub a: __sdk::ConnectionId, +} + +impl From for super::Reducer { + fn from(args: InsertOneConnectionIdArgs) -> Self { + Self::InsertOneConnectionId { a: args.a } + } +} + +impl __sdk::InModule for InsertOneConnectionIdArgs { + type Module = super::RemoteModule; +} + +pub struct InsertOneConnectionIdCallbackId(__sdk::CallbackId); + +#[allow(non_camel_case_types)] +/// Extension trait for access to the reducer `insert_one_connection_id`. +/// +/// Implemented for [`super::RemoteReducers`]. +pub trait insert_one_connection_id { + /// Request that the remote module invoke the reducer `insert_one_connection_id` to run as soon as possible. + /// + /// This method returns immediately, and errors only if we are unable to send the request. + /// The reducer will run asynchronously in the future, + /// and its status can be observed by listening for [`Self::on_insert_one_connection_id`] callbacks. + fn insert_one_connection_id(&self, a: __sdk::ConnectionId) -> __sdk::Result<()>; + /// Register a callback to run whenever we are notified of an invocation of the reducer `insert_one_connection_id`. + /// + /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] + /// to determine the reducer's status. + /// + /// The returned [`InsertOneConnectionIdCallbackId`] can be passed to [`Self::remove_on_insert_one_connection_id`] + /// to cancel the callback. + fn on_insert_one_connection_id( + &self, + callback: impl FnMut(&super::ReducerEventContext, &__sdk::ConnectionId) + Send + 'static, + ) -> InsertOneConnectionIdCallbackId; + /// Cancel a callback previously registered by [`Self::on_insert_one_connection_id`], + /// causing it not to run in the future. + fn remove_on_insert_one_connection_id(&self, callback: InsertOneConnectionIdCallbackId); +} + +impl insert_one_connection_id for super::RemoteReducers { + fn insert_one_connection_id(&self, a: __sdk::ConnectionId) -> __sdk::Result<()> { + self.imp + .call_reducer("insert_one_connection_id", InsertOneConnectionIdArgs { a }) + } + fn on_insert_one_connection_id( + &self, + mut callback: impl FnMut(&super::ReducerEventContext, &__sdk::ConnectionId) + Send + 'static, + ) -> InsertOneConnectionIdCallbackId { + InsertOneConnectionIdCallbackId(self.imp.on_reducer( + "insert_one_connection_id", + Box::new(move |ctx: &super::ReducerEventContext| { + let super::ReducerEventContext { + event: + __sdk::ReducerEvent { + reducer: super::Reducer::InsertOneConnectionId { a }, + .. + }, + .. + } = ctx + else { + unreachable!() + }; + callback(ctx, a) + }), + )) + } + fn remove_on_insert_one_connection_id(&self, callback: InsertOneConnectionIdCallbackId) { + self.imp.remove_on_reducer("insert_one_connection_id", callback.0) + } +} + +#[allow(non_camel_case_types)] +#[doc(hidden)] +/// Extension trait for setting the call-flags for the reducer `insert_one_connection_id`. +/// +/// Implemented for [`super::SetReducerFlags`]. +/// +/// This type is currently unstable and may be removed without a major version bump. +pub trait set_flags_for_insert_one_connection_id { + /// Set the call-reducer flags for the reducer `insert_one_connection_id` to `flags`. + /// + /// This type is currently unstable and may be removed without a major version bump. + fn insert_one_connection_id(&self, flags: __ws::CallReducerFlags); +} + +impl set_flags_for_insert_one_connection_id for super::SetReducerFlags { + fn insert_one_connection_id(&self, flags: __ws::CallReducerFlags) { + self.imp.set_call_reducer_flags("insert_one_connection_id", flags); + } +} diff --git a/crates/sdk/tests/test-client/src/module_bindings/insert_pk_address_reducer.rs b/crates/sdk/tests/test-client/src/module_bindings/insert_pk_connection_id_reducer.rs similarity index 50% rename from crates/sdk/tests/test-client/src/module_bindings/insert_pk_address_reducer.rs rename to crates/sdk/tests/test-client/src/module_bindings/insert_pk_connection_id_reducer.rs index f030f35dd22..525b84f23b2 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/insert_pk_address_reducer.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/insert_pk_connection_id_reducer.rs @@ -6,69 +6,69 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; #[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] #[sats(crate = __lib)] -pub(super) struct InsertPkAddressArgs { - pub a: __sdk::Address, +pub(super) struct InsertPkConnectionIdArgs { + pub a: __sdk::ConnectionId, pub data: i32, } -impl From for super::Reducer { - fn from(args: InsertPkAddressArgs) -> Self { - Self::InsertPkAddress { +impl From for super::Reducer { + fn from(args: InsertPkConnectionIdArgs) -> Self { + Self::InsertPkConnectionId { a: args.a, data: args.data, } } } -impl __sdk::InModule for InsertPkAddressArgs { +impl __sdk::InModule for InsertPkConnectionIdArgs { type Module = super::RemoteModule; } -pub struct InsertPkAddressCallbackId(__sdk::CallbackId); +pub struct InsertPkConnectionIdCallbackId(__sdk::CallbackId); #[allow(non_camel_case_types)] -/// Extension trait for access to the reducer `insert_pk_address`. +/// Extension trait for access to the reducer `insert_pk_connection_id`. /// /// Implemented for [`super::RemoteReducers`]. -pub trait insert_pk_address { - /// Request that the remote module invoke the reducer `insert_pk_address` to run as soon as possible. +pub trait insert_pk_connection_id { + /// Request that the remote module invoke the reducer `insert_pk_connection_id` to run as soon as possible. /// /// This method returns immediately, and errors only if we are unable to send the request. /// The reducer will run asynchronously in the future, - /// and its status can be observed by listening for [`Self::on_insert_pk_address`] callbacks. - fn insert_pk_address(&self, a: __sdk::Address, data: i32) -> __sdk::Result<()>; - /// Register a callback to run whenever we are notified of an invocation of the reducer `insert_pk_address`. + /// and its status can be observed by listening for [`Self::on_insert_pk_connection_id`] callbacks. + fn insert_pk_connection_id(&self, a: __sdk::ConnectionId, data: i32) -> __sdk::Result<()>; + /// Register a callback to run whenever we are notified of an invocation of the reducer `insert_pk_connection_id`. /// /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] /// to determine the reducer's status. /// - /// The returned [`InsertPkAddressCallbackId`] can be passed to [`Self::remove_on_insert_pk_address`] + /// The returned [`InsertPkConnectionIdCallbackId`] can be passed to [`Self::remove_on_insert_pk_connection_id`] /// to cancel the callback. - fn on_insert_pk_address( + fn on_insert_pk_connection_id( &self, - callback: impl FnMut(&super::ReducerEventContext, &__sdk::Address, &i32) + Send + 'static, - ) -> InsertPkAddressCallbackId; - /// Cancel a callback previously registered by [`Self::on_insert_pk_address`], + callback: impl FnMut(&super::ReducerEventContext, &__sdk::ConnectionId, &i32) + Send + 'static, + ) -> InsertPkConnectionIdCallbackId; + /// Cancel a callback previously registered by [`Self::on_insert_pk_connection_id`], /// causing it not to run in the future. - fn remove_on_insert_pk_address(&self, callback: InsertPkAddressCallbackId); + fn remove_on_insert_pk_connection_id(&self, callback: InsertPkConnectionIdCallbackId); } -impl insert_pk_address for super::RemoteReducers { - fn insert_pk_address(&self, a: __sdk::Address, data: i32) -> __sdk::Result<()> { +impl insert_pk_connection_id for super::RemoteReducers { + fn insert_pk_connection_id(&self, a: __sdk::ConnectionId, data: i32) -> __sdk::Result<()> { self.imp - .call_reducer("insert_pk_address", InsertPkAddressArgs { a, data }) + .call_reducer("insert_pk_connection_id", InsertPkConnectionIdArgs { a, data }) } - fn on_insert_pk_address( + fn on_insert_pk_connection_id( &self, - mut callback: impl FnMut(&super::ReducerEventContext, &__sdk::Address, &i32) + Send + 'static, - ) -> InsertPkAddressCallbackId { - InsertPkAddressCallbackId(self.imp.on_reducer( - "insert_pk_address", + mut callback: impl FnMut(&super::ReducerEventContext, &__sdk::ConnectionId, &i32) + Send + 'static, + ) -> InsertPkConnectionIdCallbackId { + InsertPkConnectionIdCallbackId(self.imp.on_reducer( + "insert_pk_connection_id", Box::new(move |ctx: &super::ReducerEventContext| { let super::ReducerEventContext { event: __sdk::ReducerEvent { - reducer: super::Reducer::InsertPkAddress { a, data }, + reducer: super::Reducer::InsertPkConnectionId { a, data }, .. }, .. @@ -80,27 +80,27 @@ impl insert_pk_address for super::RemoteReducers { }), )) } - fn remove_on_insert_pk_address(&self, callback: InsertPkAddressCallbackId) { - self.imp.remove_on_reducer("insert_pk_address", callback.0) + fn remove_on_insert_pk_connection_id(&self, callback: InsertPkConnectionIdCallbackId) { + self.imp.remove_on_reducer("insert_pk_connection_id", callback.0) } } #[allow(non_camel_case_types)] #[doc(hidden)] -/// Extension trait for setting the call-flags for the reducer `insert_pk_address`. +/// Extension trait for setting the call-flags for the reducer `insert_pk_connection_id`. /// /// Implemented for [`super::SetReducerFlags`]. /// /// This type is currently unstable and may be removed without a major version bump. -pub trait set_flags_for_insert_pk_address { - /// Set the call-reducer flags for the reducer `insert_pk_address` to `flags`. +pub trait set_flags_for_insert_pk_connection_id { + /// Set the call-reducer flags for the reducer `insert_pk_connection_id` to `flags`. /// /// This type is currently unstable and may be removed without a major version bump. - fn insert_pk_address(&self, flags: __ws::CallReducerFlags); + fn insert_pk_connection_id(&self, flags: __ws::CallReducerFlags); } -impl set_flags_for_insert_pk_address for super::SetReducerFlags { - fn insert_pk_address(&self, flags: __ws::CallReducerFlags) { - self.imp.set_call_reducer_flags("insert_pk_address", flags); +impl set_flags_for_insert_pk_connection_id for super::SetReducerFlags { + fn insert_pk_connection_id(&self, flags: __ws::CallReducerFlags) { + self.imp.set_call_reducer_flags("insert_pk_connection_id", flags); } } diff --git a/crates/sdk/tests/test-client/src/module_bindings/insert_unique_address_reducer.rs b/crates/sdk/tests/test-client/src/module_bindings/insert_unique_connection_id_reducer.rs similarity index 51% rename from crates/sdk/tests/test-client/src/module_bindings/insert_unique_address_reducer.rs rename to crates/sdk/tests/test-client/src/module_bindings/insert_unique_connection_id_reducer.rs index c81e325f527..fa4fc140d78 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/insert_unique_address_reducer.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/insert_unique_connection_id_reducer.rs @@ -6,69 +6,69 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; #[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] #[sats(crate = __lib)] -pub(super) struct InsertUniqueAddressArgs { - pub a: __sdk::Address, +pub(super) struct InsertUniqueConnectionIdArgs { + pub a: __sdk::ConnectionId, pub data: i32, } -impl From for super::Reducer { - fn from(args: InsertUniqueAddressArgs) -> Self { - Self::InsertUniqueAddress { +impl From for super::Reducer { + fn from(args: InsertUniqueConnectionIdArgs) -> Self { + Self::InsertUniqueConnectionId { a: args.a, data: args.data, } } } -impl __sdk::InModule for InsertUniqueAddressArgs { +impl __sdk::InModule for InsertUniqueConnectionIdArgs { type Module = super::RemoteModule; } -pub struct InsertUniqueAddressCallbackId(__sdk::CallbackId); +pub struct InsertUniqueConnectionIdCallbackId(__sdk::CallbackId); #[allow(non_camel_case_types)] -/// Extension trait for access to the reducer `insert_unique_address`. +/// Extension trait for access to the reducer `insert_unique_connection_id`. /// /// Implemented for [`super::RemoteReducers`]. -pub trait insert_unique_address { - /// Request that the remote module invoke the reducer `insert_unique_address` to run as soon as possible. +pub trait insert_unique_connection_id { + /// Request that the remote module invoke the reducer `insert_unique_connection_id` to run as soon as possible. /// /// This method returns immediately, and errors only if we are unable to send the request. /// The reducer will run asynchronously in the future, - /// and its status can be observed by listening for [`Self::on_insert_unique_address`] callbacks. - fn insert_unique_address(&self, a: __sdk::Address, data: i32) -> __sdk::Result<()>; - /// Register a callback to run whenever we are notified of an invocation of the reducer `insert_unique_address`. + /// and its status can be observed by listening for [`Self::on_insert_unique_connection_id`] callbacks. + fn insert_unique_connection_id(&self, a: __sdk::ConnectionId, data: i32) -> __sdk::Result<()>; + /// Register a callback to run whenever we are notified of an invocation of the reducer `insert_unique_connection_id`. /// /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] /// to determine the reducer's status. /// - /// The returned [`InsertUniqueAddressCallbackId`] can be passed to [`Self::remove_on_insert_unique_address`] + /// The returned [`InsertUniqueConnectionIdCallbackId`] can be passed to [`Self::remove_on_insert_unique_connection_id`] /// to cancel the callback. - fn on_insert_unique_address( + fn on_insert_unique_connection_id( &self, - callback: impl FnMut(&super::ReducerEventContext, &__sdk::Address, &i32) + Send + 'static, - ) -> InsertUniqueAddressCallbackId; - /// Cancel a callback previously registered by [`Self::on_insert_unique_address`], + callback: impl FnMut(&super::ReducerEventContext, &__sdk::ConnectionId, &i32) + Send + 'static, + ) -> InsertUniqueConnectionIdCallbackId; + /// Cancel a callback previously registered by [`Self::on_insert_unique_connection_id`], /// causing it not to run in the future. - fn remove_on_insert_unique_address(&self, callback: InsertUniqueAddressCallbackId); + fn remove_on_insert_unique_connection_id(&self, callback: InsertUniqueConnectionIdCallbackId); } -impl insert_unique_address for super::RemoteReducers { - fn insert_unique_address(&self, a: __sdk::Address, data: i32) -> __sdk::Result<()> { +impl insert_unique_connection_id for super::RemoteReducers { + fn insert_unique_connection_id(&self, a: __sdk::ConnectionId, data: i32) -> __sdk::Result<()> { self.imp - .call_reducer("insert_unique_address", InsertUniqueAddressArgs { a, data }) + .call_reducer("insert_unique_connection_id", InsertUniqueConnectionIdArgs { a, data }) } - fn on_insert_unique_address( + fn on_insert_unique_connection_id( &self, - mut callback: impl FnMut(&super::ReducerEventContext, &__sdk::Address, &i32) + Send + 'static, - ) -> InsertUniqueAddressCallbackId { - InsertUniqueAddressCallbackId(self.imp.on_reducer( - "insert_unique_address", + mut callback: impl FnMut(&super::ReducerEventContext, &__sdk::ConnectionId, &i32) + Send + 'static, + ) -> InsertUniqueConnectionIdCallbackId { + InsertUniqueConnectionIdCallbackId(self.imp.on_reducer( + "insert_unique_connection_id", Box::new(move |ctx: &super::ReducerEventContext| { let super::ReducerEventContext { event: __sdk::ReducerEvent { - reducer: super::Reducer::InsertUniqueAddress { a, data }, + reducer: super::Reducer::InsertUniqueConnectionId { a, data }, .. }, .. @@ -80,27 +80,27 @@ impl insert_unique_address for super::RemoteReducers { }), )) } - fn remove_on_insert_unique_address(&self, callback: InsertUniqueAddressCallbackId) { - self.imp.remove_on_reducer("insert_unique_address", callback.0) + fn remove_on_insert_unique_connection_id(&self, callback: InsertUniqueConnectionIdCallbackId) { + self.imp.remove_on_reducer("insert_unique_connection_id", callback.0) } } #[allow(non_camel_case_types)] #[doc(hidden)] -/// Extension trait for setting the call-flags for the reducer `insert_unique_address`. +/// Extension trait for setting the call-flags for the reducer `insert_unique_connection_id`. /// /// Implemented for [`super::SetReducerFlags`]. /// /// This type is currently unstable and may be removed without a major version bump. -pub trait set_flags_for_insert_unique_address { - /// Set the call-reducer flags for the reducer `insert_unique_address` to `flags`. +pub trait set_flags_for_insert_unique_connection_id { + /// Set the call-reducer flags for the reducer `insert_unique_connection_id` to `flags`. /// /// This type is currently unstable and may be removed without a major version bump. - fn insert_unique_address(&self, flags: __ws::CallReducerFlags); + fn insert_unique_connection_id(&self, flags: __ws::CallReducerFlags); } -impl set_flags_for_insert_unique_address for super::SetReducerFlags { - fn insert_unique_address(&self, flags: __ws::CallReducerFlags) { - self.imp.set_call_reducer_flags("insert_unique_address", flags); +impl set_flags_for_insert_unique_connection_id for super::SetReducerFlags { + fn insert_unique_connection_id(&self, flags: __ws::CallReducerFlags) { + self.imp.set_call_reducer_flags("insert_unique_connection_id", flags); } } diff --git a/crates/sdk/tests/test-client/src/module_bindings/insert_vec_address_reducer.rs b/crates/sdk/tests/test-client/src/module_bindings/insert_vec_address_reducer.rs deleted file mode 100644 index 4106675a7a7..00000000000 --- a/crates/sdk/tests/test-client/src/module_bindings/insert_vec_address_reducer.rs +++ /dev/null @@ -1,101 +0,0 @@ -// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. - -#![allow(unused, clippy::all)] -use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; - -#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] -#[sats(crate = __lib)] -pub(super) struct InsertVecAddressArgs { - pub a: Vec<__sdk::Address>, -} - -impl From for super::Reducer { - fn from(args: InsertVecAddressArgs) -> Self { - Self::InsertVecAddress { a: args.a } - } -} - -impl __sdk::InModule for InsertVecAddressArgs { - type Module = super::RemoteModule; -} - -pub struct InsertVecAddressCallbackId(__sdk::CallbackId); - -#[allow(non_camel_case_types)] -/// Extension trait for access to the reducer `insert_vec_address`. -/// -/// Implemented for [`super::RemoteReducers`]. -pub trait insert_vec_address { - /// Request that the remote module invoke the reducer `insert_vec_address` to run as soon as possible. - /// - /// This method returns immediately, and errors only if we are unable to send the request. - /// The reducer will run asynchronously in the future, - /// and its status can be observed by listening for [`Self::on_insert_vec_address`] callbacks. - fn insert_vec_address(&self, a: Vec<__sdk::Address>) -> __sdk::Result<()>; - /// Register a callback to run whenever we are notified of an invocation of the reducer `insert_vec_address`. - /// - /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] - /// to determine the reducer's status. - /// - /// The returned [`InsertVecAddressCallbackId`] can be passed to [`Self::remove_on_insert_vec_address`] - /// to cancel the callback. - fn on_insert_vec_address( - &self, - callback: impl FnMut(&super::ReducerEventContext, &Vec<__sdk::Address>) + Send + 'static, - ) -> InsertVecAddressCallbackId; - /// Cancel a callback previously registered by [`Self::on_insert_vec_address`], - /// causing it not to run in the future. - fn remove_on_insert_vec_address(&self, callback: InsertVecAddressCallbackId); -} - -impl insert_vec_address for super::RemoteReducers { - fn insert_vec_address(&self, a: Vec<__sdk::Address>) -> __sdk::Result<()> { - self.imp.call_reducer("insert_vec_address", InsertVecAddressArgs { a }) - } - fn on_insert_vec_address( - &self, - mut callback: impl FnMut(&super::ReducerEventContext, &Vec<__sdk::Address>) + Send + 'static, - ) -> InsertVecAddressCallbackId { - InsertVecAddressCallbackId(self.imp.on_reducer( - "insert_vec_address", - Box::new(move |ctx: &super::ReducerEventContext| { - let super::ReducerEventContext { - event: - __sdk::ReducerEvent { - reducer: super::Reducer::InsertVecAddress { a }, - .. - }, - .. - } = ctx - else { - unreachable!() - }; - callback(ctx, a) - }), - )) - } - fn remove_on_insert_vec_address(&self, callback: InsertVecAddressCallbackId) { - self.imp.remove_on_reducer("insert_vec_address", callback.0) - } -} - -#[allow(non_camel_case_types)] -#[doc(hidden)] -/// Extension trait for setting the call-flags for the reducer `insert_vec_address`. -/// -/// Implemented for [`super::SetReducerFlags`]. -/// -/// This type is currently unstable and may be removed without a major version bump. -pub trait set_flags_for_insert_vec_address { - /// Set the call-reducer flags for the reducer `insert_vec_address` to `flags`. - /// - /// This type is currently unstable and may be removed without a major version bump. - fn insert_vec_address(&self, flags: __ws::CallReducerFlags); -} - -impl set_flags_for_insert_vec_address for super::SetReducerFlags { - fn insert_vec_address(&self, flags: __ws::CallReducerFlags) { - self.imp.set_call_reducer_flags("insert_vec_address", flags); - } -} diff --git a/crates/sdk/tests/test-client/src/module_bindings/insert_vec_connection_id_reducer.rs b/crates/sdk/tests/test-client/src/module_bindings/insert_vec_connection_id_reducer.rs new file mode 100644 index 00000000000..2337cb46256 --- /dev/null +++ b/crates/sdk/tests/test-client/src/module_bindings/insert_vec_connection_id_reducer.rs @@ -0,0 +1,102 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#![allow(unused, clippy::all)] +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] +#[sats(crate = __lib)] +pub(super) struct InsertVecConnectionIdArgs { + pub a: Vec<__sdk::ConnectionId>, +} + +impl From for super::Reducer { + fn from(args: InsertVecConnectionIdArgs) -> Self { + Self::InsertVecConnectionId { a: args.a } + } +} + +impl __sdk::InModule for InsertVecConnectionIdArgs { + type Module = super::RemoteModule; +} + +pub struct InsertVecConnectionIdCallbackId(__sdk::CallbackId); + +#[allow(non_camel_case_types)] +/// Extension trait for access to the reducer `insert_vec_connection_id`. +/// +/// Implemented for [`super::RemoteReducers`]. +pub trait insert_vec_connection_id { + /// Request that the remote module invoke the reducer `insert_vec_connection_id` to run as soon as possible. + /// + /// This method returns immediately, and errors only if we are unable to send the request. + /// The reducer will run asynchronously in the future, + /// and its status can be observed by listening for [`Self::on_insert_vec_connection_id`] callbacks. + fn insert_vec_connection_id(&self, a: Vec<__sdk::ConnectionId>) -> __sdk::Result<()>; + /// Register a callback to run whenever we are notified of an invocation of the reducer `insert_vec_connection_id`. + /// + /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] + /// to determine the reducer's status. + /// + /// The returned [`InsertVecConnectionIdCallbackId`] can be passed to [`Self::remove_on_insert_vec_connection_id`] + /// to cancel the callback. + fn on_insert_vec_connection_id( + &self, + callback: impl FnMut(&super::ReducerEventContext, &Vec<__sdk::ConnectionId>) + Send + 'static, + ) -> InsertVecConnectionIdCallbackId; + /// Cancel a callback previously registered by [`Self::on_insert_vec_connection_id`], + /// causing it not to run in the future. + fn remove_on_insert_vec_connection_id(&self, callback: InsertVecConnectionIdCallbackId); +} + +impl insert_vec_connection_id for super::RemoteReducers { + fn insert_vec_connection_id(&self, a: Vec<__sdk::ConnectionId>) -> __sdk::Result<()> { + self.imp + .call_reducer("insert_vec_connection_id", InsertVecConnectionIdArgs { a }) + } + fn on_insert_vec_connection_id( + &self, + mut callback: impl FnMut(&super::ReducerEventContext, &Vec<__sdk::ConnectionId>) + Send + 'static, + ) -> InsertVecConnectionIdCallbackId { + InsertVecConnectionIdCallbackId(self.imp.on_reducer( + "insert_vec_connection_id", + Box::new(move |ctx: &super::ReducerEventContext| { + let super::ReducerEventContext { + event: + __sdk::ReducerEvent { + reducer: super::Reducer::InsertVecConnectionId { a }, + .. + }, + .. + } = ctx + else { + unreachable!() + }; + callback(ctx, a) + }), + )) + } + fn remove_on_insert_vec_connection_id(&self, callback: InsertVecConnectionIdCallbackId) { + self.imp.remove_on_reducer("insert_vec_connection_id", callback.0) + } +} + +#[allow(non_camel_case_types)] +#[doc(hidden)] +/// Extension trait for setting the call-flags for the reducer `insert_vec_connection_id`. +/// +/// Implemented for [`super::SetReducerFlags`]. +/// +/// This type is currently unstable and may be removed without a major version bump. +pub trait set_flags_for_insert_vec_connection_id { + /// Set the call-reducer flags for the reducer `insert_vec_connection_id` to `flags`. + /// + /// This type is currently unstable and may be removed without a major version bump. + fn insert_vec_connection_id(&self, flags: __ws::CallReducerFlags); +} + +impl set_flags_for_insert_vec_connection_id for super::SetReducerFlags { + fn insert_vec_connection_id(&self, flags: __ws::CallReducerFlags) { + self.imp.set_call_reducer_flags("insert_vec_connection_id", flags); + } +} diff --git a/crates/sdk/tests/test-client/src/module_bindings/mod.rs b/crates/sdk/tests/test-client/src/module_bindings/mod.rs index 94584042ce8..9c125f29ad8 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/mod.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/mod.rs @@ -6,8 +6,8 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; pub mod byte_struct_type; pub mod delete_large_table_reducer; -pub mod delete_pk_address_reducer; pub mod delete_pk_bool_reducer; +pub mod delete_pk_connection_id_reducer; pub mod delete_pk_i_128_reducer; pub mod delete_pk_i_16_reducer; pub mod delete_pk_i_256_reducer; @@ -22,8 +22,8 @@ pub mod delete_pk_u_256_reducer; pub mod delete_pk_u_32_reducer; pub mod delete_pk_u_64_reducer; pub mod delete_pk_u_8_reducer; -pub mod delete_unique_address_reducer; pub mod delete_unique_bool_reducer; +pub mod delete_unique_connection_id_reducer; pub mod delete_unique_i_128_reducer; pub mod delete_unique_i_16_reducer; pub mod delete_unique_i_256_reducer; @@ -46,18 +46,18 @@ pub mod indexed_table_2_type; pub mod indexed_table_table; pub mod indexed_table_type; pub mod insert_call_timestamp_reducer; -pub mod insert_caller_one_address_reducer; +pub mod insert_caller_one_connection_id_reducer; pub mod insert_caller_one_identity_reducer; -pub mod insert_caller_pk_address_reducer; +pub mod insert_caller_pk_connection_id_reducer; pub mod insert_caller_pk_identity_reducer; -pub mod insert_caller_unique_address_reducer; +pub mod insert_caller_unique_connection_id_reducer; pub mod insert_caller_unique_identity_reducer; -pub mod insert_caller_vec_address_reducer; +pub mod insert_caller_vec_connection_id_reducer; pub mod insert_caller_vec_identity_reducer; pub mod insert_large_table_reducer; -pub mod insert_one_address_reducer; pub mod insert_one_bool_reducer; pub mod insert_one_byte_struct_reducer; +pub mod insert_one_connection_id_reducer; pub mod insert_one_enum_with_payload_reducer; pub mod insert_one_every_primitive_struct_reducer; pub mod insert_one_every_vec_struct_reducer; @@ -86,8 +86,8 @@ pub mod insert_option_identity_reducer; pub mod insert_option_simple_enum_reducer; pub mod insert_option_string_reducer; pub mod insert_option_vec_option_i_32_reducer; -pub mod insert_pk_address_reducer; pub mod insert_pk_bool_reducer; +pub mod insert_pk_connection_id_reducer; pub mod insert_pk_i_128_reducer; pub mod insert_pk_i_16_reducer; pub mod insert_pk_i_256_reducer; @@ -104,8 +104,8 @@ pub mod insert_pk_u_64_reducer; pub mod insert_pk_u_8_reducer; pub mod insert_primitives_as_strings_reducer; pub mod insert_table_holds_table_reducer; -pub mod insert_unique_address_reducer; pub mod insert_unique_bool_reducer; +pub mod insert_unique_connection_id_reducer; pub mod insert_unique_i_128_reducer; pub mod insert_unique_i_16_reducer; pub mod insert_unique_i_256_reducer; @@ -120,9 +120,9 @@ pub mod insert_unique_u_256_reducer; pub mod insert_unique_u_32_reducer; pub mod insert_unique_u_64_reducer; pub mod insert_unique_u_8_reducer; -pub mod insert_vec_address_reducer; pub mod insert_vec_bool_reducer; pub mod insert_vec_byte_struct_reducer; +pub mod insert_vec_connection_id_reducer; pub mod insert_vec_enum_with_payload_reducer; pub mod insert_vec_every_primitive_struct_reducer; pub mod insert_vec_every_vec_struct_reducer; @@ -148,12 +148,12 @@ pub mod insert_vec_unit_struct_reducer; pub mod large_table_table; pub mod large_table_type; pub mod no_op_succeeds_reducer; -pub mod one_address_table; -pub mod one_address_type; pub mod one_bool_table; pub mod one_bool_type; pub mod one_byte_struct_table; pub mod one_byte_struct_type; +pub mod one_connection_id_table; +pub mod one_connection_id_type; pub mod one_enum_with_payload_table; pub mod one_enum_with_payload_type; pub mod one_every_primitive_struct_table; @@ -210,10 +210,10 @@ pub mod option_string_table; pub mod option_string_type; pub mod option_vec_option_i_32_table; pub mod option_vec_option_i_32_type; -pub mod pk_address_table; -pub mod pk_address_type; pub mod pk_bool_table; pub mod pk_bool_type; +pub mod pk_connection_id_table; +pub mod pk_connection_id_type; pub mod pk_i_128_table; pub mod pk_i_128_type; pub mod pk_i_16_table; @@ -248,10 +248,10 @@ pub mod send_scheduled_message_reducer; pub mod simple_enum_type; pub mod table_holds_table_table; pub mod table_holds_table_type; -pub mod unique_address_table; -pub mod unique_address_type; pub mod unique_bool_table; pub mod unique_bool_type; +pub mod unique_connection_id_table; +pub mod unique_connection_id_type; pub mod unique_i_128_table; pub mod unique_i_128_type; pub mod unique_i_16_table; @@ -281,8 +281,8 @@ pub mod unique_u_64_type; pub mod unique_u_8_table; pub mod unique_u_8_type; pub mod unit_struct_type; -pub mod update_pk_address_reducer; pub mod update_pk_bool_reducer; +pub mod update_pk_connection_id_reducer; pub mod update_pk_i_128_reducer; pub mod update_pk_i_16_reducer; pub mod update_pk_i_256_reducer; @@ -297,8 +297,8 @@ pub mod update_pk_u_256_reducer; pub mod update_pk_u_32_reducer; pub mod update_pk_u_64_reducer; pub mod update_pk_u_8_reducer; -pub mod update_unique_address_reducer; pub mod update_unique_bool_reducer; +pub mod update_unique_connection_id_reducer; pub mod update_unique_i_128_reducer; pub mod update_unique_i_16_reducer; pub mod update_unique_i_256_reducer; @@ -313,12 +313,12 @@ pub mod update_unique_u_256_reducer; pub mod update_unique_u_32_reducer; pub mod update_unique_u_64_reducer; pub mod update_unique_u_8_reducer; -pub mod vec_address_table; -pub mod vec_address_type; pub mod vec_bool_table; pub mod vec_bool_type; pub mod vec_byte_struct_table; pub mod vec_byte_struct_type; +pub mod vec_connection_id_table; +pub mod vec_connection_id_type; pub mod vec_enum_with_payload_table; pub mod vec_enum_with_payload_type; pub mod vec_every_primitive_struct_table; @@ -368,8 +368,10 @@ pub use byte_struct_type::ByteStruct; pub use delete_large_table_reducer::{ delete_large_table, set_flags_for_delete_large_table, DeleteLargeTableCallbackId, }; -pub use delete_pk_address_reducer::{delete_pk_address, set_flags_for_delete_pk_address, DeletePkAddressCallbackId}; pub use delete_pk_bool_reducer::{delete_pk_bool, set_flags_for_delete_pk_bool, DeletePkBoolCallbackId}; +pub use delete_pk_connection_id_reducer::{ + delete_pk_connection_id, set_flags_for_delete_pk_connection_id, DeletePkConnectionIdCallbackId, +}; pub use delete_pk_i_128_reducer::{delete_pk_i_128, set_flags_for_delete_pk_i_128, DeletePkI128CallbackId}; pub use delete_pk_i_16_reducer::{delete_pk_i_16, set_flags_for_delete_pk_i_16, DeletePkI16CallbackId}; pub use delete_pk_i_256_reducer::{delete_pk_i_256, set_flags_for_delete_pk_i_256, DeletePkI256CallbackId}; @@ -386,12 +388,12 @@ pub use delete_pk_u_256_reducer::{delete_pk_u_256, set_flags_for_delete_pk_u_256 pub use delete_pk_u_32_reducer::{delete_pk_u_32, set_flags_for_delete_pk_u_32, DeletePkU32CallbackId}; pub use delete_pk_u_64_reducer::{delete_pk_u_64, set_flags_for_delete_pk_u_64, DeletePkU64CallbackId}; pub use delete_pk_u_8_reducer::{delete_pk_u_8, set_flags_for_delete_pk_u_8, DeletePkU8CallbackId}; -pub use delete_unique_address_reducer::{ - delete_unique_address, set_flags_for_delete_unique_address, DeleteUniqueAddressCallbackId, -}; pub use delete_unique_bool_reducer::{ delete_unique_bool, set_flags_for_delete_unique_bool, DeleteUniqueBoolCallbackId, }; +pub use delete_unique_connection_id_reducer::{ + delete_unique_connection_id, set_flags_for_delete_unique_connection_id, DeleteUniqueConnectionIdCallbackId, +}; pub use delete_unique_i_128_reducer::{ delete_unique_i_128, set_flags_for_delete_unique_i_128, DeleteUniqueI128CallbackId, }; @@ -428,26 +430,29 @@ pub use indexed_table_type::IndexedTable; pub use insert_call_timestamp_reducer::{ insert_call_timestamp, set_flags_for_insert_call_timestamp, InsertCallTimestampCallbackId, }; -pub use insert_caller_one_address_reducer::{ - insert_caller_one_address, set_flags_for_insert_caller_one_address, InsertCallerOneAddressCallbackId, +pub use insert_caller_one_connection_id_reducer::{ + insert_caller_one_connection_id, set_flags_for_insert_caller_one_connection_id, + InsertCallerOneConnectionIdCallbackId, }; pub use insert_caller_one_identity_reducer::{ insert_caller_one_identity, set_flags_for_insert_caller_one_identity, InsertCallerOneIdentityCallbackId, }; -pub use insert_caller_pk_address_reducer::{ - insert_caller_pk_address, set_flags_for_insert_caller_pk_address, InsertCallerPkAddressCallbackId, +pub use insert_caller_pk_connection_id_reducer::{ + insert_caller_pk_connection_id, set_flags_for_insert_caller_pk_connection_id, InsertCallerPkConnectionIdCallbackId, }; pub use insert_caller_pk_identity_reducer::{ insert_caller_pk_identity, set_flags_for_insert_caller_pk_identity, InsertCallerPkIdentityCallbackId, }; -pub use insert_caller_unique_address_reducer::{ - insert_caller_unique_address, set_flags_for_insert_caller_unique_address, InsertCallerUniqueAddressCallbackId, +pub use insert_caller_unique_connection_id_reducer::{ + insert_caller_unique_connection_id, set_flags_for_insert_caller_unique_connection_id, + InsertCallerUniqueConnectionIdCallbackId, }; pub use insert_caller_unique_identity_reducer::{ insert_caller_unique_identity, set_flags_for_insert_caller_unique_identity, InsertCallerUniqueIdentityCallbackId, }; -pub use insert_caller_vec_address_reducer::{ - insert_caller_vec_address, set_flags_for_insert_caller_vec_address, InsertCallerVecAddressCallbackId, +pub use insert_caller_vec_connection_id_reducer::{ + insert_caller_vec_connection_id, set_flags_for_insert_caller_vec_connection_id, + InsertCallerVecConnectionIdCallbackId, }; pub use insert_caller_vec_identity_reducer::{ insert_caller_vec_identity, set_flags_for_insert_caller_vec_identity, InsertCallerVecIdentityCallbackId, @@ -455,13 +460,13 @@ pub use insert_caller_vec_identity_reducer::{ pub use insert_large_table_reducer::{ insert_large_table, set_flags_for_insert_large_table, InsertLargeTableCallbackId, }; -pub use insert_one_address_reducer::{ - insert_one_address, set_flags_for_insert_one_address, InsertOneAddressCallbackId, -}; pub use insert_one_bool_reducer::{insert_one_bool, set_flags_for_insert_one_bool, InsertOneBoolCallbackId}; pub use insert_one_byte_struct_reducer::{ insert_one_byte_struct, set_flags_for_insert_one_byte_struct, InsertOneByteStructCallbackId, }; +pub use insert_one_connection_id_reducer::{ + insert_one_connection_id, set_flags_for_insert_one_connection_id, InsertOneConnectionIdCallbackId, +}; pub use insert_one_enum_with_payload_reducer::{ insert_one_enum_with_payload, set_flags_for_insert_one_enum_with_payload, InsertOneEnumWithPayloadCallbackId, }; @@ -516,8 +521,10 @@ pub use insert_option_string_reducer::{ pub use insert_option_vec_option_i_32_reducer::{ insert_option_vec_option_i_32, set_flags_for_insert_option_vec_option_i_32, InsertOptionVecOptionI32CallbackId, }; -pub use insert_pk_address_reducer::{insert_pk_address, set_flags_for_insert_pk_address, InsertPkAddressCallbackId}; pub use insert_pk_bool_reducer::{insert_pk_bool, set_flags_for_insert_pk_bool, InsertPkBoolCallbackId}; +pub use insert_pk_connection_id_reducer::{ + insert_pk_connection_id, set_flags_for_insert_pk_connection_id, InsertPkConnectionIdCallbackId, +}; pub use insert_pk_i_128_reducer::{insert_pk_i_128, set_flags_for_insert_pk_i_128, InsertPkI128CallbackId}; pub use insert_pk_i_16_reducer::{insert_pk_i_16, set_flags_for_insert_pk_i_16, InsertPkI16CallbackId}; pub use insert_pk_i_256_reducer::{insert_pk_i_256, set_flags_for_insert_pk_i_256, InsertPkI256CallbackId}; @@ -540,12 +547,12 @@ pub use insert_primitives_as_strings_reducer::{ pub use insert_table_holds_table_reducer::{ insert_table_holds_table, set_flags_for_insert_table_holds_table, InsertTableHoldsTableCallbackId, }; -pub use insert_unique_address_reducer::{ - insert_unique_address, set_flags_for_insert_unique_address, InsertUniqueAddressCallbackId, -}; pub use insert_unique_bool_reducer::{ insert_unique_bool, set_flags_for_insert_unique_bool, InsertUniqueBoolCallbackId, }; +pub use insert_unique_connection_id_reducer::{ + insert_unique_connection_id, set_flags_for_insert_unique_connection_id, InsertUniqueConnectionIdCallbackId, +}; pub use insert_unique_i_128_reducer::{ insert_unique_i_128, set_flags_for_insert_unique_i_128, InsertUniqueI128CallbackId, }; @@ -572,13 +579,13 @@ pub use insert_unique_u_256_reducer::{ pub use insert_unique_u_32_reducer::{insert_unique_u_32, set_flags_for_insert_unique_u_32, InsertUniqueU32CallbackId}; pub use insert_unique_u_64_reducer::{insert_unique_u_64, set_flags_for_insert_unique_u_64, InsertUniqueU64CallbackId}; pub use insert_unique_u_8_reducer::{insert_unique_u_8, set_flags_for_insert_unique_u_8, InsertUniqueU8CallbackId}; -pub use insert_vec_address_reducer::{ - insert_vec_address, set_flags_for_insert_vec_address, InsertVecAddressCallbackId, -}; pub use insert_vec_bool_reducer::{insert_vec_bool, set_flags_for_insert_vec_bool, InsertVecBoolCallbackId}; pub use insert_vec_byte_struct_reducer::{ insert_vec_byte_struct, set_flags_for_insert_vec_byte_struct, InsertVecByteStructCallbackId, }; +pub use insert_vec_connection_id_reducer::{ + insert_vec_connection_id, set_flags_for_insert_vec_connection_id, InsertVecConnectionIdCallbackId, +}; pub use insert_vec_enum_with_payload_reducer::{ insert_vec_enum_with_payload, set_flags_for_insert_vec_enum_with_payload, InsertVecEnumWithPayloadCallbackId, }; @@ -619,12 +626,12 @@ pub use insert_vec_unit_struct_reducer::{ pub use large_table_table::*; pub use large_table_type::LargeTable; pub use no_op_succeeds_reducer::{no_op_succeeds, set_flags_for_no_op_succeeds, NoOpSucceedsCallbackId}; -pub use one_address_table::*; -pub use one_address_type::OneAddress; pub use one_bool_table::*; pub use one_bool_type::OneBool; pub use one_byte_struct_table::*; pub use one_byte_struct_type::OneByteStruct; +pub use one_connection_id_table::*; +pub use one_connection_id_type::OneConnectionId; pub use one_enum_with_payload_table::*; pub use one_enum_with_payload_type::OneEnumWithPayload; pub use one_every_primitive_struct_table::*; @@ -681,10 +688,10 @@ pub use option_string_table::*; pub use option_string_type::OptionString; pub use option_vec_option_i_32_table::*; pub use option_vec_option_i_32_type::OptionVecOptionI32; -pub use pk_address_table::*; -pub use pk_address_type::PkAddress; pub use pk_bool_table::*; pub use pk_bool_type::PkBool; +pub use pk_connection_id_table::*; +pub use pk_connection_id_type::PkConnectionId; pub use pk_i_128_table::*; pub use pk_i_128_type::PkI128; pub use pk_i_16_table::*; @@ -721,10 +728,10 @@ pub use send_scheduled_message_reducer::{ pub use simple_enum_type::SimpleEnum; pub use table_holds_table_table::*; pub use table_holds_table_type::TableHoldsTable; -pub use unique_address_table::*; -pub use unique_address_type::UniqueAddress; pub use unique_bool_table::*; pub use unique_bool_type::UniqueBool; +pub use unique_connection_id_table::*; +pub use unique_connection_id_type::UniqueConnectionId; pub use unique_i_128_table::*; pub use unique_i_128_type::UniqueI128; pub use unique_i_16_table::*; @@ -754,8 +761,10 @@ pub use unique_u_64_type::UniqueU64; pub use unique_u_8_table::*; pub use unique_u_8_type::UniqueU8; pub use unit_struct_type::UnitStruct; -pub use update_pk_address_reducer::{set_flags_for_update_pk_address, update_pk_address, UpdatePkAddressCallbackId}; pub use update_pk_bool_reducer::{set_flags_for_update_pk_bool, update_pk_bool, UpdatePkBoolCallbackId}; +pub use update_pk_connection_id_reducer::{ + set_flags_for_update_pk_connection_id, update_pk_connection_id, UpdatePkConnectionIdCallbackId, +}; pub use update_pk_i_128_reducer::{set_flags_for_update_pk_i_128, update_pk_i_128, UpdatePkI128CallbackId}; pub use update_pk_i_16_reducer::{set_flags_for_update_pk_i_16, update_pk_i_16, UpdatePkI16CallbackId}; pub use update_pk_i_256_reducer::{set_flags_for_update_pk_i_256, update_pk_i_256, UpdatePkI256CallbackId}; @@ -772,12 +781,12 @@ pub use update_pk_u_256_reducer::{set_flags_for_update_pk_u_256, update_pk_u_256 pub use update_pk_u_32_reducer::{set_flags_for_update_pk_u_32, update_pk_u_32, UpdatePkU32CallbackId}; pub use update_pk_u_64_reducer::{set_flags_for_update_pk_u_64, update_pk_u_64, UpdatePkU64CallbackId}; pub use update_pk_u_8_reducer::{set_flags_for_update_pk_u_8, update_pk_u_8, UpdatePkU8CallbackId}; -pub use update_unique_address_reducer::{ - set_flags_for_update_unique_address, update_unique_address, UpdateUniqueAddressCallbackId, -}; pub use update_unique_bool_reducer::{ set_flags_for_update_unique_bool, update_unique_bool, UpdateUniqueBoolCallbackId, }; +pub use update_unique_connection_id_reducer::{ + set_flags_for_update_unique_connection_id, update_unique_connection_id, UpdateUniqueConnectionIdCallbackId, +}; pub use update_unique_i_128_reducer::{ set_flags_for_update_unique_i_128, update_unique_i_128, UpdateUniqueI128CallbackId, }; @@ -804,12 +813,12 @@ pub use update_unique_u_256_reducer::{ pub use update_unique_u_32_reducer::{set_flags_for_update_unique_u_32, update_unique_u_32, UpdateUniqueU32CallbackId}; pub use update_unique_u_64_reducer::{set_flags_for_update_unique_u_64, update_unique_u_64, UpdateUniqueU64CallbackId}; pub use update_unique_u_8_reducer::{set_flags_for_update_unique_u_8, update_unique_u_8, UpdateUniqueU8CallbackId}; -pub use vec_address_table::*; -pub use vec_address_type::VecAddress; pub use vec_bool_table::*; pub use vec_bool_type::VecBool; pub use vec_byte_struct_table::*; pub use vec_byte_struct_type::VecByteStruct; +pub use vec_connection_id_table::*; +pub use vec_connection_id_type::VecConnectionId; pub use vec_enum_with_payload_table::*; pub use vec_enum_with_payload_type::VecEnumWithPayload; pub use vec_every_primitive_struct_table::*; @@ -887,12 +896,12 @@ pub enum Reducer { u: EveryPrimitiveStruct, v: EveryVecStruct, }, - DeletePkAddress { - a: __sdk::Address, - }, DeletePkBool { b: bool, }, + DeletePkConnectionId { + a: __sdk::ConnectionId, + }, DeletePkI128 { n: i128, }, @@ -935,12 +944,12 @@ pub enum Reducer { DeletePkU8 { n: u8, }, - DeleteUniqueAddress { - a: __sdk::Address, - }, DeleteUniqueBool { b: bool, }, + DeleteUniqueConnectionId { + a: __sdk::ConnectionId, + }, DeleteUniqueI128 { n: i128, }, @@ -984,21 +993,21 @@ pub enum Reducer { n: u8, }, InsertCallTimestamp, - InsertCallerOneAddress, + InsertCallerOneConnectionId, InsertCallerOneIdentity, - InsertCallerPkAddress { + InsertCallerPkConnectionId { data: i32, }, InsertCallerPkIdentity { data: i32, }, - InsertCallerUniqueAddress { + InsertCallerUniqueConnectionId { data: i32, }, InsertCallerUniqueIdentity { data: i32, }, - InsertCallerVecAddress, + InsertCallerVecConnectionId, InsertCallerVecIdentity, InsertLargeTable { a: u8, @@ -1024,15 +1033,15 @@ pub enum Reducer { u: EveryPrimitiveStruct, v: EveryVecStruct, }, - InsertOneAddress { - a: __sdk::Address, - }, InsertOneBool { b: bool, }, InsertOneByteStruct { s: ByteStruct, }, + InsertOneConnectionId { + a: __sdk::ConnectionId, + }, InsertOneEnumWithPayload { e: EnumWithPayload, }, @@ -1117,14 +1126,14 @@ pub enum Reducer { InsertOptionVecOptionI32 { v: Option>>, }, - InsertPkAddress { - a: __sdk::Address, - data: i32, - }, InsertPkBool { b: bool, data: i32, }, + InsertPkConnectionId { + a: __sdk::ConnectionId, + data: i32, + }, InsertPkI128 { n: i128, data: i32, @@ -1188,14 +1197,14 @@ pub enum Reducer { a: OneU8, b: VecU8, }, - InsertUniqueAddress { - a: __sdk::Address, - data: i32, - }, InsertUniqueBool { b: bool, data: i32, }, + InsertUniqueConnectionId { + a: __sdk::ConnectionId, + data: i32, + }, InsertUniqueI128 { n: i128, data: i32, @@ -1252,15 +1261,15 @@ pub enum Reducer { n: u8, data: i32, }, - InsertVecAddress { - a: Vec<__sdk::Address>, - }, InsertVecBool { b: Vec, }, InsertVecByteStruct { s: Vec, }, + InsertVecConnectionId { + a: Vec<__sdk::ConnectionId>, + }, InsertVecEnumWithPayload { e: Vec, }, @@ -1331,14 +1340,14 @@ pub enum Reducer { SendScheduledMessage { arg: ScheduledTable, }, - UpdatePkAddress { - a: __sdk::Address, - data: i32, - }, UpdatePkBool { b: bool, data: i32, }, + UpdatePkConnectionId { + a: __sdk::ConnectionId, + data: i32, + }, UpdatePkI128 { n: i128, data: i32, @@ -1395,14 +1404,14 @@ pub enum Reducer { n: u8, data: i32, }, - UpdateUniqueAddress { - a: __sdk::Address, - data: i32, - }, UpdateUniqueBool { b: bool, data: i32, }, + UpdateUniqueConnectionId { + a: __sdk::ConnectionId, + data: i32, + }, UpdateUniqueI128 { n: i128, data: i32, @@ -1469,8 +1478,8 @@ impl __sdk::Reducer for Reducer { fn reducer_name(&self) -> &'static str { match self { Reducer::DeleteLargeTable { .. } => "delete_large_table", - Reducer::DeletePkAddress { .. } => "delete_pk_address", Reducer::DeletePkBool { .. } => "delete_pk_bool", + Reducer::DeletePkConnectionId { .. } => "delete_pk_connection_id", Reducer::DeletePkI128 { .. } => "delete_pk_i128", Reducer::DeletePkI16 { .. } => "delete_pk_i16", Reducer::DeletePkI256 { .. } => "delete_pk_i256", @@ -1485,8 +1494,8 @@ impl __sdk::Reducer for Reducer { Reducer::DeletePkU32 { .. } => "delete_pk_u32", Reducer::DeletePkU64 { .. } => "delete_pk_u64", Reducer::DeletePkU8 { .. } => "delete_pk_u8", - Reducer::DeleteUniqueAddress { .. } => "delete_unique_address", Reducer::DeleteUniqueBool { .. } => "delete_unique_bool", + Reducer::DeleteUniqueConnectionId { .. } => "delete_unique_connection_id", Reducer::DeleteUniqueI128 { .. } => "delete_unique_i128", Reducer::DeleteUniqueI16 { .. } => "delete_unique_i16", Reducer::DeleteUniqueI256 { .. } => "delete_unique_i256", @@ -1502,18 +1511,18 @@ impl __sdk::Reducer for Reducer { Reducer::DeleteUniqueU64 { .. } => "delete_unique_u64", Reducer::DeleteUniqueU8 { .. } => "delete_unique_u8", Reducer::InsertCallTimestamp => "insert_call_timestamp", - Reducer::InsertCallerOneAddress => "insert_caller_one_address", + Reducer::InsertCallerOneConnectionId => "insert_caller_one_connection_id", Reducer::InsertCallerOneIdentity => "insert_caller_one_identity", - Reducer::InsertCallerPkAddress { .. } => "insert_caller_pk_address", + Reducer::InsertCallerPkConnectionId { .. } => "insert_caller_pk_connection_id", Reducer::InsertCallerPkIdentity { .. } => "insert_caller_pk_identity", - Reducer::InsertCallerUniqueAddress { .. } => "insert_caller_unique_address", + Reducer::InsertCallerUniqueConnectionId { .. } => "insert_caller_unique_connection_id", Reducer::InsertCallerUniqueIdentity { .. } => "insert_caller_unique_identity", - Reducer::InsertCallerVecAddress => "insert_caller_vec_address", + Reducer::InsertCallerVecConnectionId => "insert_caller_vec_connection_id", Reducer::InsertCallerVecIdentity => "insert_caller_vec_identity", Reducer::InsertLargeTable { .. } => "insert_large_table", - Reducer::InsertOneAddress { .. } => "insert_one_address", Reducer::InsertOneBool { .. } => "insert_one_bool", Reducer::InsertOneByteStruct { .. } => "insert_one_byte_struct", + Reducer::InsertOneConnectionId { .. } => "insert_one_connection_id", Reducer::InsertOneEnumWithPayload { .. } => "insert_one_enum_with_payload", Reducer::InsertOneEveryPrimitiveStruct { .. } => "insert_one_every_primitive_struct", Reducer::InsertOneEveryVecStruct { .. } => "insert_one_every_vec_struct", @@ -1542,8 +1551,8 @@ impl __sdk::Reducer for Reducer { Reducer::InsertOptionSimpleEnum { .. } => "insert_option_simple_enum", Reducer::InsertOptionString { .. } => "insert_option_string", Reducer::InsertOptionVecOptionI32 { .. } => "insert_option_vec_option_i32", - Reducer::InsertPkAddress { .. } => "insert_pk_address", Reducer::InsertPkBool { .. } => "insert_pk_bool", + Reducer::InsertPkConnectionId { .. } => "insert_pk_connection_id", Reducer::InsertPkI128 { .. } => "insert_pk_i128", Reducer::InsertPkI16 { .. } => "insert_pk_i16", Reducer::InsertPkI256 { .. } => "insert_pk_i256", @@ -1560,8 +1569,8 @@ impl __sdk::Reducer for Reducer { Reducer::InsertPkU8 { .. } => "insert_pk_u8", Reducer::InsertPrimitivesAsStrings { .. } => "insert_primitives_as_strings", Reducer::InsertTableHoldsTable { .. } => "insert_table_holds_table", - Reducer::InsertUniqueAddress { .. } => "insert_unique_address", Reducer::InsertUniqueBool { .. } => "insert_unique_bool", + Reducer::InsertUniqueConnectionId { .. } => "insert_unique_connection_id", Reducer::InsertUniqueI128 { .. } => "insert_unique_i128", Reducer::InsertUniqueI16 { .. } => "insert_unique_i16", Reducer::InsertUniqueI256 { .. } => "insert_unique_i256", @@ -1576,9 +1585,9 @@ impl __sdk::Reducer for Reducer { Reducer::InsertUniqueU32 { .. } => "insert_unique_u32", Reducer::InsertUniqueU64 { .. } => "insert_unique_u64", Reducer::InsertUniqueU8 { .. } => "insert_unique_u8", - Reducer::InsertVecAddress { .. } => "insert_vec_address", Reducer::InsertVecBool { .. } => "insert_vec_bool", Reducer::InsertVecByteStruct { .. } => "insert_vec_byte_struct", + Reducer::InsertVecConnectionId { .. } => "insert_vec_connection_id", Reducer::InsertVecEnumWithPayload { .. } => "insert_vec_enum_with_payload", Reducer::InsertVecEveryPrimitiveStruct { .. } => "insert_vec_every_primitive_struct", Reducer::InsertVecEveryVecStruct { .. } => "insert_vec_every_vec_struct", @@ -1603,8 +1612,8 @@ impl __sdk::Reducer for Reducer { Reducer::InsertVecUnitStruct { .. } => "insert_vec_unit_struct", Reducer::NoOpSucceeds => "no_op_succeeds", Reducer::SendScheduledMessage { .. } => "send_scheduled_message", - Reducer::UpdatePkAddress { .. } => "update_pk_address", Reducer::UpdatePkBool { .. } => "update_pk_bool", + Reducer::UpdatePkConnectionId { .. } => "update_pk_connection_id", Reducer::UpdatePkI128 { .. } => "update_pk_i128", Reducer::UpdatePkI16 { .. } => "update_pk_i16", Reducer::UpdatePkI256 { .. } => "update_pk_i256", @@ -1619,8 +1628,8 @@ impl __sdk::Reducer for Reducer { Reducer::UpdatePkU32 { .. } => "update_pk_u32", Reducer::UpdatePkU64 { .. } => "update_pk_u64", Reducer::UpdatePkU8 { .. } => "update_pk_u8", - Reducer::UpdateUniqueAddress { .. } => "update_unique_address", Reducer::UpdateUniqueBool { .. } => "update_unique_bool", + Reducer::UpdateUniqueConnectionId { .. } => "update_unique_connection_id", Reducer::UpdateUniqueI128 { .. } => "update_unique_i128", Reducer::UpdateUniqueI16 { .. } => "update_unique_i16", Reducer::UpdateUniqueI256 { .. } => "update_unique_i256", @@ -1649,18 +1658,15 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer { )? .into(), ), - "delete_pk_address" => Ok( - __sdk::parse_reducer_args::( - "delete_pk_address", - &value.args, - )? - .into(), - ), "delete_pk_bool" => Ok(__sdk::parse_reducer_args::( "delete_pk_bool", &value.args, )? .into()), + "delete_pk_connection_id" => Ok(__sdk::parse_reducer_args::< + delete_pk_connection_id_reducer::DeletePkConnectionIdArgs, + >("delete_pk_connection_id", &value.args)? + .into()), "delete_pk_i128" => Ok(__sdk::parse_reducer_args::( "delete_pk_i128", &value.args, @@ -1735,10 +1741,6 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer { &value.args, )? .into()), - "delete_unique_address" => Ok(__sdk::parse_reducer_args::< - delete_unique_address_reducer::DeleteUniqueAddressArgs, - >("delete_unique_address", &value.args)? - .into()), "delete_unique_bool" => Ok( __sdk::parse_reducer_args::( "delete_unique_bool", @@ -1746,6 +1748,10 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer { )? .into(), ), + "delete_unique_connection_id" => Ok(__sdk::parse_reducer_args::< + delete_unique_connection_id_reducer::DeleteUniqueConnectionIdArgs, + >("delete_unique_connection_id", &value.args)? + .into()), "delete_unique_i128" => Ok( __sdk::parse_reducer_args::( "delete_unique_i128", @@ -1842,33 +1848,35 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer { insert_call_timestamp_reducer::InsertCallTimestampArgs, >("insert_call_timestamp", &value.args)? .into()), - "insert_caller_one_address" => Ok(__sdk::parse_reducer_args::< - insert_caller_one_address_reducer::InsertCallerOneAddressArgs, - >("insert_caller_one_address", &value.args)? + "insert_caller_one_connection_id" => Ok(__sdk::parse_reducer_args::< + insert_caller_one_connection_id_reducer::InsertCallerOneConnectionIdArgs, + >("insert_caller_one_connection_id", &value.args)? .into()), "insert_caller_one_identity" => Ok(__sdk::parse_reducer_args::< insert_caller_one_identity_reducer::InsertCallerOneIdentityArgs, >("insert_caller_one_identity", &value.args)? .into()), - "insert_caller_pk_address" => Ok(__sdk::parse_reducer_args::< - insert_caller_pk_address_reducer::InsertCallerPkAddressArgs, - >("insert_caller_pk_address", &value.args)? + "insert_caller_pk_connection_id" => Ok(__sdk::parse_reducer_args::< + insert_caller_pk_connection_id_reducer::InsertCallerPkConnectionIdArgs, + >("insert_caller_pk_connection_id", &value.args)? .into()), "insert_caller_pk_identity" => Ok(__sdk::parse_reducer_args::< insert_caller_pk_identity_reducer::InsertCallerPkIdentityArgs, >("insert_caller_pk_identity", &value.args)? .into()), - "insert_caller_unique_address" => Ok(__sdk::parse_reducer_args::< - insert_caller_unique_address_reducer::InsertCallerUniqueAddressArgs, - >("insert_caller_unique_address", &value.args)? - .into()), + "insert_caller_unique_connection_id" => { + Ok(__sdk::parse_reducer_args::< + insert_caller_unique_connection_id_reducer::InsertCallerUniqueConnectionIdArgs, + >("insert_caller_unique_connection_id", &value.args)? + .into()) + } "insert_caller_unique_identity" => Ok(__sdk::parse_reducer_args::< insert_caller_unique_identity_reducer::InsertCallerUniqueIdentityArgs, >("insert_caller_unique_identity", &value.args)? .into()), - "insert_caller_vec_address" => Ok(__sdk::parse_reducer_args::< - insert_caller_vec_address_reducer::InsertCallerVecAddressArgs, - >("insert_caller_vec_address", &value.args)? + "insert_caller_vec_connection_id" => Ok(__sdk::parse_reducer_args::< + insert_caller_vec_connection_id_reducer::InsertCallerVecConnectionIdArgs, + >("insert_caller_vec_connection_id", &value.args)? .into()), "insert_caller_vec_identity" => Ok(__sdk::parse_reducer_args::< insert_caller_vec_identity_reducer::InsertCallerVecIdentityArgs, @@ -1881,13 +1889,6 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer { )? .into(), ), - "insert_one_address" => Ok( - __sdk::parse_reducer_args::( - "insert_one_address", - &value.args, - )? - .into(), - ), "insert_one_bool" => Ok(__sdk::parse_reducer_args::( "insert_one_bool", &value.args, @@ -1897,6 +1898,10 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer { insert_one_byte_struct_reducer::InsertOneByteStructArgs, >("insert_one_byte_struct", &value.args)? .into()), + "insert_one_connection_id" => Ok(__sdk::parse_reducer_args::< + insert_one_connection_id_reducer::InsertOneConnectionIdArgs, + >("insert_one_connection_id", &value.args)? + .into()), "insert_one_enum_with_payload" => Ok(__sdk::parse_reducer_args::< insert_one_enum_with_payload_reducer::InsertOneEnumWithPayloadArgs, >("insert_one_enum_with_payload", &value.args)? @@ -2042,18 +2047,15 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer { insert_option_vec_option_i_32_reducer::InsertOptionVecOptionI32Args, >("insert_option_vec_option_i32", &value.args)? .into()), - "insert_pk_address" => Ok( - __sdk::parse_reducer_args::( - "insert_pk_address", - &value.args, - )? - .into(), - ), "insert_pk_bool" => Ok(__sdk::parse_reducer_args::( "insert_pk_bool", &value.args, )? .into()), + "insert_pk_connection_id" => Ok(__sdk::parse_reducer_args::< + insert_pk_connection_id_reducer::InsertPkConnectionIdArgs, + >("insert_pk_connection_id", &value.args)? + .into()), "insert_pk_i128" => Ok(__sdk::parse_reducer_args::( "insert_pk_i128", &value.args, @@ -2136,10 +2138,6 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer { insert_table_holds_table_reducer::InsertTableHoldsTableArgs, >("insert_table_holds_table", &value.args)? .into()), - "insert_unique_address" => Ok(__sdk::parse_reducer_args::< - insert_unique_address_reducer::InsertUniqueAddressArgs, - >("insert_unique_address", &value.args)? - .into()), "insert_unique_bool" => Ok( __sdk::parse_reducer_args::( "insert_unique_bool", @@ -2147,6 +2145,10 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer { )? .into(), ), + "insert_unique_connection_id" => Ok(__sdk::parse_reducer_args::< + insert_unique_connection_id_reducer::InsertUniqueConnectionIdArgs, + >("insert_unique_connection_id", &value.args)? + .into()), "insert_unique_i128" => Ok( __sdk::parse_reducer_args::( "insert_unique_i128", @@ -2239,13 +2241,6 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer { )? .into(), ), - "insert_vec_address" => Ok( - __sdk::parse_reducer_args::( - "insert_vec_address", - &value.args, - )? - .into(), - ), "insert_vec_bool" => Ok(__sdk::parse_reducer_args::( "insert_vec_bool", &value.args, @@ -2255,6 +2250,10 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer { insert_vec_byte_struct_reducer::InsertVecByteStructArgs, >("insert_vec_byte_struct", &value.args)? .into()), + "insert_vec_connection_id" => Ok(__sdk::parse_reducer_args::< + insert_vec_connection_id_reducer::InsertVecConnectionIdArgs, + >("insert_vec_connection_id", &value.args)? + .into()), "insert_vec_enum_with_payload" => Ok(__sdk::parse_reducer_args::< insert_vec_enum_with_payload_reducer::InsertVecEnumWithPayloadArgs, >("insert_vec_enum_with_payload", &value.args)? @@ -2380,18 +2379,15 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer { send_scheduled_message_reducer::SendScheduledMessageArgs, >("send_scheduled_message", &value.args)? .into()), - "update_pk_address" => Ok( - __sdk::parse_reducer_args::( - "update_pk_address", - &value.args, - )? - .into(), - ), "update_pk_bool" => Ok(__sdk::parse_reducer_args::( "update_pk_bool", &value.args, )? .into()), + "update_pk_connection_id" => Ok(__sdk::parse_reducer_args::< + update_pk_connection_id_reducer::UpdatePkConnectionIdArgs, + >("update_pk_connection_id", &value.args)? + .into()), "update_pk_i128" => Ok(__sdk::parse_reducer_args::( "update_pk_i128", &value.args, @@ -2466,10 +2462,6 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer { &value.args, )? .into()), - "update_unique_address" => Ok(__sdk::parse_reducer_args::< - update_unique_address_reducer::UpdateUniqueAddressArgs, - >("update_unique_address", &value.args)? - .into()), "update_unique_bool" => Ok( __sdk::parse_reducer_args::( "update_unique_bool", @@ -2477,6 +2469,10 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer { )? .into(), ), + "update_unique_connection_id" => Ok(__sdk::parse_reducer_args::< + update_unique_connection_id_reducer::UpdateUniqueConnectionIdArgs, + >("update_unique_connection_id", &value.args)? + .into()), "update_unique_i128" => Ok( __sdk::parse_reducer_args::( "update_unique_i128", @@ -2581,9 +2577,9 @@ pub struct DbUpdate { indexed_table: __sdk::TableUpdate, indexed_table_2: __sdk::TableUpdate, large_table: __sdk::TableUpdate, - one_address: __sdk::TableUpdate, one_bool: __sdk::TableUpdate, one_byte_struct: __sdk::TableUpdate, + one_connection_id: __sdk::TableUpdate, one_enum_with_payload: __sdk::TableUpdate, one_every_primitive_struct: __sdk::TableUpdate, one_every_vec_struct: __sdk::TableUpdate, @@ -2612,8 +2608,8 @@ pub struct DbUpdate { option_simple_enum: __sdk::TableUpdate, option_string: __sdk::TableUpdate, option_vec_option_i_32: __sdk::TableUpdate, - pk_address: __sdk::TableUpdate, pk_bool: __sdk::TableUpdate, + pk_connection_id: __sdk::TableUpdate, pk_i_128: __sdk::TableUpdate, pk_i_16: __sdk::TableUpdate, pk_i_256: __sdk::TableUpdate, @@ -2630,8 +2626,8 @@ pub struct DbUpdate { pk_u_8: __sdk::TableUpdate, scheduled_table: __sdk::TableUpdate, table_holds_table: __sdk::TableUpdate, - unique_address: __sdk::TableUpdate, unique_bool: __sdk::TableUpdate, + unique_connection_id: __sdk::TableUpdate, unique_i_128: __sdk::TableUpdate, unique_i_16: __sdk::TableUpdate, unique_i_256: __sdk::TableUpdate, @@ -2646,9 +2642,9 @@ pub struct DbUpdate { unique_u_32: __sdk::TableUpdate, unique_u_64: __sdk::TableUpdate, unique_u_8: __sdk::TableUpdate, - vec_address: __sdk::TableUpdate, vec_bool: __sdk::TableUpdate, vec_byte_struct: __sdk::TableUpdate, + vec_connection_id: __sdk::TableUpdate, vec_enum_with_payload: __sdk::TableUpdate, vec_every_primitive_struct: __sdk::TableUpdate, vec_every_vec_struct: __sdk::TableUpdate, @@ -2684,11 +2680,13 @@ impl TryFrom<__ws::DatabaseUpdate<__ws::BsatnFormat>> for DbUpdate { db_update.indexed_table_2 = indexed_table_2_table::parse_table_update(table_update)? } "large_table" => db_update.large_table = large_table_table::parse_table_update(table_update)?, - "one_address" => db_update.one_address = one_address_table::parse_table_update(table_update)?, "one_bool" => db_update.one_bool = one_bool_table::parse_table_update(table_update)?, "one_byte_struct" => { db_update.one_byte_struct = one_byte_struct_table::parse_table_update(table_update)? } + "one_connection_id" => { + db_update.one_connection_id = one_connection_id_table::parse_table_update(table_update)? + } "one_enum_with_payload" => { db_update.one_enum_with_payload = one_enum_with_payload_table::parse_table_update(table_update)? } @@ -2737,8 +2735,10 @@ impl TryFrom<__ws::DatabaseUpdate<__ws::BsatnFormat>> for DbUpdate { "option_vec_option_i32" => { db_update.option_vec_option_i_32 = option_vec_option_i_32_table::parse_table_update(table_update)? } - "pk_address" => db_update.pk_address = pk_address_table::parse_table_update(table_update)?, "pk_bool" => db_update.pk_bool = pk_bool_table::parse_table_update(table_update)?, + "pk_connection_id" => { + db_update.pk_connection_id = pk_connection_id_table::parse_table_update(table_update)? + } "pk_i128" => db_update.pk_i_128 = pk_i_128_table::parse_table_update(table_update)?, "pk_i16" => db_update.pk_i_16 = pk_i_16_table::parse_table_update(table_update)?, "pk_i256" => db_update.pk_i_256 = pk_i_256_table::parse_table_update(table_update)?, @@ -2759,8 +2759,10 @@ impl TryFrom<__ws::DatabaseUpdate<__ws::BsatnFormat>> for DbUpdate { "table_holds_table" => { db_update.table_holds_table = table_holds_table_table::parse_table_update(table_update)? } - "unique_address" => db_update.unique_address = unique_address_table::parse_table_update(table_update)?, "unique_bool" => db_update.unique_bool = unique_bool_table::parse_table_update(table_update)?, + "unique_connection_id" => { + db_update.unique_connection_id = unique_connection_id_table::parse_table_update(table_update)? + } "unique_i128" => db_update.unique_i_128 = unique_i_128_table::parse_table_update(table_update)?, "unique_i16" => db_update.unique_i_16 = unique_i_16_table::parse_table_update(table_update)?, "unique_i256" => db_update.unique_i_256 = unique_i_256_table::parse_table_update(table_update)?, @@ -2777,11 +2779,13 @@ impl TryFrom<__ws::DatabaseUpdate<__ws::BsatnFormat>> for DbUpdate { "unique_u32" => db_update.unique_u_32 = unique_u_32_table::parse_table_update(table_update)?, "unique_u64" => db_update.unique_u_64 = unique_u_64_table::parse_table_update(table_update)?, "unique_u8" => db_update.unique_u_8 = unique_u_8_table::parse_table_update(table_update)?, - "vec_address" => db_update.vec_address = vec_address_table::parse_table_update(table_update)?, "vec_bool" => db_update.vec_bool = vec_bool_table::parse_table_update(table_update)?, "vec_byte_struct" => { db_update.vec_byte_struct = vec_byte_struct_table::parse_table_update(table_update)? } + "vec_connection_id" => { + db_update.vec_connection_id = vec_connection_id_table::parse_table_update(table_update)? + } "vec_enum_with_payload" => { db_update.vec_enum_with_payload = vec_enum_with_payload_table::parse_table_update(table_update)? } @@ -2834,9 +2838,9 @@ impl __sdk::DbUpdate for DbUpdate { cache.apply_diff_to_table::("indexed_table", &self.indexed_table); cache.apply_diff_to_table::("indexed_table_2", &self.indexed_table_2); cache.apply_diff_to_table::("large_table", &self.large_table); - cache.apply_diff_to_table::("one_address", &self.one_address); cache.apply_diff_to_table::("one_bool", &self.one_bool); cache.apply_diff_to_table::("one_byte_struct", &self.one_byte_struct); + cache.apply_diff_to_table::("one_connection_id", &self.one_connection_id); cache.apply_diff_to_table::("one_enum_with_payload", &self.one_enum_with_payload); cache.apply_diff_to_table::( "one_every_primitive_struct", @@ -2871,8 +2875,8 @@ impl __sdk::DbUpdate for DbUpdate { cache.apply_diff_to_table::("option_simple_enum", &self.option_simple_enum); cache.apply_diff_to_table::("option_string", &self.option_string); cache.apply_diff_to_table::("option_vec_option_i32", &self.option_vec_option_i_32); - cache.apply_diff_to_table::("pk_address", &self.pk_address); cache.apply_diff_to_table::("pk_bool", &self.pk_bool); + cache.apply_diff_to_table::("pk_connection_id", &self.pk_connection_id); cache.apply_diff_to_table::("pk_i128", &self.pk_i_128); cache.apply_diff_to_table::("pk_i16", &self.pk_i_16); cache.apply_diff_to_table::("pk_i256", &self.pk_i_256); @@ -2889,8 +2893,8 @@ impl __sdk::DbUpdate for DbUpdate { cache.apply_diff_to_table::("pk_u8", &self.pk_u_8); cache.apply_diff_to_table::("scheduled_table", &self.scheduled_table); cache.apply_diff_to_table::("table_holds_table", &self.table_holds_table); - cache.apply_diff_to_table::("unique_address", &self.unique_address); cache.apply_diff_to_table::("unique_bool", &self.unique_bool); + cache.apply_diff_to_table::("unique_connection_id", &self.unique_connection_id); cache.apply_diff_to_table::("unique_i128", &self.unique_i_128); cache.apply_diff_to_table::("unique_i16", &self.unique_i_16); cache.apply_diff_to_table::("unique_i256", &self.unique_i_256); @@ -2905,9 +2909,9 @@ impl __sdk::DbUpdate for DbUpdate { cache.apply_diff_to_table::("unique_u32", &self.unique_u_32); cache.apply_diff_to_table::("unique_u64", &self.unique_u_64); cache.apply_diff_to_table::("unique_u8", &self.unique_u_8); - cache.apply_diff_to_table::("vec_address", &self.vec_address); cache.apply_diff_to_table::("vec_bool", &self.vec_bool); cache.apply_diff_to_table::("vec_byte_struct", &self.vec_byte_struct); + cache.apply_diff_to_table::("vec_connection_id", &self.vec_connection_id); cache.apply_diff_to_table::("vec_enum_with_payload", &self.vec_enum_with_payload); cache.apply_diff_to_table::( "vec_every_primitive_struct", @@ -2938,9 +2942,9 @@ impl __sdk::DbUpdate for DbUpdate { callbacks.invoke_table_row_callbacks::("indexed_table", &self.indexed_table, event); callbacks.invoke_table_row_callbacks::("indexed_table_2", &self.indexed_table_2, event); callbacks.invoke_table_row_callbacks::("large_table", &self.large_table, event); - callbacks.invoke_table_row_callbacks::("one_address", &self.one_address, event); callbacks.invoke_table_row_callbacks::("one_bool", &self.one_bool, event); callbacks.invoke_table_row_callbacks::("one_byte_struct", &self.one_byte_struct, event); + callbacks.invoke_table_row_callbacks::("one_connection_id", &self.one_connection_id, event); callbacks.invoke_table_row_callbacks::( "one_enum_with_payload", &self.one_enum_with_payload, @@ -2989,8 +2993,8 @@ impl __sdk::DbUpdate for DbUpdate { &self.option_vec_option_i_32, event, ); - callbacks.invoke_table_row_callbacks::("pk_address", &self.pk_address, event); callbacks.invoke_table_row_callbacks::("pk_bool", &self.pk_bool, event); + callbacks.invoke_table_row_callbacks::("pk_connection_id", &self.pk_connection_id, event); callbacks.invoke_table_row_callbacks::("pk_i128", &self.pk_i_128, event); callbacks.invoke_table_row_callbacks::("pk_i16", &self.pk_i_16, event); callbacks.invoke_table_row_callbacks::("pk_i256", &self.pk_i_256, event); @@ -3007,8 +3011,12 @@ impl __sdk::DbUpdate for DbUpdate { callbacks.invoke_table_row_callbacks::("pk_u8", &self.pk_u_8, event); callbacks.invoke_table_row_callbacks::("scheduled_table", &self.scheduled_table, event); callbacks.invoke_table_row_callbacks::("table_holds_table", &self.table_holds_table, event); - callbacks.invoke_table_row_callbacks::("unique_address", &self.unique_address, event); callbacks.invoke_table_row_callbacks::("unique_bool", &self.unique_bool, event); + callbacks.invoke_table_row_callbacks::( + "unique_connection_id", + &self.unique_connection_id, + event, + ); callbacks.invoke_table_row_callbacks::("unique_i128", &self.unique_i_128, event); callbacks.invoke_table_row_callbacks::("unique_i16", &self.unique_i_16, event); callbacks.invoke_table_row_callbacks::("unique_i256", &self.unique_i_256, event); @@ -3023,9 +3031,9 @@ impl __sdk::DbUpdate for DbUpdate { callbacks.invoke_table_row_callbacks::("unique_u32", &self.unique_u_32, event); callbacks.invoke_table_row_callbacks::("unique_u64", &self.unique_u_64, event); callbacks.invoke_table_row_callbacks::("unique_u8", &self.unique_u_8, event); - callbacks.invoke_table_row_callbacks::("vec_address", &self.vec_address, event); callbacks.invoke_table_row_callbacks::("vec_bool", &self.vec_bool, event); callbacks.invoke_table_row_callbacks::("vec_byte_struct", &self.vec_byte_struct, event); + callbacks.invoke_table_row_callbacks::("vec_connection_id", &self.vec_connection_id, event); callbacks.invoke_table_row_callbacks::( "vec_enum_with_payload", &self.vec_enum_with_payload, @@ -3171,8 +3179,8 @@ impl __sdk::DbContext for DbConnection { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } @@ -3389,8 +3397,8 @@ impl __sdk::DbContext for EventContext { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } @@ -3465,8 +3473,8 @@ impl __sdk::DbContext for ReducerEventContext { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } @@ -3537,8 +3545,8 @@ impl __sdk::DbContext for SubscriptionEventContext { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } @@ -3613,8 +3621,8 @@ impl __sdk::DbContext for ErrorContext { fn try_identity(&self) -> Option<__sdk::Identity> { self.imp.try_identity() } - fn address(&self) -> __sdk::Address { - self.imp.address() + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() } } @@ -3637,9 +3645,9 @@ impl __sdk::SpacetimeModule for RemoteModule { indexed_table_table::register_table(client_cache); indexed_table_2_table::register_table(client_cache); large_table_table::register_table(client_cache); - one_address_table::register_table(client_cache); one_bool_table::register_table(client_cache); one_byte_struct_table::register_table(client_cache); + one_connection_id_table::register_table(client_cache); one_enum_with_payload_table::register_table(client_cache); one_every_primitive_struct_table::register_table(client_cache); one_every_vec_struct_table::register_table(client_cache); @@ -3668,8 +3676,8 @@ impl __sdk::SpacetimeModule for RemoteModule { option_simple_enum_table::register_table(client_cache); option_string_table::register_table(client_cache); option_vec_option_i_32_table::register_table(client_cache); - pk_address_table::register_table(client_cache); pk_bool_table::register_table(client_cache); + pk_connection_id_table::register_table(client_cache); pk_i_128_table::register_table(client_cache); pk_i_16_table::register_table(client_cache); pk_i_256_table::register_table(client_cache); @@ -3686,8 +3694,8 @@ impl __sdk::SpacetimeModule for RemoteModule { pk_u_8_table::register_table(client_cache); scheduled_table_table::register_table(client_cache); table_holds_table_table::register_table(client_cache); - unique_address_table::register_table(client_cache); unique_bool_table::register_table(client_cache); + unique_connection_id_table::register_table(client_cache); unique_i_128_table::register_table(client_cache); unique_i_16_table::register_table(client_cache); unique_i_256_table::register_table(client_cache); @@ -3702,9 +3710,9 @@ impl __sdk::SpacetimeModule for RemoteModule { unique_u_32_table::register_table(client_cache); unique_u_64_table::register_table(client_cache); unique_u_8_table::register_table(client_cache); - vec_address_table::register_table(client_cache); vec_bool_table::register_table(client_cache); vec_byte_struct_table::register_table(client_cache); + vec_connection_id_table::register_table(client_cache); vec_enum_with_payload_table::register_table(client_cache); vec_every_primitive_struct_table::register_table(client_cache); vec_every_vec_struct_table::register_table(client_cache); diff --git a/crates/sdk/tests/test-client/src/module_bindings/one_address_table.rs b/crates/sdk/tests/test-client/src/module_bindings/one_address_table.rs deleted file mode 100644 index a7f4535aa5f..00000000000 --- a/crates/sdk/tests/test-client/src/module_bindings/one_address_table.rs +++ /dev/null @@ -1,94 +0,0 @@ -// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. - -#![allow(unused, clippy::all)] -use super::one_address_type::OneAddress; -use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; - -/// Table handle for the table `one_address`. -/// -/// Obtain a handle from the [`OneAddressTableAccess::one_address`] method on [`super::RemoteTables`], -/// like `ctx.db.one_address()`. -/// -/// Users are encouraged not to explicitly reference this type, -/// but to directly chain method calls, -/// like `ctx.db.one_address().on_insert(...)`. -pub struct OneAddressTableHandle<'ctx> { - imp: __sdk::TableHandle, - ctx: std::marker::PhantomData<&'ctx super::RemoteTables>, -} - -#[allow(non_camel_case_types)] -/// Extension trait for access to the table `one_address`. -/// -/// Implemented for [`super::RemoteTables`]. -pub trait OneAddressTableAccess { - #[allow(non_snake_case)] - /// Obtain a [`OneAddressTableHandle`], which mediates access to the table `one_address`. - fn one_address(&self) -> OneAddressTableHandle<'_>; -} - -impl OneAddressTableAccess for super::RemoteTables { - fn one_address(&self) -> OneAddressTableHandle<'_> { - OneAddressTableHandle { - imp: self.imp.get_table::("one_address"), - ctx: std::marker::PhantomData, - } - } -} - -pub struct OneAddressInsertCallbackId(__sdk::CallbackId); -pub struct OneAddressDeleteCallbackId(__sdk::CallbackId); - -impl<'ctx> __sdk::Table for OneAddressTableHandle<'ctx> { - type Row = OneAddress; - type EventContext = super::EventContext; - - fn count(&self) -> u64 { - self.imp.count() - } - fn iter(&self) -> impl Iterator + '_ { - self.imp.iter() - } - - type InsertCallbackId = OneAddressInsertCallbackId; - - fn on_insert( - &self, - callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, - ) -> OneAddressInsertCallbackId { - OneAddressInsertCallbackId(self.imp.on_insert(Box::new(callback))) - } - - fn remove_on_insert(&self, callback: OneAddressInsertCallbackId) { - self.imp.remove_on_insert(callback.0) - } - - type DeleteCallbackId = OneAddressDeleteCallbackId; - - fn on_delete( - &self, - callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, - ) -> OneAddressDeleteCallbackId { - OneAddressDeleteCallbackId(self.imp.on_delete(Box::new(callback))) - } - - fn remove_on_delete(&self, callback: OneAddressDeleteCallbackId) { - self.imp.remove_on_delete(callback.0) - } -} - -#[doc(hidden)] -pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { - let _table = client_cache.get_or_make_table::("one_address"); -} -#[doc(hidden)] -pub(super) fn parse_table_update( - raw_updates: __ws::TableUpdate<__ws::BsatnFormat>, -) -> __sdk::Result<__sdk::TableUpdate> { - __sdk::TableUpdate::parse_table_update_no_primary_key(raw_updates).map_err(|e| { - __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") - .with_cause(e) - .into() - }) -} diff --git a/crates/sdk/tests/test-client/src/module_bindings/one_connection_id_table.rs b/crates/sdk/tests/test-client/src/module_bindings/one_connection_id_table.rs new file mode 100644 index 00000000000..ca9a6c76e62 --- /dev/null +++ b/crates/sdk/tests/test-client/src/module_bindings/one_connection_id_table.rs @@ -0,0 +1,94 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#![allow(unused, clippy::all)] +use super::one_connection_id_type::OneConnectionId; +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +/// Table handle for the table `one_connection_id`. +/// +/// Obtain a handle from the [`OneConnectionIdTableAccess::one_connection_id`] method on [`super::RemoteTables`], +/// like `ctx.db.one_connection_id()`. +/// +/// Users are encouraged not to explicitly reference this type, +/// but to directly chain method calls, +/// like `ctx.db.one_connection_id().on_insert(...)`. +pub struct OneConnectionIdTableHandle<'ctx> { + imp: __sdk::TableHandle, + ctx: std::marker::PhantomData<&'ctx super::RemoteTables>, +} + +#[allow(non_camel_case_types)] +/// Extension trait for access to the table `one_connection_id`. +/// +/// Implemented for [`super::RemoteTables`]. +pub trait OneConnectionIdTableAccess { + #[allow(non_snake_case)] + /// Obtain a [`OneConnectionIdTableHandle`], which mediates access to the table `one_connection_id`. + fn one_connection_id(&self) -> OneConnectionIdTableHandle<'_>; +} + +impl OneConnectionIdTableAccess for super::RemoteTables { + fn one_connection_id(&self) -> OneConnectionIdTableHandle<'_> { + OneConnectionIdTableHandle { + imp: self.imp.get_table::("one_connection_id"), + ctx: std::marker::PhantomData, + } + } +} + +pub struct OneConnectionIdInsertCallbackId(__sdk::CallbackId); +pub struct OneConnectionIdDeleteCallbackId(__sdk::CallbackId); + +impl<'ctx> __sdk::Table for OneConnectionIdTableHandle<'ctx> { + type Row = OneConnectionId; + type EventContext = super::EventContext; + + fn count(&self) -> u64 { + self.imp.count() + } + fn iter(&self) -> impl Iterator + '_ { + self.imp.iter() + } + + type InsertCallbackId = OneConnectionIdInsertCallbackId; + + fn on_insert( + &self, + callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, + ) -> OneConnectionIdInsertCallbackId { + OneConnectionIdInsertCallbackId(self.imp.on_insert(Box::new(callback))) + } + + fn remove_on_insert(&self, callback: OneConnectionIdInsertCallbackId) { + self.imp.remove_on_insert(callback.0) + } + + type DeleteCallbackId = OneConnectionIdDeleteCallbackId; + + fn on_delete( + &self, + callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, + ) -> OneConnectionIdDeleteCallbackId { + OneConnectionIdDeleteCallbackId(self.imp.on_delete(Box::new(callback))) + } + + fn remove_on_delete(&self, callback: OneConnectionIdDeleteCallbackId) { + self.imp.remove_on_delete(callback.0) + } +} + +#[doc(hidden)] +pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { + let _table = client_cache.get_or_make_table::("one_connection_id"); +} +#[doc(hidden)] +pub(super) fn parse_table_update( + raw_updates: __ws::TableUpdate<__ws::BsatnFormat>, +) -> __sdk::Result<__sdk::TableUpdate> { + __sdk::TableUpdate::parse_table_update_no_primary_key(raw_updates).map_err(|e| { + __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") + .with_cause(e) + .into() + }) +} diff --git a/crates/sdk/tests/test-client/src/module_bindings/one_address_type.rs b/crates/sdk/tests/test-client/src/module_bindings/one_connection_id_type.rs similarity index 79% rename from crates/sdk/tests/test-client/src/module_bindings/one_address_type.rs rename to crates/sdk/tests/test-client/src/module_bindings/one_connection_id_type.rs index f7ef39e0622..d1f11dcec88 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/one_address_type.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/one_connection_id_type.rs @@ -6,10 +6,10 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; #[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] #[sats(crate = __lib)] -pub struct OneAddress { - pub a: __sdk::Address, +pub struct OneConnectionId { + pub a: __sdk::ConnectionId, } -impl __sdk::InModule for OneAddress { +impl __sdk::InModule for OneConnectionId { type Module = super::RemoteModule; } diff --git a/crates/sdk/tests/test-client/src/module_bindings/pk_address_table.rs b/crates/sdk/tests/test-client/src/module_bindings/pk_address_table.rs deleted file mode 100644 index 17b7a384ed8..00000000000 --- a/crates/sdk/tests/test-client/src/module_bindings/pk_address_table.rs +++ /dev/null @@ -1,143 +0,0 @@ -// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. - -#![allow(unused, clippy::all)] -use super::pk_address_type::PkAddress; -use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; - -/// Table handle for the table `pk_address`. -/// -/// Obtain a handle from the [`PkAddressTableAccess::pk_address`] method on [`super::RemoteTables`], -/// like `ctx.db.pk_address()`. -/// -/// Users are encouraged not to explicitly reference this type, -/// but to directly chain method calls, -/// like `ctx.db.pk_address().on_insert(...)`. -pub struct PkAddressTableHandle<'ctx> { - imp: __sdk::TableHandle, - ctx: std::marker::PhantomData<&'ctx super::RemoteTables>, -} - -#[allow(non_camel_case_types)] -/// Extension trait for access to the table `pk_address`. -/// -/// Implemented for [`super::RemoteTables`]. -pub trait PkAddressTableAccess { - #[allow(non_snake_case)] - /// Obtain a [`PkAddressTableHandle`], which mediates access to the table `pk_address`. - fn pk_address(&self) -> PkAddressTableHandle<'_>; -} - -impl PkAddressTableAccess for super::RemoteTables { - fn pk_address(&self) -> PkAddressTableHandle<'_> { - PkAddressTableHandle { - imp: self.imp.get_table::("pk_address"), - ctx: std::marker::PhantomData, - } - } -} - -pub struct PkAddressInsertCallbackId(__sdk::CallbackId); -pub struct PkAddressDeleteCallbackId(__sdk::CallbackId); - -impl<'ctx> __sdk::Table for PkAddressTableHandle<'ctx> { - type Row = PkAddress; - type EventContext = super::EventContext; - - fn count(&self) -> u64 { - self.imp.count() - } - fn iter(&self) -> impl Iterator + '_ { - self.imp.iter() - } - - type InsertCallbackId = PkAddressInsertCallbackId; - - fn on_insert( - &self, - callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, - ) -> PkAddressInsertCallbackId { - PkAddressInsertCallbackId(self.imp.on_insert(Box::new(callback))) - } - - fn remove_on_insert(&self, callback: PkAddressInsertCallbackId) { - self.imp.remove_on_insert(callback.0) - } - - type DeleteCallbackId = PkAddressDeleteCallbackId; - - fn on_delete( - &self, - callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, - ) -> PkAddressDeleteCallbackId { - PkAddressDeleteCallbackId(self.imp.on_delete(Box::new(callback))) - } - - fn remove_on_delete(&self, callback: PkAddressDeleteCallbackId) { - self.imp.remove_on_delete(callback.0) - } -} - -#[doc(hidden)] -pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { - let _table = client_cache.get_or_make_table::("pk_address"); - _table.add_unique_constraint::<__sdk::Address>("a", |row| &row.a); -} -pub struct PkAddressUpdateCallbackId(__sdk::CallbackId); - -impl<'ctx> __sdk::TableWithPrimaryKey for PkAddressTableHandle<'ctx> { - type UpdateCallbackId = PkAddressUpdateCallbackId; - - fn on_update( - &self, - callback: impl FnMut(&Self::EventContext, &Self::Row, &Self::Row) + Send + 'static, - ) -> PkAddressUpdateCallbackId { - PkAddressUpdateCallbackId(self.imp.on_update(Box::new(callback))) - } - - fn remove_on_update(&self, callback: PkAddressUpdateCallbackId) { - self.imp.remove_on_update(callback.0) - } -} - -#[doc(hidden)] -pub(super) fn parse_table_update( - raw_updates: __ws::TableUpdate<__ws::BsatnFormat>, -) -> __sdk::Result<__sdk::TableUpdate> { - __sdk::TableUpdate::parse_table_update_with_primary_key::<__sdk::Address>(raw_updates, |row: &PkAddress| &row.a) - .map_err(|e| { - __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") - .with_cause(e) - .into() - }) -} - -/// Access to the `a` unique index on the table `pk_address`, -/// which allows point queries on the field of the same name -/// via the [`PkAddressAUnique::find`] method. -/// -/// Users are encouraged not to explicitly reference this type, -/// but to directly chain method calls, -/// like `ctx.db.pk_address().a().find(...)`. -pub struct PkAddressAUnique<'ctx> { - imp: __sdk::UniqueConstraintHandle, - phantom: std::marker::PhantomData<&'ctx super::RemoteTables>, -} - -impl<'ctx> PkAddressTableHandle<'ctx> { - /// Get a handle on the `a` unique index on the table `pk_address`. - pub fn a(&self) -> PkAddressAUnique<'ctx> { - PkAddressAUnique { - imp: self.imp.get_unique_constraint::<__sdk::Address>("a"), - phantom: std::marker::PhantomData, - } - } -} - -impl<'ctx> PkAddressAUnique<'ctx> { - /// Find the subscribed row whose `a` column value is equal to `col_val`, - /// if such a row is present in the client cache. - pub fn find(&self, col_val: &__sdk::Address) -> Option { - self.imp.find(col_val) - } -} diff --git a/crates/sdk/tests/test-client/src/module_bindings/pk_connection_id_table.rs b/crates/sdk/tests/test-client/src/module_bindings/pk_connection_id_table.rs new file mode 100644 index 00000000000..294780a1c42 --- /dev/null +++ b/crates/sdk/tests/test-client/src/module_bindings/pk_connection_id_table.rs @@ -0,0 +1,146 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#![allow(unused, clippy::all)] +use super::pk_connection_id_type::PkConnectionId; +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +/// Table handle for the table `pk_connection_id`. +/// +/// Obtain a handle from the [`PkConnectionIdTableAccess::pk_connection_id`] method on [`super::RemoteTables`], +/// like `ctx.db.pk_connection_id()`. +/// +/// Users are encouraged not to explicitly reference this type, +/// but to directly chain method calls, +/// like `ctx.db.pk_connection_id().on_insert(...)`. +pub struct PkConnectionIdTableHandle<'ctx> { + imp: __sdk::TableHandle, + ctx: std::marker::PhantomData<&'ctx super::RemoteTables>, +} + +#[allow(non_camel_case_types)] +/// Extension trait for access to the table `pk_connection_id`. +/// +/// Implemented for [`super::RemoteTables`]. +pub trait PkConnectionIdTableAccess { + #[allow(non_snake_case)] + /// Obtain a [`PkConnectionIdTableHandle`], which mediates access to the table `pk_connection_id`. + fn pk_connection_id(&self) -> PkConnectionIdTableHandle<'_>; +} + +impl PkConnectionIdTableAccess for super::RemoteTables { + fn pk_connection_id(&self) -> PkConnectionIdTableHandle<'_> { + PkConnectionIdTableHandle { + imp: self.imp.get_table::("pk_connection_id"), + ctx: std::marker::PhantomData, + } + } +} + +pub struct PkConnectionIdInsertCallbackId(__sdk::CallbackId); +pub struct PkConnectionIdDeleteCallbackId(__sdk::CallbackId); + +impl<'ctx> __sdk::Table for PkConnectionIdTableHandle<'ctx> { + type Row = PkConnectionId; + type EventContext = super::EventContext; + + fn count(&self) -> u64 { + self.imp.count() + } + fn iter(&self) -> impl Iterator + '_ { + self.imp.iter() + } + + type InsertCallbackId = PkConnectionIdInsertCallbackId; + + fn on_insert( + &self, + callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, + ) -> PkConnectionIdInsertCallbackId { + PkConnectionIdInsertCallbackId(self.imp.on_insert(Box::new(callback))) + } + + fn remove_on_insert(&self, callback: PkConnectionIdInsertCallbackId) { + self.imp.remove_on_insert(callback.0) + } + + type DeleteCallbackId = PkConnectionIdDeleteCallbackId; + + fn on_delete( + &self, + callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, + ) -> PkConnectionIdDeleteCallbackId { + PkConnectionIdDeleteCallbackId(self.imp.on_delete(Box::new(callback))) + } + + fn remove_on_delete(&self, callback: PkConnectionIdDeleteCallbackId) { + self.imp.remove_on_delete(callback.0) + } +} + +#[doc(hidden)] +pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { + let _table = client_cache.get_or_make_table::("pk_connection_id"); + _table.add_unique_constraint::<__sdk::ConnectionId>("a", |row| &row.a); +} +pub struct PkConnectionIdUpdateCallbackId(__sdk::CallbackId); + +impl<'ctx> __sdk::TableWithPrimaryKey for PkConnectionIdTableHandle<'ctx> { + type UpdateCallbackId = PkConnectionIdUpdateCallbackId; + + fn on_update( + &self, + callback: impl FnMut(&Self::EventContext, &Self::Row, &Self::Row) + Send + 'static, + ) -> PkConnectionIdUpdateCallbackId { + PkConnectionIdUpdateCallbackId(self.imp.on_update(Box::new(callback))) + } + + fn remove_on_update(&self, callback: PkConnectionIdUpdateCallbackId) { + self.imp.remove_on_update(callback.0) + } +} + +#[doc(hidden)] +pub(super) fn parse_table_update( + raw_updates: __ws::TableUpdate<__ws::BsatnFormat>, +) -> __sdk::Result<__sdk::TableUpdate> { + __sdk::TableUpdate::parse_table_update_with_primary_key::<__sdk::ConnectionId>( + raw_updates, + |row: &PkConnectionId| &row.a, + ) + .map_err(|e| { + __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") + .with_cause(e) + .into() + }) +} + +/// Access to the `a` unique index on the table `pk_connection_id`, +/// which allows point queries on the field of the same name +/// via the [`PkConnectionIdAUnique::find`] method. +/// +/// Users are encouraged not to explicitly reference this type, +/// but to directly chain method calls, +/// like `ctx.db.pk_connection_id().a().find(...)`. +pub struct PkConnectionIdAUnique<'ctx> { + imp: __sdk::UniqueConstraintHandle, + phantom: std::marker::PhantomData<&'ctx super::RemoteTables>, +} + +impl<'ctx> PkConnectionIdTableHandle<'ctx> { + /// Get a handle on the `a` unique index on the table `pk_connection_id`. + pub fn a(&self) -> PkConnectionIdAUnique<'ctx> { + PkConnectionIdAUnique { + imp: self.imp.get_unique_constraint::<__sdk::ConnectionId>("a"), + phantom: std::marker::PhantomData, + } + } +} + +impl<'ctx> PkConnectionIdAUnique<'ctx> { + /// Find the subscribed row whose `a` column value is equal to `col_val`, + /// if such a row is present in the client cache. + pub fn find(&self, col_val: &__sdk::ConnectionId) -> Option { + self.imp.find(col_val) + } +} diff --git a/crates/sdk/tests/test-client/src/module_bindings/pk_address_type.rs b/crates/sdk/tests/test-client/src/module_bindings/pk_connection_id_type.rs similarity index 80% rename from crates/sdk/tests/test-client/src/module_bindings/pk_address_type.rs rename to crates/sdk/tests/test-client/src/module_bindings/pk_connection_id_type.rs index 344dcf12480..d4a71a4d790 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/pk_address_type.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/pk_connection_id_type.rs @@ -6,11 +6,11 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; #[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] #[sats(crate = __lib)] -pub struct PkAddress { - pub a: __sdk::Address, +pub struct PkConnectionId { + pub a: __sdk::ConnectionId, pub data: i32, } -impl __sdk::InModule for PkAddress { +impl __sdk::InModule for PkConnectionId { type Module = super::RemoteModule; } diff --git a/crates/sdk/tests/test-client/src/module_bindings/unique_address_table.rs b/crates/sdk/tests/test-client/src/module_bindings/unique_address_table.rs deleted file mode 100644 index 529b8aef9f5..00000000000 --- a/crates/sdk/tests/test-client/src/module_bindings/unique_address_table.rs +++ /dev/null @@ -1,125 +0,0 @@ -// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. - -#![allow(unused, clippy::all)] -use super::unique_address_type::UniqueAddress; -use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; - -/// Table handle for the table `unique_address`. -/// -/// Obtain a handle from the [`UniqueAddressTableAccess::unique_address`] method on [`super::RemoteTables`], -/// like `ctx.db.unique_address()`. -/// -/// Users are encouraged not to explicitly reference this type, -/// but to directly chain method calls, -/// like `ctx.db.unique_address().on_insert(...)`. -pub struct UniqueAddressTableHandle<'ctx> { - imp: __sdk::TableHandle, - ctx: std::marker::PhantomData<&'ctx super::RemoteTables>, -} - -#[allow(non_camel_case_types)] -/// Extension trait for access to the table `unique_address`. -/// -/// Implemented for [`super::RemoteTables`]. -pub trait UniqueAddressTableAccess { - #[allow(non_snake_case)] - /// Obtain a [`UniqueAddressTableHandle`], which mediates access to the table `unique_address`. - fn unique_address(&self) -> UniqueAddressTableHandle<'_>; -} - -impl UniqueAddressTableAccess for super::RemoteTables { - fn unique_address(&self) -> UniqueAddressTableHandle<'_> { - UniqueAddressTableHandle { - imp: self.imp.get_table::("unique_address"), - ctx: std::marker::PhantomData, - } - } -} - -pub struct UniqueAddressInsertCallbackId(__sdk::CallbackId); -pub struct UniqueAddressDeleteCallbackId(__sdk::CallbackId); - -impl<'ctx> __sdk::Table for UniqueAddressTableHandle<'ctx> { - type Row = UniqueAddress; - type EventContext = super::EventContext; - - fn count(&self) -> u64 { - self.imp.count() - } - fn iter(&self) -> impl Iterator + '_ { - self.imp.iter() - } - - type InsertCallbackId = UniqueAddressInsertCallbackId; - - fn on_insert( - &self, - callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, - ) -> UniqueAddressInsertCallbackId { - UniqueAddressInsertCallbackId(self.imp.on_insert(Box::new(callback))) - } - - fn remove_on_insert(&self, callback: UniqueAddressInsertCallbackId) { - self.imp.remove_on_insert(callback.0) - } - - type DeleteCallbackId = UniqueAddressDeleteCallbackId; - - fn on_delete( - &self, - callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, - ) -> UniqueAddressDeleteCallbackId { - UniqueAddressDeleteCallbackId(self.imp.on_delete(Box::new(callback))) - } - - fn remove_on_delete(&self, callback: UniqueAddressDeleteCallbackId) { - self.imp.remove_on_delete(callback.0) - } -} - -#[doc(hidden)] -pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { - let _table = client_cache.get_or_make_table::("unique_address"); - _table.add_unique_constraint::<__sdk::Address>("a", |row| &row.a); -} -#[doc(hidden)] -pub(super) fn parse_table_update( - raw_updates: __ws::TableUpdate<__ws::BsatnFormat>, -) -> __sdk::Result<__sdk::TableUpdate> { - __sdk::TableUpdate::parse_table_update_no_primary_key(raw_updates).map_err(|e| { - __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") - .with_cause(e) - .into() - }) -} - -/// Access to the `a` unique index on the table `unique_address`, -/// which allows point queries on the field of the same name -/// via the [`UniqueAddressAUnique::find`] method. -/// -/// Users are encouraged not to explicitly reference this type, -/// but to directly chain method calls, -/// like `ctx.db.unique_address().a().find(...)`. -pub struct UniqueAddressAUnique<'ctx> { - imp: __sdk::UniqueConstraintHandle, - phantom: std::marker::PhantomData<&'ctx super::RemoteTables>, -} - -impl<'ctx> UniqueAddressTableHandle<'ctx> { - /// Get a handle on the `a` unique index on the table `unique_address`. - pub fn a(&self) -> UniqueAddressAUnique<'ctx> { - UniqueAddressAUnique { - imp: self.imp.get_unique_constraint::<__sdk::Address>("a"), - phantom: std::marker::PhantomData, - } - } -} - -impl<'ctx> UniqueAddressAUnique<'ctx> { - /// Find the subscribed row whose `a` column value is equal to `col_val`, - /// if such a row is present in the client cache. - pub fn find(&self, col_val: &__sdk::Address) -> Option { - self.imp.find(col_val) - } -} diff --git a/crates/sdk/tests/test-client/src/module_bindings/unique_connection_id_table.rs b/crates/sdk/tests/test-client/src/module_bindings/unique_connection_id_table.rs new file mode 100644 index 00000000000..b675610a530 --- /dev/null +++ b/crates/sdk/tests/test-client/src/module_bindings/unique_connection_id_table.rs @@ -0,0 +1,125 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#![allow(unused, clippy::all)] +use super::unique_connection_id_type::UniqueConnectionId; +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +/// Table handle for the table `unique_connection_id`. +/// +/// Obtain a handle from the [`UniqueConnectionIdTableAccess::unique_connection_id`] method on [`super::RemoteTables`], +/// like `ctx.db.unique_connection_id()`. +/// +/// Users are encouraged not to explicitly reference this type, +/// but to directly chain method calls, +/// like `ctx.db.unique_connection_id().on_insert(...)`. +pub struct UniqueConnectionIdTableHandle<'ctx> { + imp: __sdk::TableHandle, + ctx: std::marker::PhantomData<&'ctx super::RemoteTables>, +} + +#[allow(non_camel_case_types)] +/// Extension trait for access to the table `unique_connection_id`. +/// +/// Implemented for [`super::RemoteTables`]. +pub trait UniqueConnectionIdTableAccess { + #[allow(non_snake_case)] + /// Obtain a [`UniqueConnectionIdTableHandle`], which mediates access to the table `unique_connection_id`. + fn unique_connection_id(&self) -> UniqueConnectionIdTableHandle<'_>; +} + +impl UniqueConnectionIdTableAccess for super::RemoteTables { + fn unique_connection_id(&self) -> UniqueConnectionIdTableHandle<'_> { + UniqueConnectionIdTableHandle { + imp: self.imp.get_table::("unique_connection_id"), + ctx: std::marker::PhantomData, + } + } +} + +pub struct UniqueConnectionIdInsertCallbackId(__sdk::CallbackId); +pub struct UniqueConnectionIdDeleteCallbackId(__sdk::CallbackId); + +impl<'ctx> __sdk::Table for UniqueConnectionIdTableHandle<'ctx> { + type Row = UniqueConnectionId; + type EventContext = super::EventContext; + + fn count(&self) -> u64 { + self.imp.count() + } + fn iter(&self) -> impl Iterator + '_ { + self.imp.iter() + } + + type InsertCallbackId = UniqueConnectionIdInsertCallbackId; + + fn on_insert( + &self, + callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, + ) -> UniqueConnectionIdInsertCallbackId { + UniqueConnectionIdInsertCallbackId(self.imp.on_insert(Box::new(callback))) + } + + fn remove_on_insert(&self, callback: UniqueConnectionIdInsertCallbackId) { + self.imp.remove_on_insert(callback.0) + } + + type DeleteCallbackId = UniqueConnectionIdDeleteCallbackId; + + fn on_delete( + &self, + callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, + ) -> UniqueConnectionIdDeleteCallbackId { + UniqueConnectionIdDeleteCallbackId(self.imp.on_delete(Box::new(callback))) + } + + fn remove_on_delete(&self, callback: UniqueConnectionIdDeleteCallbackId) { + self.imp.remove_on_delete(callback.0) + } +} + +#[doc(hidden)] +pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { + let _table = client_cache.get_or_make_table::("unique_connection_id"); + _table.add_unique_constraint::<__sdk::ConnectionId>("a", |row| &row.a); +} +#[doc(hidden)] +pub(super) fn parse_table_update( + raw_updates: __ws::TableUpdate<__ws::BsatnFormat>, +) -> __sdk::Result<__sdk::TableUpdate> { + __sdk::TableUpdate::parse_table_update_no_primary_key(raw_updates).map_err(|e| { + __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") + .with_cause(e) + .into() + }) +} + +/// Access to the `a` unique index on the table `unique_connection_id`, +/// which allows point queries on the field of the same name +/// via the [`UniqueConnectionIdAUnique::find`] method. +/// +/// Users are encouraged not to explicitly reference this type, +/// but to directly chain method calls, +/// like `ctx.db.unique_connection_id().a().find(...)`. +pub struct UniqueConnectionIdAUnique<'ctx> { + imp: __sdk::UniqueConstraintHandle, + phantom: std::marker::PhantomData<&'ctx super::RemoteTables>, +} + +impl<'ctx> UniqueConnectionIdTableHandle<'ctx> { + /// Get a handle on the `a` unique index on the table `unique_connection_id`. + pub fn a(&self) -> UniqueConnectionIdAUnique<'ctx> { + UniqueConnectionIdAUnique { + imp: self.imp.get_unique_constraint::<__sdk::ConnectionId>("a"), + phantom: std::marker::PhantomData, + } + } +} + +impl<'ctx> UniqueConnectionIdAUnique<'ctx> { + /// Find the subscribed row whose `a` column value is equal to `col_val`, + /// if such a row is present in the client cache. + pub fn find(&self, col_val: &__sdk::ConnectionId) -> Option { + self.imp.find(col_val) + } +} diff --git a/crates/sdk/tests/test-client/src/module_bindings/unique_address_type.rs b/crates/sdk/tests/test-client/src/module_bindings/unique_connection_id_type.rs similarity index 79% rename from crates/sdk/tests/test-client/src/module_bindings/unique_address_type.rs rename to crates/sdk/tests/test-client/src/module_bindings/unique_connection_id_type.rs index b11e83996aa..91f6b6bcfc0 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/unique_address_type.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/unique_connection_id_type.rs @@ -6,11 +6,11 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; #[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] #[sats(crate = __lib)] -pub struct UniqueAddress { - pub a: __sdk::Address, +pub struct UniqueConnectionId { + pub a: __sdk::ConnectionId, pub data: i32, } -impl __sdk::InModule for UniqueAddress { +impl __sdk::InModule for UniqueConnectionId { type Module = super::RemoteModule; } diff --git a/crates/sdk/tests/test-client/src/module_bindings/update_pk_address_reducer.rs b/crates/sdk/tests/test-client/src/module_bindings/update_pk_connection_id_reducer.rs similarity index 50% rename from crates/sdk/tests/test-client/src/module_bindings/update_pk_address_reducer.rs rename to crates/sdk/tests/test-client/src/module_bindings/update_pk_connection_id_reducer.rs index c2cd6ba9d33..e6971b4c880 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/update_pk_address_reducer.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/update_pk_connection_id_reducer.rs @@ -6,69 +6,69 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; #[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] #[sats(crate = __lib)] -pub(super) struct UpdatePkAddressArgs { - pub a: __sdk::Address, +pub(super) struct UpdatePkConnectionIdArgs { + pub a: __sdk::ConnectionId, pub data: i32, } -impl From for super::Reducer { - fn from(args: UpdatePkAddressArgs) -> Self { - Self::UpdatePkAddress { +impl From for super::Reducer { + fn from(args: UpdatePkConnectionIdArgs) -> Self { + Self::UpdatePkConnectionId { a: args.a, data: args.data, } } } -impl __sdk::InModule for UpdatePkAddressArgs { +impl __sdk::InModule for UpdatePkConnectionIdArgs { type Module = super::RemoteModule; } -pub struct UpdatePkAddressCallbackId(__sdk::CallbackId); +pub struct UpdatePkConnectionIdCallbackId(__sdk::CallbackId); #[allow(non_camel_case_types)] -/// Extension trait for access to the reducer `update_pk_address`. +/// Extension trait for access to the reducer `update_pk_connection_id`. /// /// Implemented for [`super::RemoteReducers`]. -pub trait update_pk_address { - /// Request that the remote module invoke the reducer `update_pk_address` to run as soon as possible. +pub trait update_pk_connection_id { + /// Request that the remote module invoke the reducer `update_pk_connection_id` to run as soon as possible. /// /// This method returns immediately, and errors only if we are unable to send the request. /// The reducer will run asynchronously in the future, - /// and its status can be observed by listening for [`Self::on_update_pk_address`] callbacks. - fn update_pk_address(&self, a: __sdk::Address, data: i32) -> __sdk::Result<()>; - /// Register a callback to run whenever we are notified of an invocation of the reducer `update_pk_address`. + /// and its status can be observed by listening for [`Self::on_update_pk_connection_id`] callbacks. + fn update_pk_connection_id(&self, a: __sdk::ConnectionId, data: i32) -> __sdk::Result<()>; + /// Register a callback to run whenever we are notified of an invocation of the reducer `update_pk_connection_id`. /// /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] /// to determine the reducer's status. /// - /// The returned [`UpdatePkAddressCallbackId`] can be passed to [`Self::remove_on_update_pk_address`] + /// The returned [`UpdatePkConnectionIdCallbackId`] can be passed to [`Self::remove_on_update_pk_connection_id`] /// to cancel the callback. - fn on_update_pk_address( + fn on_update_pk_connection_id( &self, - callback: impl FnMut(&super::ReducerEventContext, &__sdk::Address, &i32) + Send + 'static, - ) -> UpdatePkAddressCallbackId; - /// Cancel a callback previously registered by [`Self::on_update_pk_address`], + callback: impl FnMut(&super::ReducerEventContext, &__sdk::ConnectionId, &i32) + Send + 'static, + ) -> UpdatePkConnectionIdCallbackId; + /// Cancel a callback previously registered by [`Self::on_update_pk_connection_id`], /// causing it not to run in the future. - fn remove_on_update_pk_address(&self, callback: UpdatePkAddressCallbackId); + fn remove_on_update_pk_connection_id(&self, callback: UpdatePkConnectionIdCallbackId); } -impl update_pk_address for super::RemoteReducers { - fn update_pk_address(&self, a: __sdk::Address, data: i32) -> __sdk::Result<()> { +impl update_pk_connection_id for super::RemoteReducers { + fn update_pk_connection_id(&self, a: __sdk::ConnectionId, data: i32) -> __sdk::Result<()> { self.imp - .call_reducer("update_pk_address", UpdatePkAddressArgs { a, data }) + .call_reducer("update_pk_connection_id", UpdatePkConnectionIdArgs { a, data }) } - fn on_update_pk_address( + fn on_update_pk_connection_id( &self, - mut callback: impl FnMut(&super::ReducerEventContext, &__sdk::Address, &i32) + Send + 'static, - ) -> UpdatePkAddressCallbackId { - UpdatePkAddressCallbackId(self.imp.on_reducer( - "update_pk_address", + mut callback: impl FnMut(&super::ReducerEventContext, &__sdk::ConnectionId, &i32) + Send + 'static, + ) -> UpdatePkConnectionIdCallbackId { + UpdatePkConnectionIdCallbackId(self.imp.on_reducer( + "update_pk_connection_id", Box::new(move |ctx: &super::ReducerEventContext| { let super::ReducerEventContext { event: __sdk::ReducerEvent { - reducer: super::Reducer::UpdatePkAddress { a, data }, + reducer: super::Reducer::UpdatePkConnectionId { a, data }, .. }, .. @@ -80,27 +80,27 @@ impl update_pk_address for super::RemoteReducers { }), )) } - fn remove_on_update_pk_address(&self, callback: UpdatePkAddressCallbackId) { - self.imp.remove_on_reducer("update_pk_address", callback.0) + fn remove_on_update_pk_connection_id(&self, callback: UpdatePkConnectionIdCallbackId) { + self.imp.remove_on_reducer("update_pk_connection_id", callback.0) } } #[allow(non_camel_case_types)] #[doc(hidden)] -/// Extension trait for setting the call-flags for the reducer `update_pk_address`. +/// Extension trait for setting the call-flags for the reducer `update_pk_connection_id`. /// /// Implemented for [`super::SetReducerFlags`]. /// /// This type is currently unstable and may be removed without a major version bump. -pub trait set_flags_for_update_pk_address { - /// Set the call-reducer flags for the reducer `update_pk_address` to `flags`. +pub trait set_flags_for_update_pk_connection_id { + /// Set the call-reducer flags for the reducer `update_pk_connection_id` to `flags`. /// /// This type is currently unstable and may be removed without a major version bump. - fn update_pk_address(&self, flags: __ws::CallReducerFlags); + fn update_pk_connection_id(&self, flags: __ws::CallReducerFlags); } -impl set_flags_for_update_pk_address for super::SetReducerFlags { - fn update_pk_address(&self, flags: __ws::CallReducerFlags) { - self.imp.set_call_reducer_flags("update_pk_address", flags); +impl set_flags_for_update_pk_connection_id for super::SetReducerFlags { + fn update_pk_connection_id(&self, flags: __ws::CallReducerFlags) { + self.imp.set_call_reducer_flags("update_pk_connection_id", flags); } } diff --git a/crates/sdk/tests/test-client/src/module_bindings/update_unique_address_reducer.rs b/crates/sdk/tests/test-client/src/module_bindings/update_unique_connection_id_reducer.rs similarity index 51% rename from crates/sdk/tests/test-client/src/module_bindings/update_unique_address_reducer.rs rename to crates/sdk/tests/test-client/src/module_bindings/update_unique_connection_id_reducer.rs index 08a8f24ac20..4d30bcde78d 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/update_unique_address_reducer.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/update_unique_connection_id_reducer.rs @@ -6,69 +6,69 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; #[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] #[sats(crate = __lib)] -pub(super) struct UpdateUniqueAddressArgs { - pub a: __sdk::Address, +pub(super) struct UpdateUniqueConnectionIdArgs { + pub a: __sdk::ConnectionId, pub data: i32, } -impl From for super::Reducer { - fn from(args: UpdateUniqueAddressArgs) -> Self { - Self::UpdateUniqueAddress { +impl From for super::Reducer { + fn from(args: UpdateUniqueConnectionIdArgs) -> Self { + Self::UpdateUniqueConnectionId { a: args.a, data: args.data, } } } -impl __sdk::InModule for UpdateUniqueAddressArgs { +impl __sdk::InModule for UpdateUniqueConnectionIdArgs { type Module = super::RemoteModule; } -pub struct UpdateUniqueAddressCallbackId(__sdk::CallbackId); +pub struct UpdateUniqueConnectionIdCallbackId(__sdk::CallbackId); #[allow(non_camel_case_types)] -/// Extension trait for access to the reducer `update_unique_address`. +/// Extension trait for access to the reducer `update_unique_connection_id`. /// /// Implemented for [`super::RemoteReducers`]. -pub trait update_unique_address { - /// Request that the remote module invoke the reducer `update_unique_address` to run as soon as possible. +pub trait update_unique_connection_id { + /// Request that the remote module invoke the reducer `update_unique_connection_id` to run as soon as possible. /// /// This method returns immediately, and errors only if we are unable to send the request. /// The reducer will run asynchronously in the future, - /// and its status can be observed by listening for [`Self::on_update_unique_address`] callbacks. - fn update_unique_address(&self, a: __sdk::Address, data: i32) -> __sdk::Result<()>; - /// Register a callback to run whenever we are notified of an invocation of the reducer `update_unique_address`. + /// and its status can be observed by listening for [`Self::on_update_unique_connection_id`] callbacks. + fn update_unique_connection_id(&self, a: __sdk::ConnectionId, data: i32) -> __sdk::Result<()>; + /// Register a callback to run whenever we are notified of an invocation of the reducer `update_unique_connection_id`. /// /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] /// to determine the reducer's status. /// - /// The returned [`UpdateUniqueAddressCallbackId`] can be passed to [`Self::remove_on_update_unique_address`] + /// The returned [`UpdateUniqueConnectionIdCallbackId`] can be passed to [`Self::remove_on_update_unique_connection_id`] /// to cancel the callback. - fn on_update_unique_address( + fn on_update_unique_connection_id( &self, - callback: impl FnMut(&super::ReducerEventContext, &__sdk::Address, &i32) + Send + 'static, - ) -> UpdateUniqueAddressCallbackId; - /// Cancel a callback previously registered by [`Self::on_update_unique_address`], + callback: impl FnMut(&super::ReducerEventContext, &__sdk::ConnectionId, &i32) + Send + 'static, + ) -> UpdateUniqueConnectionIdCallbackId; + /// Cancel a callback previously registered by [`Self::on_update_unique_connection_id`], /// causing it not to run in the future. - fn remove_on_update_unique_address(&self, callback: UpdateUniqueAddressCallbackId); + fn remove_on_update_unique_connection_id(&self, callback: UpdateUniqueConnectionIdCallbackId); } -impl update_unique_address for super::RemoteReducers { - fn update_unique_address(&self, a: __sdk::Address, data: i32) -> __sdk::Result<()> { +impl update_unique_connection_id for super::RemoteReducers { + fn update_unique_connection_id(&self, a: __sdk::ConnectionId, data: i32) -> __sdk::Result<()> { self.imp - .call_reducer("update_unique_address", UpdateUniqueAddressArgs { a, data }) + .call_reducer("update_unique_connection_id", UpdateUniqueConnectionIdArgs { a, data }) } - fn on_update_unique_address( + fn on_update_unique_connection_id( &self, - mut callback: impl FnMut(&super::ReducerEventContext, &__sdk::Address, &i32) + Send + 'static, - ) -> UpdateUniqueAddressCallbackId { - UpdateUniqueAddressCallbackId(self.imp.on_reducer( - "update_unique_address", + mut callback: impl FnMut(&super::ReducerEventContext, &__sdk::ConnectionId, &i32) + Send + 'static, + ) -> UpdateUniqueConnectionIdCallbackId { + UpdateUniqueConnectionIdCallbackId(self.imp.on_reducer( + "update_unique_connection_id", Box::new(move |ctx: &super::ReducerEventContext| { let super::ReducerEventContext { event: __sdk::ReducerEvent { - reducer: super::Reducer::UpdateUniqueAddress { a, data }, + reducer: super::Reducer::UpdateUniqueConnectionId { a, data }, .. }, .. @@ -80,27 +80,27 @@ impl update_unique_address for super::RemoteReducers { }), )) } - fn remove_on_update_unique_address(&self, callback: UpdateUniqueAddressCallbackId) { - self.imp.remove_on_reducer("update_unique_address", callback.0) + fn remove_on_update_unique_connection_id(&self, callback: UpdateUniqueConnectionIdCallbackId) { + self.imp.remove_on_reducer("update_unique_connection_id", callback.0) } } #[allow(non_camel_case_types)] #[doc(hidden)] -/// Extension trait for setting the call-flags for the reducer `update_unique_address`. +/// Extension trait for setting the call-flags for the reducer `update_unique_connection_id`. /// /// Implemented for [`super::SetReducerFlags`]. /// /// This type is currently unstable and may be removed without a major version bump. -pub trait set_flags_for_update_unique_address { - /// Set the call-reducer flags for the reducer `update_unique_address` to `flags`. +pub trait set_flags_for_update_unique_connection_id { + /// Set the call-reducer flags for the reducer `update_unique_connection_id` to `flags`. /// /// This type is currently unstable and may be removed without a major version bump. - fn update_unique_address(&self, flags: __ws::CallReducerFlags); + fn update_unique_connection_id(&self, flags: __ws::CallReducerFlags); } -impl set_flags_for_update_unique_address for super::SetReducerFlags { - fn update_unique_address(&self, flags: __ws::CallReducerFlags) { - self.imp.set_call_reducer_flags("update_unique_address", flags); +impl set_flags_for_update_unique_connection_id for super::SetReducerFlags { + fn update_unique_connection_id(&self, flags: __ws::CallReducerFlags) { + self.imp.set_call_reducer_flags("update_unique_connection_id", flags); } } diff --git a/crates/sdk/tests/test-client/src/module_bindings/vec_address_table.rs b/crates/sdk/tests/test-client/src/module_bindings/vec_address_table.rs deleted file mode 100644 index ce8740f525a..00000000000 --- a/crates/sdk/tests/test-client/src/module_bindings/vec_address_table.rs +++ /dev/null @@ -1,94 +0,0 @@ -// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. - -#![allow(unused, clippy::all)] -use super::vec_address_type::VecAddress; -use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; - -/// Table handle for the table `vec_address`. -/// -/// Obtain a handle from the [`VecAddressTableAccess::vec_address`] method on [`super::RemoteTables`], -/// like `ctx.db.vec_address()`. -/// -/// Users are encouraged not to explicitly reference this type, -/// but to directly chain method calls, -/// like `ctx.db.vec_address().on_insert(...)`. -pub struct VecAddressTableHandle<'ctx> { - imp: __sdk::TableHandle, - ctx: std::marker::PhantomData<&'ctx super::RemoteTables>, -} - -#[allow(non_camel_case_types)] -/// Extension trait for access to the table `vec_address`. -/// -/// Implemented for [`super::RemoteTables`]. -pub trait VecAddressTableAccess { - #[allow(non_snake_case)] - /// Obtain a [`VecAddressTableHandle`], which mediates access to the table `vec_address`. - fn vec_address(&self) -> VecAddressTableHandle<'_>; -} - -impl VecAddressTableAccess for super::RemoteTables { - fn vec_address(&self) -> VecAddressTableHandle<'_> { - VecAddressTableHandle { - imp: self.imp.get_table::("vec_address"), - ctx: std::marker::PhantomData, - } - } -} - -pub struct VecAddressInsertCallbackId(__sdk::CallbackId); -pub struct VecAddressDeleteCallbackId(__sdk::CallbackId); - -impl<'ctx> __sdk::Table for VecAddressTableHandle<'ctx> { - type Row = VecAddress; - type EventContext = super::EventContext; - - fn count(&self) -> u64 { - self.imp.count() - } - fn iter(&self) -> impl Iterator + '_ { - self.imp.iter() - } - - type InsertCallbackId = VecAddressInsertCallbackId; - - fn on_insert( - &self, - callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, - ) -> VecAddressInsertCallbackId { - VecAddressInsertCallbackId(self.imp.on_insert(Box::new(callback))) - } - - fn remove_on_insert(&self, callback: VecAddressInsertCallbackId) { - self.imp.remove_on_insert(callback.0) - } - - type DeleteCallbackId = VecAddressDeleteCallbackId; - - fn on_delete( - &self, - callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, - ) -> VecAddressDeleteCallbackId { - VecAddressDeleteCallbackId(self.imp.on_delete(Box::new(callback))) - } - - fn remove_on_delete(&self, callback: VecAddressDeleteCallbackId) { - self.imp.remove_on_delete(callback.0) - } -} - -#[doc(hidden)] -pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { - let _table = client_cache.get_or_make_table::("vec_address"); -} -#[doc(hidden)] -pub(super) fn parse_table_update( - raw_updates: __ws::TableUpdate<__ws::BsatnFormat>, -) -> __sdk::Result<__sdk::TableUpdate> { - __sdk::TableUpdate::parse_table_update_no_primary_key(raw_updates).map_err(|e| { - __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") - .with_cause(e) - .into() - }) -} diff --git a/crates/sdk/tests/test-client/src/module_bindings/vec_connection_id_table.rs b/crates/sdk/tests/test-client/src/module_bindings/vec_connection_id_table.rs new file mode 100644 index 00000000000..35a35f3096d --- /dev/null +++ b/crates/sdk/tests/test-client/src/module_bindings/vec_connection_id_table.rs @@ -0,0 +1,94 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#![allow(unused, clippy::all)] +use super::vec_connection_id_type::VecConnectionId; +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +/// Table handle for the table `vec_connection_id`. +/// +/// Obtain a handle from the [`VecConnectionIdTableAccess::vec_connection_id`] method on [`super::RemoteTables`], +/// like `ctx.db.vec_connection_id()`. +/// +/// Users are encouraged not to explicitly reference this type, +/// but to directly chain method calls, +/// like `ctx.db.vec_connection_id().on_insert(...)`. +pub struct VecConnectionIdTableHandle<'ctx> { + imp: __sdk::TableHandle, + ctx: std::marker::PhantomData<&'ctx super::RemoteTables>, +} + +#[allow(non_camel_case_types)] +/// Extension trait for access to the table `vec_connection_id`. +/// +/// Implemented for [`super::RemoteTables`]. +pub trait VecConnectionIdTableAccess { + #[allow(non_snake_case)] + /// Obtain a [`VecConnectionIdTableHandle`], which mediates access to the table `vec_connection_id`. + fn vec_connection_id(&self) -> VecConnectionIdTableHandle<'_>; +} + +impl VecConnectionIdTableAccess for super::RemoteTables { + fn vec_connection_id(&self) -> VecConnectionIdTableHandle<'_> { + VecConnectionIdTableHandle { + imp: self.imp.get_table::("vec_connection_id"), + ctx: std::marker::PhantomData, + } + } +} + +pub struct VecConnectionIdInsertCallbackId(__sdk::CallbackId); +pub struct VecConnectionIdDeleteCallbackId(__sdk::CallbackId); + +impl<'ctx> __sdk::Table for VecConnectionIdTableHandle<'ctx> { + type Row = VecConnectionId; + type EventContext = super::EventContext; + + fn count(&self) -> u64 { + self.imp.count() + } + fn iter(&self) -> impl Iterator + '_ { + self.imp.iter() + } + + type InsertCallbackId = VecConnectionIdInsertCallbackId; + + fn on_insert( + &self, + callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, + ) -> VecConnectionIdInsertCallbackId { + VecConnectionIdInsertCallbackId(self.imp.on_insert(Box::new(callback))) + } + + fn remove_on_insert(&self, callback: VecConnectionIdInsertCallbackId) { + self.imp.remove_on_insert(callback.0) + } + + type DeleteCallbackId = VecConnectionIdDeleteCallbackId; + + fn on_delete( + &self, + callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, + ) -> VecConnectionIdDeleteCallbackId { + VecConnectionIdDeleteCallbackId(self.imp.on_delete(Box::new(callback))) + } + + fn remove_on_delete(&self, callback: VecConnectionIdDeleteCallbackId) { + self.imp.remove_on_delete(callback.0) + } +} + +#[doc(hidden)] +pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { + let _table = client_cache.get_or_make_table::("vec_connection_id"); +} +#[doc(hidden)] +pub(super) fn parse_table_update( + raw_updates: __ws::TableUpdate<__ws::BsatnFormat>, +) -> __sdk::Result<__sdk::TableUpdate> { + __sdk::TableUpdate::parse_table_update_no_primary_key(raw_updates).map_err(|e| { + __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") + .with_cause(e) + .into() + }) +} diff --git a/crates/sdk/tests/test-client/src/module_bindings/vec_address_type.rs b/crates/sdk/tests/test-client/src/module_bindings/vec_connection_id_type.rs similarity index 78% rename from crates/sdk/tests/test-client/src/module_bindings/vec_address_type.rs rename to crates/sdk/tests/test-client/src/module_bindings/vec_connection_id_type.rs index d550a425f05..b27bed828be 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/vec_address_type.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/vec_connection_id_type.rs @@ -6,10 +6,10 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; #[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] #[sats(crate = __lib)] -pub struct VecAddress { - pub a: Vec<__sdk::Address>, +pub struct VecConnectionId { + pub a: Vec<__sdk::ConnectionId>, } -impl __sdk::InModule for VecAddress { +impl __sdk::InModule for VecConnectionId { type Module = super::RemoteModule; } diff --git a/crates/sdk/tests/test-client/src/pk_test_table.rs b/crates/sdk/tests/test-client/src/pk_test_table.rs index d113c5ed6be..f72b5f84a6d 100644 --- a/crates/sdk/tests/test-client/src/pk_test_table.rs +++ b/crates/sdk/tests/test-client/src/pk_test_table.rs @@ -1,5 +1,5 @@ use crate::module_bindings::*; -use spacetimedb_sdk::{i256, u256, Address, Event, Identity, Table, TableWithPrimaryKey}; +use spacetimedb_sdk::{i256, u256, ConnectionId, Event, Identity, Table, TableWithPrimaryKey}; use std::sync::Arc; use test_counter::TestCounter; @@ -368,16 +368,16 @@ impl_pk_test_table! { accessor_method = pk_identity; } - PkAddress { - Key = Address; + PkConnectionId { + Key = ConnectionId; key_field_name = a; - insert_reducer = insert_pk_address; - insert_reducer_event = InsertPkAddress; - delete_reducer = delete_pk_address; - delete_reducer_event = DeletePkAddress; - update_reducer = update_pk_address; - update_reducer_event = UpdatePkAddress; - accessor_method = pk_address; + insert_reducer = insert_pk_connection_id; + insert_reducer_event = InsertPkConnectionId; + delete_reducer = delete_pk_connection_id; + delete_reducer_event = DeletePkConnectionId; + update_reducer = update_pk_connection_id; + update_reducer_event = UpdatePkConnectionId; + accessor_method = pk_connection_id; } } diff --git a/crates/sdk/tests/test-client/src/simple_test_table.rs b/crates/sdk/tests/test-client/src/simple_test_table.rs index a66ff9b8faa..60a06eaa2cf 100644 --- a/crates/sdk/tests/test-client/src/simple_test_table.rs +++ b/crates/sdk/tests/test-client/src/simple_test_table.rs @@ -1,5 +1,5 @@ use crate::module_bindings::*; -use spacetimedb_sdk::{i256, u256, Address, Event, Identity, Table, Timestamp}; +use spacetimedb_sdk::{i256, u256, ConnectionId, Event, Identity, Table, Timestamp}; use std::sync::{ atomic::{AtomicUsize, Ordering}, Arc, @@ -177,12 +177,12 @@ impl_simple_test_table! { accessor_method = one_identity; } - OneAddress { - Contents = Address; + OneConnectionId { + Contents = ConnectionId; field_name = a; - insert_reducer = insert_one_address; - insert_reducer_event = InsertOneAddress; - accessor_method = one_address; + insert_reducer = insert_one_connection_id; + insert_reducer_event = InsertOneConnectionId; + accessor_method = one_connection_id; } OneTimestamp { @@ -362,12 +362,12 @@ impl_simple_test_table! { accessor_method = vec_identity; } - VecAddress { - Contents = Vec
; + VecConnectionId { + Contents = Vec; field_name = a; - insert_reducer = insert_vec_address; - insert_reducer_event = InsertVecAddress; - accessor_method = vec_address; + insert_reducer = insert_vec_connection_id; + insert_reducer_event = InsertVecConnectionId; + accessor_method = vec_connection_id; } VecTimestamp { diff --git a/crates/sdk/tests/test-client/src/unique_test_table.rs b/crates/sdk/tests/test-client/src/unique_test_table.rs index 1ca1bf65005..58852625e48 100644 --- a/crates/sdk/tests/test-client/src/unique_test_table.rs +++ b/crates/sdk/tests/test-client/src/unique_test_table.rs @@ -1,5 +1,5 @@ use crate::module_bindings::*; -use spacetimedb_sdk::{i256, u256, Address, Event, Identity, Table}; +use spacetimedb_sdk::{i256, u256, ConnectionId, Event, Identity, Table}; use std::sync::Arc; use test_counter::TestCounter; @@ -280,13 +280,13 @@ impl_unique_test_table! { accessor_method = unique_identity; } - UniqueAddress { - Key = Address; + UniqueConnectionId { + Key = ConnectionId; key_field_name = a; - insert_reducer = insert_unique_address; - insert_reducer_event = InsertUniqueAddress; - delete_reducer = delete_unique_address; - delete_reducer_event = DeleteUniqueAddress; - accessor_method = unique_address; + insert_reducer = insert_unique_connection_id; + insert_reducer_event = InsertUniqueConnectionId; + delete_reducer = delete_unique_connection_id; + delete_reducer_event = DeleteUniqueConnectionId; + accessor_method = unique_connection_id; } } diff --git a/crates/sdk/tests/test.rs b/crates/sdk/tests/test.rs index 85e0d3decba..1932fdd84cb 100644 --- a/crates/sdk/tests/test.rs +++ b/crates/sdk/tests/test.rs @@ -68,23 +68,23 @@ macro_rules! declare_tests_with_suffix { } #[test] - fn insert_address() { - make_test("insert_address").run(); + fn insert_connection_id() { + make_test("insert_connection_id").run(); } #[test] - fn insert_caller_address() { - make_test("insert_caller_address").run(); + fn insert_caller_connection_id() { + make_test("insert_caller_connection_id").run(); } #[test] - fn delete_address() { - make_test("delete_address").run(); + fn delete_connection_id() { + make_test("delete_connection_id").run(); } #[test] - fn update_address() { - make_test("delete_address").run(); + fn update_connection_id() { + make_test("delete_connection_id").run(); } #[test] @@ -165,8 +165,8 @@ macro_rules! declare_tests_with_suffix { } #[test] - fn reconnect_same_address() { - make_test("reconnect_same_address").run(); + fn reconnect_same_connection_id() { + make_test("reconnect_same_connection_id").run(); } #[test] diff --git a/crates/snapshot/src/lib.rs b/crates/snapshot/src/lib.rs index 552f91884f8..41341e5cfac 100644 --- a/crates/snapshot/src/lib.rs +++ b/crates/snapshot/src/lib.rs @@ -467,7 +467,7 @@ pub struct SnapshotRepository { /// The directory which contains all the snapshots. root: SnapshotsPath, - /// The database address of the database instance for which this repository stores snapshots. + /// The database identity of the database instance for which this repository stores snapshots. database_identity: Identity, /// The database instance ID of the database instance for which this repository stores snapshots. @@ -478,7 +478,7 @@ pub struct SnapshotRepository { } impl SnapshotRepository { - /// Returns [`Address`] of the database this [`SnapshotRepository`] is configured to snapshot. + /// Returns the [`Identity`] of the database this [`SnapshotRepository`] is configured to snapshot. pub fn database_identity(&self) -> Identity { self.database_identity } @@ -637,12 +637,12 @@ impl SnapshotRepository { /// - The snapshot file's version does not match [`CURRENT_SNAPSHOT_VERSION`]. /// /// The following conditions are not detected or considered as errors: - /// - The snapshot file's database address or instance ID do not match those in `self`. + /// - The snapshot file's database identity or instance ID do not match those in `self`. /// - The snapshot file's module ABI version does not match [`CURRENT_MODULE_ABI_VERSION`]. /// - The snapshot file's recorded transaction offset does not match `tx_offset`. /// /// This means that callers must inspect the returned [`ReconstructedSnapshot`] - /// and verify that they can handle its contained database address, instance ID, module ABI version and transaction offset. + /// and verify that they can handle its contained database identity, instance ID, module ABI version and transaction offset. pub fn read_snapshot(&self, tx_offset: TxOffset) -> Result { let snapshot_dir = self.snapshot_dir_path(tx_offset); let lockfile = Lockfile::lock_path(&snapshot_dir); @@ -774,7 +774,7 @@ impl SnapshotRepository { } pub struct ReconstructedSnapshot { - /// The address of the snapshotted database. + /// The identity of the snapshotted database. pub database_identity: Identity, /// The instance ID of the snapshotted database. pub replica_id: u64, diff --git a/crates/standalone/src/control_db.rs b/crates/standalone/src/control_db.rs index ce442965d7a..e672c859d97 100644 --- a/crates/standalone/src/control_db.rs +++ b/crates/standalone/src/control_db.rs @@ -13,9 +13,9 @@ mod tests; /// A control database when SpacetimeDB is running standalone. /// -/// Important note: The `Addresses` and `Identities` stored in this database +/// Important note: The `ConnectionId`s and `Identity`s stored in this database /// are stored as *LITTLE-ENDIAN* byte arrays. This means that printing such an array -/// in hexadecimal will result in the REVERSE of the standard way to print `Addresses` and `Identities`. +/// in hexadecimal will result in the REVERSE of the standard way to print `ConnectionId`s and `Identity`s. #[derive(Clone)] pub struct ControlDb { db: sled::Db, diff --git a/crates/standalone/src/lib.rs b/crates/standalone/src/lib.rs index adbba99a6d1..67b1b8d8a4f 100644 --- a/crates/standalone/src/lib.rs +++ b/crates/standalone/src/lib.rs @@ -51,7 +51,7 @@ impl StandaloneEnv { let meta = MetadataFile { version: spacetimedb::config::current_version(), edition: "standalone".to_owned(), - client_address: None, + client_connection_id: None, }; if let Some(existing_meta) = MetadataFile::read(&meta_path).context("failed reading metadata.toml")? { anyhow::ensure!( diff --git a/crates/table/src/memory_usage.rs b/crates/table/src/memory_usage.rs index e9c0066deb8..6822f2f3a41 100644 --- a/crates/table/src/memory_usage.rs +++ b/crates/table/src/memory_usage.rs @@ -235,5 +235,5 @@ impl MemoryUsage for Packed { } } -impl MemoryUsage for spacetimedb_lib::Address {} +impl MemoryUsage for spacetimedb_lib::ConnectionId {} impl MemoryUsage for spacetimedb_lib::Identity {} diff --git a/crates/testing/src/modules.rs b/crates/testing/src/modules.rs index c027200e645..d3d4ede2578 100644 --- a/crates/testing/src/modules.rs +++ b/crates/testing/src/modules.rs @@ -9,7 +9,7 @@ use spacetimedb::config::CertificateAuthority; use spacetimedb::messages::control_db::HostType; use spacetimedb::Identity; use spacetimedb_client_api::auth::SpacetimeAuth; -use spacetimedb_client_api::routes::subscribe::generate_random_address; +use spacetimedb_client_api::routes::subscribe::generate_random_connection_id; use spacetimedb_paths::{RootDir, SpacetimePaths}; use tokio::runtime::{Builder, Runtime}; @@ -169,7 +169,7 @@ impl CompiledModule { // TODO: Fix this when we update identity generation. let identity = Identity::ZERO; let db_identity = SpacetimeAuth::alloc(&env).await.unwrap().identity; - let client_address = generate_random_address(); + let connection_id = generate_random_connection_id(); let program_bytes = self .program_bytes @@ -193,7 +193,7 @@ impl CompiledModule { let client_id = ClientActorId { identity, - address: client_address, + connection_id, name: env.client_actor_index().next_client_name(), }; diff --git a/crates/testing/src/sdk.rs b/crates/testing/src/sdk.rs index d507afaf025..a61d9f39ba8 100644 --- a/crates/testing/src/sdk.rs +++ b/crates/testing/src/sdk.rs @@ -90,7 +90,7 @@ pub struct Test { /// /// Will run with access to the env vars: /// - `SPACETIME_SDK_TEST_CLIENT_PROJECT` bound to the `client_project` path. - /// - `SPACETIME_SDK_TEST_DB_ADDR` bound to the database address. + /// - `SPACETIME_SDK_TEST_DB_NAME` bound to the database identity or name. run_command: String, } diff --git a/crates/vm/src/ops/parse.rs b/crates/vm/src/ops/parse.rs index 18279787e4e..b45c5dd339b 100644 --- a/crates/vm/src/ops/parse.rs +++ b/crates/vm/src/ops/parse.rs @@ -1,5 +1,5 @@ use crate::errors::{ErrorType, ErrorVm}; -use spacetimedb_lib::{Address, Identity}; +use spacetimedb_lib::{ConnectionId, Identity}; use spacetimedb_sats::satn::Satn; use spacetimedb_sats::{i256, u256, AlgebraicType, AlgebraicValue, ProductType, SumType}; use std::fmt::Display; @@ -33,15 +33,15 @@ pub fn parse_simple_enum(sum: &SumType, tag_name: &str) -> Result Result { if product.is_identity() { return Ok(Identity::from_hex(value.trim_start_matches("0x")) .map_err(|err| ErrorVm::Other(err.into()))? .into()); } - if product.is_address() { - return Ok(Address::from_hex(value.trim_start_matches("0x")) + if product.is_connection_id() { + return Ok(ConnectionId::from_hex(value.trim_start_matches("0x")) .map_err(ErrorVm::Other)? .into()); } diff --git a/modules/module-test-cs/Lib.cs b/modules/module-test-cs/Lib.cs index 01ae67f1e8a..67593315a1f 100644 --- a/modules/module-test-cs/Lib.cs +++ b/modules/module-test-cs/Lib.cs @@ -154,7 +154,7 @@ public partial struct RepeatingTestArg public partial struct HasSpecialStuff { public Identity identity; - public Address address; + public ConnectionId connection_id; } // Two tables using the same row type. @@ -251,7 +251,7 @@ public static void log_module_identity(ReducerContext ctx) public static void test(ReducerContext ctx, TestAlias arg, TestB arg2, TestC arg3, TestF arg4) { Log.Info("BEGIN"); - Log.Info($"sender: {ctx.CallerIdentity}"); + Log.Info($"sender: {ctx.Sender}"); Log.Info($"timestamp: {ctx.Timestamp}"); Log.Info($"bar: {arg2.foo}"); @@ -436,7 +436,7 @@ public static void test_btree_index_args(ReducerContext ctx) [Reducer] public static void assert_caller_identity_is_module_identity(ReducerContext ctx) { - var caller = ctx.CallerIdentity; + var caller = ctx.Sender; var owner = ctx.Identity; if (!caller.Equals(owner)) { @@ -447,4 +447,4 @@ public static void assert_caller_identity_is_module_identity(ReducerContext ctx) Log.Info($"Called by the owner {owner}"); } } -} \ No newline at end of file +} diff --git a/modules/module-test/src/lib.rs b/modules/module-test/src/lib.rs index 1fcfe02086b..d3c5e81404b 100644 --- a/modules/module-test/src/lib.rs +++ b/modules/module-test/src/lib.rs @@ -2,7 +2,9 @@ use spacetimedb::log; use spacetimedb::spacetimedb_lib::db::raw_def::v9::TableAccess; use spacetimedb::spacetimedb_lib::{self, bsatn}; -use spacetimedb::{duration, table, Address, Deserialize, Identity, ReducerContext, SpacetimeType, Table, Timestamp}; +use spacetimedb::{ + duration, table, ConnectionId, Deserialize, Identity, ReducerContext, SpacetimeType, Table, Timestamp, +}; pub type TestAlias = TestA; @@ -137,7 +139,7 @@ pub struct RepeatingTestArg { #[spacetimedb::table(name = has_special_stuff)] pub struct HasSpecialStuff { identity: Identity, - address: Address, + connection_id: ConnectionId, } /// These two tables defined with the same row type diff --git a/modules/sdk-test-connect-disconnect-cs/Lib.cs b/modules/sdk-test-connect-disconnect-cs/Lib.cs index d00d2050e20..79af81d8cc4 100644 --- a/modules/sdk-test-connect-disconnect-cs/Lib.cs +++ b/modules/sdk-test-connect-disconnect-cs/Lib.cs @@ -19,12 +19,12 @@ static partial class Module [SpacetimeDB.Reducer(ReducerKind.ClientConnected)] public static void identity_connected(ReducerContext ctx) { - ctx.Db.connected.Insert(new Connected { identity = ctx.CallerIdentity }); + ctx.Db.connected.Insert(new Connected { identity = ctx.Sender}); } [SpacetimeDB.Reducer(ReducerKind.ClientDisconnected)] public static void identity_disconnected(ReducerContext ctx) { - ctx.Db.disconnected.Insert(new Disconnected { identity = ctx.CallerIdentity }); + ctx.Db.disconnected.Insert(new Disconnected { identity = ctx.Sender}); } } diff --git a/modules/sdk-test-cs/Lib.cs b/modules/sdk-test-cs/Lib.cs index 9bf7a8065f9..d8657236ce4 100644 --- a/modules/sdk-test-cs/Lib.cs +++ b/modules/sdk-test-cs/Lib.cs @@ -32,7 +32,7 @@ public partial record EnumWithPayload double F64, string Str, Identity Identity, - Address Address, + ConnectionId ConnectionId, Timestamp Timestamp, List Bytes, List Ints, @@ -69,7 +69,7 @@ public partial struct EveryPrimitiveStruct public double o; public string p; public Identity q; - public Address r; + public ConnectionId r; public Timestamp s; public TimeDuration t; } @@ -94,7 +94,7 @@ public partial struct EveryVecStruct public List o; public List p; public List q; - public List
r; + public List r; public List s; public List t; } @@ -303,16 +303,16 @@ public static void insert_one_identity(ReducerContext ctx, Identity i) ctx.Db.one_identity.Insert(new OneIdentity { i = i }); } - [SpacetimeDB.Table(Name = "one_address", Public = true)] - public partial struct OneAddress + [SpacetimeDB.Table(Name = "one_connection_id", Public = true)] + public partial struct OneConnectionId { - public Address a; + public ConnectionId a; } [SpacetimeDB.Reducer] - public static void insert_one_address(ReducerContext ctx, Address a) + public static void insert_one_connection_id(ReducerContext ctx, ConnectionId a) { - ctx.Db.one_address.Insert(new OneAddress { a = a }); + ctx.Db.one_connection_id.Insert(new OneConnectionId { a = a }); } [SpacetimeDB.Table(Name = "one_timestamp", Public = true)] @@ -603,16 +603,16 @@ public static void insert_vec_identity(ReducerContext ctx, List i) ctx.Db.vec_identity.Insert(new VecIdentity { i = i }); } - [SpacetimeDB.Table(Name = "vec_address", Public = true)] - public partial struct VecAddress + [SpacetimeDB.Table(Name = "vec_connection_id", Public = true)] + public partial struct VecConnectionId { - public List
a; + public List a; } [SpacetimeDB.Reducer] - public static void insert_vec_address(ReducerContext ctx, List
a) + public static void insert_vec_connection_id(ReducerContext ctx, List a) { - ctx.Db.vec_address.Insert(new VecAddress { a = a }); + ctx.Db.vec_connection_id.Insert(new VecConnectionId { a = a }); } [SpacetimeDB.Table(Name = "vec_timestamp", Public = true)] @@ -1182,31 +1182,31 @@ public static void delete_unique_identity(ReducerContext ctx, Identity i) ctx.Db.unique_identity.i.Delete(i); } - [SpacetimeDB.Table(Name = "unique_address", Public = true)] - public partial struct UniqueAddress + [SpacetimeDB.Table(Name = "unique_connection_id", Public = true)] + public partial struct UniqueConnectionId { [SpacetimeDB.Unique] - public Address a; + public ConnectionId a; public int data; } [SpacetimeDB.Reducer] - public static void insert_unique_address(ReducerContext ctx, Address a, int data) + public static void insert_unique_connection_id(ReducerContext ctx, ConnectionId a, int data) { - ctx.Db.unique_address.Insert(new UniqueAddress { a = a, data = data }); + ctx.Db.unique_connection_id.Insert(new UniqueConnectionId { a = a, data = data }); } [SpacetimeDB.Reducer] - public static void update_unique_address(ReducerContext ctx, Address a, int data) + public static void update_unique_connection_id(ReducerContext ctx, ConnectionId a, int data) { var key = a; - ctx.Db.unique_address.a.Update(new UniqueAddress { a = a, data = data }); + ctx.Db.unique_connection_id.a.Update(new UniqueConnectionId { a = a, data = data }); } [SpacetimeDB.Reducer] - public static void delete_unique_address(ReducerContext ctx, Address a) + public static void delete_unique_connection_id(ReducerContext ctx, ConnectionId a) { - ctx.Db.unique_address.a.Delete(a); + ctx.Db.unique_connection_id.a.Delete(a); } [SpacetimeDB.Table(Name = "pk_u8", Public = true)] @@ -1614,67 +1614,67 @@ public static void delete_pk_identity(ReducerContext ctx, Identity i) ctx.Db.pk_identity.i.Delete(i); } - [SpacetimeDB.Table(Name = "pk_address", Public = true)] - public partial struct PkAddress + [SpacetimeDB.Table(Name = "pk_connection_id", Public = true)] + public partial struct PkConnectionId { [SpacetimeDB.PrimaryKey] - public Address a; + public ConnectionId a; public int data; } [SpacetimeDB.Reducer] - public static void insert_pk_address(ReducerContext ctx, Address a, int data) + public static void insert_pk_connection_id(ReducerContext ctx, ConnectionId a, int data) { - ctx.Db.pk_address.Insert(new PkAddress { a = a, data = data }); + ctx.Db.pk_connection_id.Insert(new PkConnectionId { a = a, data = data }); } [SpacetimeDB.Reducer] - public static void update_pk_address(ReducerContext ctx, Address a, int data) + public static void update_pk_connection_id(ReducerContext ctx, ConnectionId a, int data) { var key = a; - ctx.Db.pk_address.a.Update(new PkAddress { a = a, data = data }); + ctx.Db.pk_connection_id.a.Update(new PkConnectionId { a = a, data = data }); } [SpacetimeDB.Reducer] - public static void delete_pk_address(ReducerContext ctx, Address a) + public static void delete_pk_connection_id(ReducerContext ctx, ConnectionId a) { - ctx.Db.pk_address.a.Delete(a); + ctx.Db.pk_connection_id.a.Delete(a); } [SpacetimeDB.Reducer] public static void insert_caller_one_identity(ReducerContext ctx) { - ctx.Db.one_identity.Insert(new OneIdentity { i = ctx.CallerIdentity }); + ctx.Db.one_identity.Insert(new OneIdentity { i = ctx.Sender }); } [SpacetimeDB.Reducer] public static void insert_caller_vec_identity(ReducerContext ctx) { ctx.Db.vec_identity.Insert( - new VecIdentity { i = new List { ctx.CallerIdentity } } + new VecIdentity { i = new List { ctx.Sender } } ); } [SpacetimeDB.Reducer] public static void insert_caller_unique_identity(ReducerContext ctx, int data) { - ctx.Db.unique_identity.Insert(new UniqueIdentity { i = ctx.CallerIdentity, data = data }); + ctx.Db.unique_identity.Insert(new UniqueIdentity { i = ctx.Sender, data = data }); } [SpacetimeDB.Reducer] public static void insert_caller_pk_identity(ReducerContext ctx, int data) { - ctx.Db.pk_identity.Insert(new PkIdentity { i = ctx.CallerIdentity, data = data }); + ctx.Db.pk_identity.Insert(new PkIdentity { i = ctx.Sender, data = data }); } [SpacetimeDB.Reducer] - public static void insert_caller_one_address(ReducerContext ctx) + public static void insert_caller_one_connection_id(ReducerContext ctx) { - ctx.Db.one_address.Insert(new OneAddress { a = (Address)ctx.CallerAddress! }); + ctx.Db.one_connection_id.Insert(new OneConnectionId { a = (ConnectionId)ctx.ConnectionId! }); } [SpacetimeDB.Reducer] - public static void insert_caller_vec_address(ReducerContext ctx) + public static void insert_caller_vec_connection_id(ReducerContext ctx) { // VecAddress::insert(VecAddress { // < a[_]>::into_vec( @@ -1685,17 +1685,17 @@ public static void insert_caller_vec_address(ReducerContext ctx) } [SpacetimeDB.Reducer] - public static void insert_caller_unique_address(ReducerContext ctx, int data) + public static void insert_caller_unique_connection_id(ReducerContext ctx, int data) { - ctx.Db.unique_address.Insert( - new UniqueAddress { a = (Address)ctx.CallerAddress!, data = data } + ctx.Db.unique_connection_id.Insert( + new UniqueConnectionId { a = (ConnectionId)ctx.ConnectionId!, data = data } ); } [SpacetimeDB.Reducer] - public static void insert_caller_pk_address(ReducerContext ctx, int data) + public static void insert_caller_pk_connection_id(ReducerContext ctx, int data) { - ctx.Db.pk_address.Insert(new PkAddress { a = (Address)ctx.CallerAddress!, data = data }); + ctx.Db.pk_connection_id.Insert(new PkConnectionId { a = (ConnectionId)ctx.ConnectionId!, data = data }); } [SpacetimeDB.Table(Name = "large_table", Public = true)] diff --git a/modules/sdk-test/src/lib.rs b/modules/sdk-test/src/lib.rs index c9fcf147da9..c774941f9c8 100644 --- a/modules/sdk-test/src/lib.rs +++ b/modules/sdk-test/src/lib.rs @@ -9,8 +9,7 @@ use anyhow::{Context, Result}; use spacetimedb::{ sats::{i256, u256}, - spacetimedb_lib::TimeDuration, - Address, Identity, ReducerContext, SpacetimeType, Table, Timestamp, + ConnectionId, Identity, ReducerContext, SpacetimeType, Table, TimeDuration, Timestamp, }; #[derive(SpacetimeType)] @@ -39,7 +38,7 @@ pub enum EnumWithPayload { F64(f64), Str(String), Identity(Identity), - Address(Address), + ConnectionId(ConnectionId), Timestamp(Timestamp), Bytes(Vec), Ints(Vec), @@ -76,7 +75,7 @@ pub struct EveryPrimitiveStruct { o: f64, p: String, q: Identity, - r: Address, + r: ConnectionId, s: Timestamp, t: TimeDuration, } @@ -100,7 +99,7 @@ pub struct EveryVecStruct { o: Vec, p: Vec, q: Vec, - r: Vec
, + r: Vec, s: Vec, t: Vec, } @@ -276,7 +275,7 @@ define_tables! { OneString { insert insert_one_string } s String; OneIdentity { insert insert_one_identity } i Identity; - OneAddress { insert insert_one_address } a Address; + OneConnectionId { insert insert_one_connection_id} a ConnectionId; OneTimestamp { insert insert_one_timestamp } t Timestamp; @@ -313,7 +312,7 @@ define_tables! { VecString { insert insert_vec_string } s Vec; VecIdentity { insert insert_vec_identity } i Vec; - VecAddress { insert insert_vec_address } a Vec
; + VecConnectionId { insert insert_vec_connection_id} a Vec; VecTimestamp { insert insert_vec_timestamp } t Vec; @@ -432,11 +431,11 @@ define_tables! { delete_by delete_unique_identity = delete_by_i(i: Identity), } #[unique] i Identity, data i32; - UniqueAddress { - insert_or_panic insert_unique_address, - update_by update_unique_address = update_by_a(a), - delete_by delete_unique_address = delete_by_a(a: Address), - } #[unique] a Address, data i32; + UniqueConnectionId { + insert_or_panic insert_unique_connection_id, + update_by update_unique_connection_id = update_by_a(a), + delete_by delete_unique_connection_id = delete_by_a(a: ConnectionId), + } #[unique] a ConnectionId, data i32; } // Tables mapping a primary key to a boring i32 payload. @@ -532,11 +531,11 @@ define_tables! { delete_by delete_pk_identity = delete_by_i(i: Identity), } #[primary_key] i Identity, data i32; - PkAddress { - insert_or_panic insert_pk_address, - update_by update_pk_address = update_by_a(a), - delete_by delete_pk_address = delete_by_a(a: Address), - } #[primary_key] a Address, data i32; + PkConnectionId { + insert_or_panic insert_pk_connection_id, + update_by update_pk_connection_id = update_by_a(a), + delete_by delete_pk_connection_id = delete_by_a(a: ConnectionId), + } #[primary_key] a ConnectionId, data i32; } #[spacetimedb::reducer] @@ -564,34 +563,34 @@ fn insert_caller_pk_identity(ctx: &ReducerContext, data: i32) -> anyhow::Result< } #[spacetimedb::reducer] -fn insert_caller_one_address(ctx: &ReducerContext) -> anyhow::Result<()> { - ctx.db.one_address().insert(OneAddress { - a: ctx.address.context("No address in reducer context")?, +fn insert_caller_one_connection_id(ctx: &ReducerContext) -> anyhow::Result<()> { + ctx.db.one_connection_id().insert(OneConnectionId { + a: ctx.connection_id.context("No connection id in reducer context")?, }); Ok(()) } #[spacetimedb::reducer] -fn insert_caller_vec_address(ctx: &ReducerContext) -> anyhow::Result<()> { - ctx.db.vec_address().insert(VecAddress { - a: vec![ctx.address.context("No address in reducer context")?], +fn insert_caller_vec_connection_id(ctx: &ReducerContext) -> anyhow::Result<()> { + ctx.db.vec_connection_id().insert(VecConnectionId { + a: vec![ctx.connection_id.context("No connection id in reducer context")?], }); Ok(()) } #[spacetimedb::reducer] -fn insert_caller_unique_address(ctx: &ReducerContext, data: i32) -> anyhow::Result<()> { - ctx.db.unique_address().insert(UniqueAddress { - a: ctx.address.context("No address in reducer context")?, +fn insert_caller_unique_connection_id(ctx: &ReducerContext, data: i32) -> anyhow::Result<()> { + ctx.db.unique_connection_id().insert(UniqueConnectionId { + a: ctx.connection_id.context("No connection id in reducer context")?, data, }); Ok(()) } #[spacetimedb::reducer] -fn insert_caller_pk_address(ctx: &ReducerContext, data: i32) -> anyhow::Result<()> { - ctx.db.pk_address().insert(PkAddress { - a: ctx.address.context("No address in reducer context")?, +fn insert_caller_pk_connection_id(ctx: &ReducerContext, data: i32) -> anyhow::Result<()> { + ctx.db.pk_connection_id().insert(PkConnectionId { + a: ctx.connection_id.context("No connection id in reducer context")?, data, }); Ok(()) diff --git a/smoketests/tests/permissions.py b/smoketests/tests/permissions.py index da337dcd43d..6d99eae70b7 100644 --- a/smoketests/tests/permissions.py +++ b/smoketests/tests/permissions.py @@ -54,7 +54,7 @@ def test_logs(self): self.spacetime("logs", self.database_identity, "-n", "10000") def test_publish(self): - """This test checks to make sure that you cannot publish to an address that you do not own.""" + """This test checks to make sure that you cannot publish to an identity that you do not own.""" self.new_identity() self.publish_module() diff --git a/smoketests/tests/zz_docker.py b/smoketests/tests/zz_docker.py index 58ded478d0c..46854723b01 100644 --- a/smoketests/tests/zz_docker.py +++ b/smoketests/tests/zz_docker.py @@ -137,28 +137,28 @@ def test_restart_module(self): class DockerRestartAutoDisconnect(Smoketest): MODULE_CODE = """ use log::info; -use spacetimedb::{Address, Identity, ReducerContext, Table}; +use spacetimedb::{ConnectionId, Identity, ReducerContext, Table}; #[spacetimedb::table(name = connected_client)] pub struct ConnectedClient { identity: Identity, - address: Address, + connection_id: ConnectionId, } #[spacetimedb::reducer(client_connected)] fn on_connect(ctx: &ReducerContext) { ctx.db.connected_client().insert(ConnectedClient { identity: ctx.sender, - address: ctx.address.expect("sender address unset"), + connection_id: ctx.connection_id.expect("sender connection id unset"), }); } #[spacetimedb::reducer(client_disconnected)] fn on_disconnect(ctx: &ReducerContext) { let sender_identity = &ctx.sender; - let sender_address = ctx.address.as_ref().expect("sender address unset"); + let sender_connection_id = ctx.connection_id.as_ref().expect("sender connection id unset"); let match_client = |row: &ConnectedClient| { - &row.identity == sender_identity && &row.address == sender_address + &row.identity == sender_identity && &row.connection_id == sender_connection_id }; if let Some(client) = ctx.db.connected_client().iter().find(match_client) { ctx.db.connected_client().delete(client);