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 3ce055b4bc7..bb33a8b65e8 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 @@ -655,9 +655,13 @@ public sealed record ReducerContext : DbContext, Internal.IReducerContext // **Note:** must be 0..=u32::MAX internal int CounterUuid; + public Identity DatabaseIdentity => Internal.IReducerContext.GetDatabaseIdentity(); - // We need this property to be non-static for parity with client SDK. - public Identity Identity => Internal.IReducerContext.GetIdentity(); + // We keep this property for compatibility with existing module code. + [global::System.Obsolete( + "ReducerContext.Identity is deprecated. Use DatabaseIdentity instead." + )] + public Identity Identity => DatabaseIdentity; internal ReducerContext( Identity identity, diff --git a/crates/bindings-csharp/Codegen.Tests/fixtures/explicitnames/snapshots/Module#FFI.verified.cs b/crates/bindings-csharp/Codegen.Tests/fixtures/explicitnames/snapshots/Module#FFI.verified.cs index a9774bfc69e..c963576250f 100644 --- a/crates/bindings-csharp/Codegen.Tests/fixtures/explicitnames/snapshots/Module#FFI.verified.cs +++ b/crates/bindings-csharp/Codegen.Tests/fixtures/explicitnames/snapshots/Module#FFI.verified.cs @@ -57,9 +57,13 @@ public sealed record ReducerContext : DbContext, Internal.IReducerContext // **Note:** must be 0..=u32::MAX internal int CounterUuid; + public Identity DatabaseIdentity => Internal.IReducerContext.GetDatabaseIdentity(); - // We need this property to be non-static for parity with client SDK. - public Identity Identity => Internal.IReducerContext.GetIdentity(); + // We keep this property for compatibility with existing module code. + [global::System.Obsolete( + "ReducerContext.Identity is deprecated. Use DatabaseIdentity instead." + )] + public Identity Identity => DatabaseIdentity; internal ReducerContext( Identity identity, 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 4632875e05f..4c6be2c99c4 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 @@ -499,9 +499,13 @@ public sealed record ReducerContext : DbContext, Internal.IReducerContext // **Note:** must be 0..=u32::MAX internal int CounterUuid; + public Identity DatabaseIdentity => Internal.IReducerContext.GetDatabaseIdentity(); - // We need this property to be non-static for parity with client SDK. - public Identity Identity => Internal.IReducerContext.GetIdentity(); + // We keep this property for compatibility with existing module code. + [global::System.Obsolete( + "ReducerContext.Identity is deprecated. Use DatabaseIdentity instead." + )] + public Identity Identity => DatabaseIdentity; internal ReducerContext( Identity identity, diff --git a/crates/bindings-csharp/Codegen/Module.cs b/crates/bindings-csharp/Codegen/Module.cs index e778b6d69cc..f6ffa50b941 100644 --- a/crates/bindings-csharp/Codegen/Module.cs +++ b/crates/bindings-csharp/Codegen/Module.cs @@ -2189,8 +2189,10 @@ public sealed record ReducerContext : DbContext, Internal.IReducerContext public readonly AuthCtx SenderAuth; // **Note:** must be 0..=u32::MAX internal int CounterUuid; - // We need this property to be non-static for parity with client SDK. - public Identity Identity => Internal.IReducerContext.GetIdentity(); + public Identity DatabaseIdentity => Internal.IReducerContext.GetDatabaseIdentity(); + // We keep this property for compatibility with existing module code. + [global::System.Obsolete("ReducerContext.Identity is deprecated. Use DatabaseIdentity instead.")] + public Identity Identity => DatabaseIdentity; internal ReducerContext(Identity identity, ConnectionId? connectionId, Random random, Timestamp time, AuthCtx? senderAuth = null) diff --git a/crates/bindings-csharp/Runtime/Internal/IReducer.cs b/crates/bindings-csharp/Runtime/Internal/IReducer.cs index ec2e698a160..878c98a2a2e 100644 --- a/crates/bindings-csharp/Runtime/Internal/IReducer.cs +++ b/crates/bindings-csharp/Runtime/Internal/IReducer.cs @@ -1,15 +1,19 @@ namespace SpacetimeDB.Internal; +using System; using System.Text; using SpacetimeDB.BSATN; public interface IReducerContext { - public static Identity GetIdentity() + public static Identity GetDatabaseIdentity() { FFI.identity(out var identity); return identity; } + + [Obsolete("IReducerContext.GetIdentity() is deprecated. Use GetDatabaseIdentity() instead.")] + public static Identity GetIdentity() => GetDatabaseIdentity(); } public interface IReducer diff --git a/crates/bindings/src/lib.rs b/crates/bindings/src/lib.rs index 9e02a3a97f0..68689ba3234 100644 --- a/crates/bindings/src/lib.rs +++ b/crates/bindings/src/lib.rs @@ -687,7 +687,7 @@ pub use spacetimedb_bindings_macro::table; /// /// #[reducer] /// fn scheduled(ctx: &ReducerContext, args: ScheduledArgs) -> Result<(), String> { -/// if ctx.sender() != ctx.identity() { +/// if ctx.sender() != ctx.database_identity() { /// return Err("Reducer `scheduled` may not be invoked by clients, only via scheduling.".into()); /// } /// // Reducer body... @@ -1081,7 +1081,7 @@ impl ReducerContext { } /// Read the current module's [`Identity`]. - pub fn identity(&self) -> Identity { + pub fn database_identity(&self) -> Identity { // Hypothetically, we *could* read the module identity out of the system tables. // However, this would be: // - Onerous, because we have no tooling to inspect the system tables from module code. @@ -1093,6 +1093,12 @@ impl ReducerContext { Identity::from_byte_array(spacetimedb_bindings_sys::identity()) } + /// Read the current module's [`Identity`]. + #[deprecated(note = "Use `ReducerContext::database_identity` instead.")] + pub fn identity(&self) -> Identity { + self.database_identity() + } + /// Create an anonymous (no sender) read-only view context pub fn as_anonymous_read_only(&self) -> AnonymousViewContext { AnonymousViewContext::default() diff --git a/modules/module-test-cs/Lib.cs b/modules/module-test-cs/Lib.cs index da038502546..3c0524bb4e0 100644 --- a/modules/module-test-cs/Lib.cs +++ b/modules/module-test-cs/Lib.cs @@ -272,7 +272,7 @@ public static void list_over_age(ReducerContext ctx, byte age) public static void log_module_identity(ReducerContext ctx) { // Note: converting to lowercase to match the Rust formatting. - Log.Info($"Module identity: {ctx.Identity.ToString().ToLower()}"); + Log.Info($"Module identity: {ctx.DatabaseIdentity.ToString().ToLower()}"); } [Reducer] @@ -464,7 +464,7 @@ public static void test_btree_index_args(ReducerContext ctx) public static void assert_caller_identity_is_module_identity(ReducerContext ctx) { var caller = ctx.Sender; - var owner = ctx.Identity; + var owner = ctx.DatabaseIdentity; if (!caller.Equals(owner)) { throw new Exception($"Caller {caller} is not the owner {owner}"); diff --git a/modules/module-test/src/lib.rs b/modules/module-test/src/lib.rs index e8a7d35ee2c..b883bcbc171 100644 --- a/modules/module-test/src/lib.rs +++ b/modules/module-test/src/lib.rs @@ -263,7 +263,7 @@ pub fn list_over_age(ctx: &ReducerContext, age: u8) { #[spacetimedb::reducer] fn log_module_identity(ctx: &ReducerContext) { - log::info!("Module identity: {}", ctx.identity()); + log::info!("Module identity: {}", ctx.database_identity()); } #[spacetimedb::reducer] @@ -471,7 +471,7 @@ fn test_btree_index_args(ctx: &ReducerContext) { #[spacetimedb::reducer] fn assert_caller_identity_is_module_identity(ctx: &ReducerContext) { let caller = ctx.sender(); - let owner = ctx.identity(); + let owner = ctx.database_identity(); if caller != owner { panic!("Caller {caller} is not the owner {owner}"); } else {