## 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
⚠️ Internal Project ⚠️
This project is intended for internal use only. It is not stable and may change without notice.
SpacetimeDB.Runtime
This project contains the runtime bindings for SpacetimeDB WebAssembly modules. See the C# module library reference for stable, user-facing documentation.
SpacetimeDB modules are compiled to WebAssembly modules that expose a specific interface; see the module ABI reference.
The runtime bindings are currently implementing via Wasi.Sdk package, which is a .NET implementation of the WASI standard. This is likely to change in the future.
While not really documented, it allows to build raw WebAssembly modules with custom bindings as well, which is what we're using here. The process is somewhat complicated, but here are the steps:
bindings.cdeclares raw C bindings to the SpacetimeDB FFI imports and marks them with attributes like__attribute__((import_module("spacetime"), import_name("_insert")))that make them WebAssembly imports. (unfortunately, function name duplication is currently unavoidable)bindings.cimplements a bunch of Mono-compatible wrappers that convert between Mono types and raw types expected by the SpacetimeDB FFI and invoke corresponding raw bindings.Runtime.csdeclares corresponding functions with compatible signatures for Mono-compatible wrappers to attach to. It marks them all with[MethodImpl(MethodImplOptions.InternalCall)].bindings.cattaches all those Mono-compatible wrappers to their C# declarations in amono_stdb_attach_bindingsfunction.bindings.cadds FFI-compatible exports that search for a method by assembly name, namespace, class name and a method name in the Mono runtime and invoke it. Those exports are marked with attributes like__attribute__((export_name("__call_reducer__")))so that they're exported from Wasm by the linker.- Finally,
bindings.cimplements no-op shims for all the WASI APIs so that they're linked internally and not attempted to be imported from the runtime itself.
The result is a WebAssembly module FFI-compatible with SpacetimeDB and with no WASI imports, which is what we need.
Regenerating RawModuleDef
To regenenerate the Autogen folder, run:
cargo run -p spacetimedb-codegen --example regen-csharp-moduledef
This folder contains the type definitions used to serialize the RawModuleDef that is returned by __describe_module__.