mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-07-23 18:47:13 -04:00
c7af2d4cd3
## Summary - add `ReducerContext::database_identity()` in Rust bindings - deprecate `ReducerContext::identity()` and keep it as a compatibility alias - update reducer docs example to use `ctx.database_identity()` - add C# reducer-context equivalent: `DatabaseIdentity` and obsolete `Identity` alias - update Rust/C# module test callsites to the new API name - update C# codegen snapshots for generated `ReducerContext` API output ## Why Issue #3201 reports user confusion between reducer `ctx.identity()` (database/module identity) and `ctx.sender`. This change clarifies naming while preserving compatibility. ## Validation - `cargo check -p spacetimedb -p module-test` (Passed) - `dotnet test crates/bindings-csharp/Codegen.Tests/Codegen.Tests.csproj --nologo` (Passed) - `dotnet test crates/bindings-csharp/Runtime.Tests/Runtime.Tests.csproj --nologo` (Failed) pre-existing unrelated failure: - `Runtime.Tests/JwtClaimsTest.cs(10,23): CS1729: 'JwtClaims' does not contain a constructor that takes 2 arguments` ## Compatibility - Rust: `identity()` still works but is deprecated in favor of `database_identity()`. - C#: `Identity` still works but is marked `[Obsolete]` in favor of `DatabaseIdentity`. Closes #3201
41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
namespace SpacetimeDB.Internal;
|
|
|
|
using System;
|
|
using System.Text;
|
|
using SpacetimeDB.BSATN;
|
|
|
|
public interface IReducerContext
|
|
{
|
|
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
|
|
{
|
|
RawReducerDefV10 MakeReducerDef(ITypeRegistrar registrar);
|
|
|
|
Lifecycle? Lifecycle { get; }
|
|
|
|
// This one is not static because we need to be able to store IReducer in a list.
|
|
void Invoke(BinaryReader reader, IReducerContext args);
|
|
|
|
public static void VolatileNonatomicScheduleImmediate(string name, MemoryStream args)
|
|
{
|
|
var name_bytes = Encoding.UTF8.GetBytes(name);
|
|
var args_bytes = args.ToArray();
|
|
|
|
FFI.volatile_nonatomic_schedule_immediate(
|
|
name_bytes,
|
|
(uint)name_bytes.Length,
|
|
args_bytes,
|
|
(uint)args_bytes.Length
|
|
);
|
|
}
|
|
}
|