Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
545bb7c
[2.0 Breaking]: Remove sender field from [Reducer|View|Procedure]Cont…
joshua-spacetime Jan 23, 2026
42bdd98
Update LLM benchmark results
clockwork-labs-bot Jan 26, 2026
85dc1dc
[2.0 Breaking] `Sender` changes for C# modules (#4143)
joshua-spacetime Jan 28, 2026
865b495
[WASM] Expose `RawModuleDefV10` from modules (#4153)
Shubham8287 Feb 3, 2026
8190694
Merge branch 'master' into 2.0-breaking-changes
Shubham8287 Feb 3, 2026
5de40c3
Update codegen to not provide private tables by default with a future…
JasonAtClockwork Feb 3, 2026
9f9c9f5
Rename allow_private to include_private to match the future argument
JasonAtClockwork Feb 3, 2026
5a6fdc0
Updated codegen snap files
JasonAtClockwork Feb 3, 2026
e472665
Updated Blackholio bindings for Unreal, but rolled back Unity as it b…
JasonAtClockwork Feb 4, 2026
165fd71
Regenerated module bindings for Unity Blackholio
JasonAtClockwork Feb 4, 2026
f65c673
Update for regression-tests module_bindings
JasonAtClockwork Feb 4, 2026
3221601
Update Rust test module_bindings
JasonAtClockwork Feb 4, 2026
56a0c78
Regenerated rust test-client again as it seemed to miss something, an…
JasonAtClockwork Feb 4, 2026
750ae7d
[2.0 Breaking] Make `connection_id` a method on `ReducerContext` (#4200)
joshua-spacetime Feb 5, 2026
8d9a0a0
Merge branch 'master' into 2.0-breaking-changes
Shubham8287 Feb 5, 2026
76eeda3
Added output to list private tables not included during the generate …
JasonAtClockwork Feb 6, 2026
2a2d98a
Merge branch '2.0-breaking-changes' into jlarabie/2.0-private-tables
JasonAtClockwork Feb 6, 2026
b549a7a
Updated snaps from merge
JasonAtClockwork Feb 6, 2026
27fc5ac
Merge branch 'master' into jlarabie/2.0-private-tables
JasonAtClockwork Feb 6, 2026
fc3af2c
Clean up procedure test for CI
JasonAtClockwork Feb 6, 2026
0c237a5
Switched to enum for the private visibility check
JasonAtClockwork Feb 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: FFI.cs
//HintName: FFI.cs
// <auto-generated />
#nullable enable
// The runtime already defines SpacetimeDB.Internal.LocalReadOnly in Runtime\Internal\Module.cs as an empty partial type.
Expand All @@ -17,7 +17,6 @@ namespace SpacetimeDB
{
public sealed record ReducerContext : DbContext<Local>, Internal.IReducerContext
{
public readonly Identity Sender;
public readonly ConnectionId? ConnectionId;
public readonly Random Rng;
public readonly Timestamp Timestamp;
Expand All @@ -29,6 +28,8 @@ public sealed record ReducerContext : DbContext<Local>, Internal.IReducerContext
// We need this property to be non-static for parity with client SDK.
public Identity Identity => Internal.IReducerContext.GetIdentity();

private readonly Identity _sender;

internal ReducerContext(
Identity identity,
ConnectionId? connectionId,
Expand All @@ -37,14 +38,19 @@ internal ReducerContext(
AuthCtx? senderAuth = null
)
{
Sender = identity;
_sender = identity;
ConnectionId = connectionId;
Rng = random;
Timestamp = time;
SenderAuth = senderAuth ?? AuthCtx.BuildFromSystemTables(connectionId, identity);
CounterUuid = 0;
}

/// <summary>
/// The identity of the client that invoked the reducer.
/// </summary>
public Identity Sender() => _sender;

/// <summary>
/// Create a new random <see cref="Uuid"/> `v4` using the built-in RNG.
/// </summary>
Expand Down Expand Up @@ -199,13 +205,18 @@ public sealed class Local : global::SpacetimeDB.LocalBase

public sealed record ViewContext : DbContext<Internal.LocalReadOnly>, Internal.IViewContext
{
public Identity Sender { get; }
private readonly Identity _sender;

internal ViewContext(Identity sender, Internal.LocalReadOnly db)
: base(db)
{
Sender = sender;
_sender = sender;
}

/// <summary>
/// The identity of the client that invoked the view.
/// </summary>
public Identity Sender() => _sender;
}

public sealed record AnonymousViewContext
Expand Down
20 changes: 16 additions & 4 deletions crates/bindings-csharp/Codegen/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,6 @@ public void Initialize(IncrementalGeneratorInitializationContext context)

namespace SpacetimeDB {
public sealed record ReducerContext : DbContext<Local>, Internal.IReducerContext {
public readonly Identity Sender;
public readonly ConnectionId? ConnectionId;
public readonly Random Rng;
public readonly Timestamp Timestamp;
Expand All @@ -1753,16 +1752,24 @@ public sealed record ReducerContext : DbContext<Local>, Internal.IReducerContext
// We need this property to be non-static for parity with client SDK.
public Identity Identity => Internal.IReducerContext.GetIdentity();

private readonly Identity _sender;

internal ReducerContext(Identity identity, ConnectionId? connectionId, Random random,
Timestamp time, AuthCtx? senderAuth = null)
{
Sender = identity;
_sender = identity;
ConnectionId = connectionId;
Rng = random;
Timestamp = time;
SenderAuth = senderAuth ?? AuthCtx.BuildFromSystemTables(connectionId, identity);
CounterUuid = 0;
}

/// <summary>
/// The identity of the client that invoked the reducer.
/// </summary>
public Identity Sender() => _sender;

/// <summary>
/// Create a new random <see cref="Uuid"/> `v4` using the built-in RNG.
/// </summary>
Expand Down Expand Up @@ -1897,13 +1904,18 @@ public sealed class Local : global::SpacetimeDB.LocalBase {

public sealed record ViewContext : DbContext<Internal.LocalReadOnly>, Internal.IViewContext
{
public Identity Sender { get; }
private readonly Identity _sender;

internal ViewContext(Identity sender, Internal.LocalReadOnly db)
: base(db)
{
Sender = sender;
_sender = sender;
}

/// <summary>
/// The identity of the client that invoked the view.
/// </summary>
public Identity Sender() => _sender;
}

public sealed record AnonymousViewContext : DbContext<Internal.LocalReadOnly>, Internal.IAnonymousViewContext
Expand Down
7 changes: 5 additions & 2 deletions crates/bindings-csharp/Runtime/Internal/TxContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ public sealed class TxContext(
Random rng
)
{
private readonly Identity _sender = sender;

public Local Db { get; } = db;
public Identity Sender { get; } = sender;
public ConnectionId? ConnectionId { get; } = connectionId;
public Timestamp Timestamp { get; } = timestamp;
public AuthCtx SenderAuth { get; } = senderAuth;
public Random Rng { get; } = rng;

public Identity Sender() => _sender;

public TxContext WithTimestamp(Timestamp ts) =>
new(Db, Sender, ConnectionId, ts, SenderAuth, Rng);
new(Db, _sender, ConnectionId, ts, SenderAuth, Rng);
}
10 changes: 7 additions & 3 deletions crates/bindings-csharp/Runtime/ProcedureContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ public abstract class ProcedureContextBase(
Timestamp time
) : Internal.IInternalProcedureContext
{
private readonly Identity _sender = sender;

public Identity Sender() => _sender;

public static Identity Identity => Internal.IProcedureContext.GetIdentity();
public Identity Sender { get; } = sender;
public ConnectionId? ConnectionId { get; } = connectionId;
public Random Rng { get; } = random;
public Timestamp Timestamp { get; private set; } = time;
Expand Down Expand Up @@ -47,7 +50,7 @@ public Internal.TxContext EnterTxContext(long timestampMicros)
txContext?.WithTimestamp(timestamp)
?? new Internal.TxContext(
CreateLocal(),
Sender,
_sender,
ConnectionId,
timestamp,
SenderAuth,
Expand Down Expand Up @@ -229,8 +232,9 @@ public abstract class ProcedureTxContextBase(Internal.TxContext inner)

internal void Refresh(Internal.TxContext inner) => Inner = inner;

public Identity Sender() => Inner.Sender();

public LocalBase Db => (LocalBase)Inner.Db;
public Identity Sender => Inner.Sender;
public ConnectionId? ConnectionId => Inner.ConnectionId;
public Timestamp Timestamp => Inner.Timestamp;
public AuthCtx SenderAuth => Inner.SenderAuth;
Expand Down
2 changes: 1 addition & 1 deletion crates/bindings-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ pub mod raw {
/// would be where you would initialize the interepreter and load the user module into it.
fn __setup__() -> Result;
/// Required. Runs after `__setup__`; returns all the exports for the module.
fn __describe_module__() -> Encoded<ModuleDef>;
fn __describe_module_v10__() -> Encoded<ModuleDef>;
/// Required. id is an index into the `ModuleDef.reducers` returned from `__describe_module__`.
/// args is a bsatn-encoded product value defined by the schema at `reducers[id]`.
fn __call_reducer__(
Expand Down
28 changes: 18 additions & 10 deletions crates/bindings/src/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use crate::query_builder::Query;
use crate::table::IndexAlgo;
use crate::{sys, AnonymousViewContext, IterBuf, ReducerContext, ReducerResult, SpacetimeType, Table, ViewContext};
use spacetimedb_lib::bsatn::EncodeError;
use spacetimedb_lib::db::raw_def::v10::RawModuleDefV10Builder;
pub use spacetimedb_lib::db::raw_def::v9::Lifecycle as LifecycleReducer;
use spacetimedb_lib::db::raw_def::v9::{RawIndexAlgorithm, RawModuleDefV9Builder, TableType, ViewResultHeader};
use spacetimedb_lib::db::raw_def::v9::{RawIndexAlgorithm, TableType, ViewResultHeader};
use spacetimedb_lib::de::{self, Deserialize, DeserializeOwned, Error as _, SeqProductAccess};
use spacetimedb_lib::sats::typespace::TypespaceBuilder;
use spacetimedb_lib::sats::{impl_deserialize, impl_serialize, ProductTypeElement};
Expand Down Expand Up @@ -674,7 +675,7 @@ pub trait RowLevelSecurityInfo {
}

/// A function which will be registered by [`register_describer`] into [`DESCRIBERS`],
/// which will be called by [`__describe_module__`] to construct a module definition.
/// which will be called by [`__describe_module_v10__`] to construct a module definition.
///
/// May be a closure over static data, so that e.g.
/// [`register_row_level_security`] doesn't need to take a type parameter.
Expand All @@ -700,6 +701,13 @@ pub fn register_reftype<T: SpacetimeType>() {
pub fn register_table<T: Table>() {
register_describer(|module| {
let product_type_ref = *T::Row::make_type(&mut module.inner).as_ref().unwrap();
if let Some(schedule) = T::SCHEDULE {
module.inner.add_schedule(
T::TABLE_NAME,
schedule.scheduled_at_column,
schedule.reducer_or_procedure_name,
);
}

let mut table = module
.inner
Expand All @@ -719,10 +727,6 @@ pub fn register_table<T: Table>() {
for &col in T::SEQUENCES {
table = table.with_column_sequence(col);
}
if let Some(schedule) = T::SCHEDULE {
table = table.with_schedule(schedule.reducer_or_procedure_name, schedule.scheduled_at_column);
}

for col in T::get_default_col_values().iter_mut() {
table = table.with_default_column_value(col.col_id, col.value.clone())
}
Expand All @@ -749,7 +753,11 @@ impl From<IndexAlgo<'_>> for RawIndexAlgorithm {
pub fn register_reducer<'a, A: Args<'a>, I: FnInfo<Invoke = ReducerFn>>(_: impl Reducer<'a, A>) {
register_describer(|module| {
let params = A::schema::<I>(&mut module.inner);
module.inner.add_reducer(I::NAME, params, I::LIFECYCLE);
if let Some(lifecycle) = I::LIFECYCLE {
module.inner.add_lifecycle_reducer(lifecycle, I::NAME, params);
} else {
module.inner.add_reducer(I::NAME, params);
}
module.reducers.push(I::INVOKE);
})
}
Expand Down Expand Up @@ -814,7 +822,7 @@ pub fn register_row_level_security(sql: &'static str) {
#[derive(Default)]
pub struct ModuleBuilder {
/// The module definition.
inner: RawModuleDefV9Builder,
inner: RawModuleDefV10Builder,
/// The reducers of the module.
reducers: Vec<ReducerFn>,
/// The procedures of the module.
Expand Down Expand Up @@ -863,7 +871,7 @@ static ANONYMOUS_VIEWS: OnceLock<Vec<AnonymousFn>> = OnceLock::new();
/// including when modules are updated (re-publishing).
/// After initialization, the module cannot alter the schema.
#[no_mangle]
extern "C" fn __describe_module__(description: BytesSink) {
extern "C" fn __describe_module_v10__(description: BytesSink) {
// Collect the `module`.
let mut module = ModuleBuilder::default();
for describer in &mut *DESCRIBERS.lock().unwrap() {
Expand All @@ -872,7 +880,7 @@ extern "C" fn __describe_module__(description: BytesSink) {

// Serialize the module to bsatn.
let module_def = module.inner.finish();
let module_def = RawModuleDef::V9(module_def);
let module_def = RawModuleDef::V10(module_def);
let bytes = bsatn::to_vec(&module_def).expect("unable to serialize typespace");

// Write the sets of reducers, procedures and views.
Expand Down
10 changes: 9 additions & 1 deletion crates/cli/src/subcommands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use clap::parser::ValueSource;
use clap::Arg;
use clap::ArgAction::Set;
use fs_err as fs;
use spacetimedb_codegen::{generate, Csharp, Lang, OutputFile, Rust, TypeScript, UnrealCpp, AUTO_GENERATED_PREFIX};
use spacetimedb_codegen::{
generate, private_table_names, Csharp, Lang, OutputFile, Rust, TypeScript, UnrealCpp, AUTO_GENERATED_PREFIX,
};
use spacetimedb_lib::de::serde::DeserializeWrapper;
use spacetimedb_lib::{sats, RawModuleDef};
use spacetimedb_schema;
Expand Down Expand Up @@ -171,6 +173,12 @@ pub async fn exec_ex(
extract_descriptions(&path).context("could not extract schema")?
};

// TODO: Update this to work with --include-private once that flag exists.
let private_tables = private_table_names(&module);
if !private_tables.is_empty() {
println!("Skipping private tables during codegen: {}.", private_tables.join(", "));
}

fs::create_dir_all(out_dir)?;

let mut paths = BTreeSet::new();
Expand Down
6 changes: 3 additions & 3 deletions crates/codegen/src/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::ops::Deref;
use super::code_indenter::CodeIndenter;
use super::Lang;
use crate::util::{
collect_case, is_reducer_invokable, iter_indexes, iter_reducers, iter_table_names_and_types,
CodegenVisibility, collect_case, is_reducer_invokable, iter_indexes, iter_reducers, iter_table_names_and_types,
print_auto_generated_file_comment, print_auto_generated_version_comment, type_ref_name,
};
use crate::{indent_scope, OutputFile};
Expand Down Expand Up @@ -1048,7 +1048,7 @@ impl Lang for Csharp<'_> {
indented_block(&mut output, |output| {
writeln!(output, "public RemoteTables(DbConnection conn)");
indented_block(output, |output| {
for (table_name, _) in iter_table_names_and_types(module) {
for (table_name, _) in iter_table_names_and_types(module, CodegenVisibility::OnlyPublic) {
writeln!(
output,
"AddTable({} = new(conn));",
Expand All @@ -1071,7 +1071,7 @@ impl Lang for Csharp<'_> {

writeln!(output, "public sealed class From");
indented_block(&mut output, |output| {
for (table_name, product_type_ref) in iter_table_names_and_types(module) {
for (table_name, product_type_ref) in iter_table_names_and_types(module, CodegenVisibility::OnlyPublic) {
let method_name = table_name.deref().to_case(Case::Pascal);
let row_type = type_ref_name(module, product_type_ref);
let table_name_lit = format!("{:?}", table_name.deref());
Expand Down
3 changes: 2 additions & 1 deletion crates/codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ pub use self::csharp::Csharp;
pub use self::rust::Rust;
pub use self::typescript::TypeScript;
pub use self::unrealcpp::UnrealCpp;
pub use util::private_table_names;
pub use util::AUTO_GENERATED_PREFIX;

pub fn generate(module: &ModuleDef, lang: &dyn Lang) -> Vec<OutputFile> {
itertools::chain!(
module.tables().map(|tbl| lang.generate_table_file(module, tbl)),
util::iter_tables(module, util::CodegenVisibility::OnlyPublic).map(|tbl| lang.generate_table_file(module, tbl)),
module.views().map(|view| lang.generate_view_file(module, view)),
module.types().flat_map(|typ| lang.generate_type_files(module, typ)),
util::iter_reducers(module).map(|reducer| lang.generate_reducer_file(module, reducer)),
Expand Down
Loading
Loading