Commit Graph

83 Commits

Author SHA1 Message Date
Tyler Cloutier 3f58b5951b Implement event tables (server, Rust/TS/C# codegen + client SDKs) (#4217)
## Summary

Implements event tables end-to-end: server datastore, module bindings
(Rust/TypeScript/C#), client codegen (Rust/TypeScript/C#), client SDKs
(Rust/TypeScript/C#), and integration tests.

Event tables are tables whose rows are ephemeral — they persist to the
commitlog and are delivered to V2 subscribers, but are NOT merged into
committed state. Rows are only visible within the transaction that
inserted them. This is the mechanism that replaces reducer event
callbacks in 2.0.

## What's included

### Server
- `is_event` flag on `RawTableDefV10`, `TableDef`, `TableSchema`
- Event table rows recorded in TxData but skipped during committed state
merge
- Commitlog replay treats event table inserts as no-ops
- Migration validation rejects changing `is_event` between module
versions
- `SELECT * FROM *` excludes event tables
- V1 WebSocket subscriptions to event tables rejected with upgrade
message
- V2 subscription path delivers event table rows correctly
- `CanBeLookupTable` trait — event tables cannot be lookup tables in
semijoins
- Runtime view validation rejects event tables

### Module bindings
- **Rust**: `#[spacetimedb::table(name = my_events, public, event)]`
- **TypeScript**: `table({ event: true }, ...)`
- **C#**: `[Table(Event = true)]`

### Client codegen (`crates/codegen/`)
- **Rust**: Generates `EventTable` impl (insert-only) for event tables,
`Table` impl for normal tables. `CanBeLookupTable` emitted for non-event
tables.
- **TypeScript**: Emits `event: true` in generated table schemas.
`ClientTableCore` type excludes `onDelete`/`onUpdate` for event tables
via conditional types.
- **C#**: Generates classes inheriting from `RemoteEventTableHandle`
(which hides `OnDelete`/`OnBeforeDelete`/`OnUpdate`) for event tables.

### Client SDKs
- **Rust**: `EventTable` trait with insert-only callbacks, client cache
bypass, `count()` returns 0, `iter()` returns empty
- **TypeScript**: Event table cache bypass in `table_cache.ts` — fires
`onInsert` callbacks but doesn't store rows. Type-level narrowing
excludes delete/update methods.
- **C#**: `RemoteEventTableHandle` base class hides delete/update
events. Parse/Apply/PostApply handle `EventTableRows` wire format, skip
cache storage, fire only `OnInsert`.

### Tests
- 9 datastore unit tests (insert/delete/update semantics, replay,
constraints, indexes, auto-inc, cross-tx reset)
- 3 Rust SDK integration tests (basic events, multiple events per
reducer, no persistence across transactions)
- Codegen snapshot tests (Rust, TypeScript, C#)
- Trybuild compile tests (event tables rejected as semijoin lookup
tables)

## Deferred
- `on_delete` codegen for event tables (server only sends inserts;
client synthesis deferred)
- Event tables in subscription joins / views (well-defined but
restricted for now)
- C++ SDK support
- RLS integration test

## API and ABI breaking changes

- `is_event: bool` added to `RawTableDefV10` (appended, defaults to
`false` — existing modules unaffected)
- `CanBeLookupTable` trait bound on semijoin methods in query builder
(all non-event tables implement it, so existing code compiles unchanged)
- `RemoteEventTableHandle` added to C# SDK (new base class for generated
event table handles)

## Expected complexity level and risk

3 — Changes touch the schema pipeline end-to-end and all three client
SDKs, but each individual change is straightforward. The core risk area
is the committed state merge skip in `committed_state.rs`. Client SDK
changes are additive (new code paths for event tables, existing paths
unchanged).

## Testing

- [x] `cargo clippy --workspace --tests --benches` passes
- [x] `cargo test -p spacetimedb-codegen` (snapshot tests)
- [x] `cargo test -p spacetimedb-datastore --features
spacetimedb-schema/test -- event_table` (9 unit tests)
- [x] `pnpm format` passes
- [x] Rust SDK integration tests pass (`event_table_tests` module)

---------

Signed-off-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
Co-authored-by: Phoebe Goldman <phoebe@goldman-tribe.org>
Co-authored-by: Jason Larabie <jason@clockworklabs.io>
Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
2026-02-15 22:56:20 +00:00
clockwork-labs-bot 927d4c4020 [2.0 Breaking] Update C# client SDK for V2 WebSocket format (#4293)
Re-opened from #4289 which was accidentally merged into its base branch
(`rekhoff/csharp-module-defs-v10-no-et`) instead of `master`.

This is the same PR, now correctly targeting `master`.

---

Original description from #4289:

This PR migrates the C# SDK client path to WebSocket v2 semantics and
aligns behavior with the Rust SDK direction for 2.0, including follow-on
fixes in generation/tests.

See #4289 for full description.

---------

Co-authored-by: rekhoff <r.ekhoff@clockworklabs.io>
Co-authored-by: Jason Larabie <jason@clockworklabs.io>
Co-authored-by: clockwork-labs-bot <clockwork-labs-bot@users.noreply.github.com>
2026-02-13 16:53:38 +00:00
SteveGibson a344465847 Set name of network thread in C# SDK (#4090)
# Description of Changes

Set name for C# SDK network thread. Helpful when profiling and debugging

# API and ABI breaking changes

No breaking changes

# Expected complexity level and risk

1 - Trivial

# Testing

Tested in Unity Profiler

Co-authored-by: SteveGibsonX <stevegibsonxj@gmail.com>
Co-authored-by: Ryan <r.ekhoff@clockworklabs.io>
2026-02-13 15:11:35 +00:00
Phoebe Goldman 98585e858d Rename with_module_name -> with_database_name (#4267)
# Description of Changes

Modules are like programs, databases are like processes. Your client
connects to a remote database, not a remote module.

<!-- Please describe your change, mention any related tickets, and so on
here. -->

# API and ABI breaking changes

Yep!

# Expected complexity level and risk

2? I made this change with find + replace, and it's possible that I
borked the edit, or missed some reference somehow. It seems unlikely,
however, that this change will have deeper implications we haven't
considered.

# Testing

N/a
2026-02-12 02:11:33 +00:00
Ryan 9a8b603565 Adding Abort to C# Websocket (#3352)
# Description of Changes

The implementation of a solution to #3044 , this adds an `Abort`
function to the `WebSocket`, which runs if `Disconnect` is called when
the `WebSocket` is not connected.

# API and ABI breaking changes

Not API breaking.

# Expected complexity level and risk

1

# Testing

- [X] Test locally with a C# CLI test client. 
**Note**: Before change (either on Rust of C# server), server would see
4 `Debug` log entries about connecting, but not see the `Info` log about
the client connection ending like would normally be seen in a
disconnect. After change, server shows no log entries at all, because
connection is properly aborted.
- [x] Test locally with a C# WebGL test client.

---------

Signed-off-by: rekhoff <r.ekhoff@clockworklabs.io>
Co-authored-by: John Detter <4099508+jdetter@users.noreply.github.com>
2026-01-30 18:32:53 +00:00
Jason Larabie 78c28d4936 Add C# client SDK procedures (#3666)
# Description of Changes

Closes: #3533 
Updated the C# SDK to handle procedures and procedure callbacks in a
similar fashion to the Rust client as well as added the codegen to
support it.

# API and ABI breaking changes

N/A

# Expected complexity level and risk

2 - This adds a new testing frame that should be removed once procedures
are handled with C# module bindings

# Testing

Added /sdks/csharp/examples~/regression-tests/procedure-client to match
modules/sdk-test-procedure which we can roll into the standard
regression-tests once C# supports the procedure attribute.

- [x] Add C# client test of sdk-test-procedure

---------

Signed-off-by: Jason Larabie <jason@clockworklabs.io>
2025-11-21 19:39:21 +00:00
Tyler Cloutier ce543854e9 Unifies server module library and client SDK for TypeScript (and fixes several bugs) (#3559)
# Description of Changes

This PR is a very large change to the workings of the TypeScript SDK and
as such requires a higher bar of testing than other PRs. However, it
does several important things:

1. Unifies the API of the server and client so they not only have the
same API, but they actually implement it with the same TypeScript types.
This fixes several inconsistencies between them and fixes several small
bugs as well.
2. Closes https://github.com/clockworklabs/SpacetimeDB/issues/3365
3. Closes https://github.com/clockworklabs/SpacetimeDB/issues/3431
4. Closes https://github.com/clockworklabs/SpacetimeDB/issues/3435
5. Subsumes the work done in
https://github.com/clockworklabs/SpacetimeDB/pull/3447
6. Derives all type information on the client from a single
`RemoteModule` type which vastly cleans up the correctness of type
checking on the client and helped me to find several small bugs

It accomplishes this by changing code generation of TypeScript on the
client to code generation approximately what a developer would manually
write in their module. The ultimate goal would be to allow the developer
to use the types and functions that they define on in their module
directly on the client without needing to do any code generation at all,
provided they are using TypeScript on the server and client.

https://github.com/clockworklabs/SpacetimeDB/issues/3365 is resolved by
`.build()`ing the `DbConnection` inside a React `useEffect` rather than
doing it directly in line with the render of the provider. In order to
do that we needed to not expose the `DbConnection` directly to
developers by returning a different type from `useSpacetimeDB`.
`useSpacetimeDB` now returns a `ConnectionState` object which is stored
as React state and updates when any of the fields change. This change
also resolves https://github.com/clockworklabs/SpacetimeDB/issues/3431.

https://github.com/clockworklabs/SpacetimeDB/issues/3435 was the issue
that initially lead me down the rabbit hole of unifying the server and
the client because it was nearly impossible to track down all the
various type functions and how they connect to the values that we code
generate on the server. After several hours of attempting this, I
decided to clean up the types a bit to be more uniform.

Implementing the unification between the client and the server also
necessitated fully implemented parts of the API that were fully
implemented on the server, but were broken or missing on the client.

# API and ABI breaking changes

[Unification] -> Means that this is breaking behavior for the client
SDK, but that the new behavior is identical to the server's existing
behavior

## Breaking changes:

- Table accessor names and index accessor names are converted to
camelCase on the `ctx`, so `ctx.db.foo_bar` is now `ctx.db.fooBar`

- [Unification] On the client `my_table.iter()` returns
`IterableIterator` instead of an `Array`
- [Unification] `module_bindings` now export `TypeBuilder`s for all
types instead of a `type MyType` and object `MyType`, so instead of
using `MyType` as a type directly, you need to infer the type `MyType`
-> `Infer<typeof MyType>`.
- [Unification] We no longer generate and export `MyTypeVariants` for
sum types (these are now accessed by `Infer<typeof
MyType.variants.myVariant>`)
- [Unification] `MyType.getTypeScriptAlgebraicType()` has been replaced
with `MyType.algebraicType`

- `useSpacetimeDB()` no longer takes type parameters
- `useTable()` now takes a `TableDef` parameter and type params are
inferred
- `useTable()` now just returns an `Array` directly instead of a object
with `{ rows }`

- [Unification] `ctx.reducers.createPlayer(argA, argB)` ->
`ctx.reducers.createPlayer({ argA, argB })`
- [Unification] `ctx.reducers.onCreatePlayer(ctx, argA, argB)` ->
`ctx.reducers.onCreatePlayer(ctx, { argA, argB })`
- [Unification] `ctx.reducers.removeOnCreatePlayer(ctx, argA, argB)` ->
`ctx.reducers.removeOnCreatePlayer(ctx, { argA, argB })`
- [Unification] `myTable.count(): number` -> `myTable.count(): bigint`
 
## Additive changes:
- `Infer<>` now also does `InferTypeOfRow<>` if applicable
- Added a `useReducer()` React hook
- `module_bindings` now exports a `tables` object with references to all
the `TableDef`s
- `module_bindings` now exports a `reducers` object with references to
all the `ReducerDef`s
- Added a new `MyType.create('MyVariant', ...)` function in addition to
the `MyType.MyVariant(...)` constructors (this is private)

## Notable things that did not change:
- `MyType.serialize(writer: BinaryWriter, value: Infer<typeof MyType>)`
and `MyType.deserialize(reader: BinaryReader): Infer<typeof MyType>` are
still supported exactly as before.
- The `MyType.MyVariant(...)` constructor function on sum types is still
present, but implemented with the private `MyType.create('MyVariant',
...)`. We could choose to move away from this API later if we didn't
like the variants polluting the namespace


# Expected complexity level and risk

4 - This is a deep reaching an complex change for the SDK. For the
server, it is much less deep reaching since it reuses much of the same
machinery, although it does require thorough testing there as some of
the code was modified.

This change is fully localized to TypeScript and does not touch the host
(or other languages) at all, and therefore only impacts a beta aspect of
SpacetimeDB.

# Testing

<!-- Describe any testing you've done, and any testing you'd like your
reviewers to do,
so that you're confident that all the changes work as expected! -->

- [ ] Added regression test for
https://github.com/clockworklabs/SpacetimeDB/issues/3435
- [x] Manually tested `test-app` and `test-react-router-app`
- [ ] Add test cases for camelCase-ing

---------

Signed-off-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
Co-authored-by: Noa <coolreader18@gmail.com>
2025-11-19 02:53:41 +00:00
Kim Altintop fa2e9b306b C#: Add confirmed reads configuration (#3282)
Allows the SpacetimeDBClient to be configured with or without confirmed
reads. Like for [TypeScript], the parameter is optional -- the server
chooses the default if not set explicitly.

[TypeScript]: https://github.com/clockworklabs/SpacetimeDB/pull/3247

# Expected complexity level and risk

1

# Testing

I don't actually know what I'm doing 😅
2025-11-18 11:10:38 +00:00
rekhoff 40ec970d17 Implement reduced coupling between SpacetimeDBClient.cs and Table.cs (#3122)
## Description of Changes
Moves table-specific operations out of `SpacetimeDBClient.cs` and into
`Table.cs` in order to reduce coupling between the two files.

This is the implementation of
https://github.com/clockworklabs/SpacetimeDB/issues/3047

This is a PR being duplicated/migrated from
https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/pull/346,
which contains prior discussion/review/approval.

## API

 - [ ] This is an API breaking change to the SDK

## Requires SpacetimeDB PRs
No PRs needed, works with latest master

## Testsuite
SpacetimeDB branch name: master

## Testing
- [X] Opened and ran Blackhol.io within Unity Editor and successfully
connecting to a locally running server
- [X] Compiled a WebGL build of Blackhol.io and successfully connecting
to a locally running server
- [x] Opened and ran BitCraft within Unity Editor and successfully
connecting to a locally running server
2025-08-05 16:59:58 +00:00
rekhoff 533c14bea3 Update WebGL message queue to 1.2.1 format (#342)
## Description of Changes
This is a fix for community bug
https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/issues/340
that was the result of changes to SpacetimeDBClient code that missed
changes to the WebGL build.

## API

 - [ ] This is an API breaking change to the SDK

## Requires SpacetimeDB PRs
- None

## Testsuite
SpacetimeDB branch name: master

## Testing

- [X] Tested changes against Blackholio running under a Unity WebGL
build
2025-07-07 10:36:20 -04:00
james gilles e168ec6f90 More granular request process tracking (#330)
## Description of Changes
Addresses
https://github.com/clockworklabs/SpacetimeDBPrivate/issues/1786 and
https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/issues/329.
Marks messages as parsed from the background parsing thread, and then
marks them as applied using a separate tracker once they are applied.

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

## Requires SpacetimeDB PRs

## Testsuite

SpacetimeDB branch name: master

## Testing

- [x] Testing against Bitcraft
2025-06-18 13:37:52 -04:00
joshua-spacetime 3dabd47bc8 Add comment on the performance of LINQ for reading BSATN (#309) 2025-04-28 17:13:28 +00:00
james gilles 590e873a50 Significantly reduce small byte array allocations (#305)
This purges the DbValue type, instead using row instances themselves as
primary key for rows without primary keys. In addition, it instantiates
only a single BinaryReader when reading updates for a table, rather than
instantiating a BinaryReader and performing an array copy per-row of the
table.

Addresses
https://github.com/clockworklabs/SpacetimeDBPrivate/issues/1633

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

## Requires SpacetimeDB PRs

## Testsuite

SpacetimeDB branch name: master

## Testing
*Write instructions for a test that you performed for this PR*

- [ ] CI

---------

Co-authored-by: rekhoff <r.ekhoff@clockworklabs.io>
2025-04-26 09:08:44 -07:00
james gilles 5ad9baa304 Pre-decompress query updates (#302)
This dramatically improves performance by avoiding the default
implementation of BrotliStream.ReadByte() inherited from Stream, which
allocates an array per byte read.

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

## Requires SpacetimeDB PRs

## Testsuite

SpacetimeDB branch name: master

## Testing
*Write instructions for a test that you performed for this PR*

- [ ] Describe a test for this PR that you have completed
2025-04-23 20:44:16 -07:00
Daniel Kierkegaard Andersen 20ed2dc067 SpacetimeDB working in Unity WebGL Builds (#286)
## Description of Changes
As it stands today, Unity WebGL doesn't work. Partially the reason for
this is Multi-Threading, and the other reason is the use of
`ClientWebSocket`. In order to fix this (specifically in the case of
Unity), here's some changes that _can_ be made. Note that this is mostly
a suggestion and does come with a few flaws, though arguably it might
still be better than it not working at all? Up to you!

The Tl;Dr of how it works, is to:
- **MultiThreading Problem**: simply invoke the `Task.Run` functions on
main thread instead, and use a coroutine in place of where the two
simultaneous threads was expected.
- **ClientWebSocket**: Use a `.jslib` to create the WebSocket directly
within Javascript, and then have JS call the corresponding correct
functions.

DISCLAIMER: currently OnClose doesn't quite work correctly as
`__allocate` isn't invoked correctly.

## API

Not a breaking change to the API, should be internal implementation
details

## Requires SpacetimeDB PRs
None

## Testsuite
????

SpacetimeDB branch name: master

## Testing
Open the Blackholeio project, try building it for WebGL

- [X] Made a game using the feature:
https://daxode.itch.io/eat-to-the-deep

---------

Co-authored-by: rekhoff <r.ekhoff@clockworklabs.io>
Co-authored-by: John Detter <no-reply@boppygames.gg>
Co-authored-by: John Detter <4099508+jdetter@users.noreply.github.com>
Co-authored-by: James Gilles <jameshgilles@gmail.com>
2025-04-22 12:59:23 -07:00
John Detter 468a6f142b Fix warning message for failed to track reducer call (#280)
## Description of Changes
*Describe what has been changed, any new features or bug fixes*

- Fixes an issue that was reported in the discord where a user was
connecting 2 clients to the same SpacetimeDB module with the same
identity but different connection IDs.

## API

- This is not breaking.

## Requires SpacetimeDB PRs

None

## Testsuite

SpacetimeDB branch name: master

## Testing

- [x] Build blackholio as a player build and launch it twice. You can
play on both clients without seeing this warning in Player.log.

---------

Co-authored-by: John Detter <no-reply@boppygames.gg>
Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
2025-04-12 01:24:41 +01:00
james gilles 3543132c7d Fix for unsubscribe bug + regression tests (#264)
## Description of Changes

This PR fixes one issue and adds regression tests for it, plus another
issue. These regression tests are run on CI. You can also run them
locally -- run a local spacetime instance and then
`tools~/run-regression-tests.sh ../SpacetimeDB`).

### Issue 1: Unsubscribe is non-functional

See
https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/issues/279.
This was a coding mistake made during the rush to 1.0. It was easily
fixed.

### Issue 2: Indexes not tracking deletes

This was recently discovered by the BitCraft team.

The problem was introduced in
https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/commit/cefc727b7693fe97e3dd848fef2bb17bf20c8be6
which introduced `RemoteTableHandle<EventContext,
Row>.IndexBase<Column>`. This class stores a `Dictionary<Column,
List<Row>>` to allow fast filtering. It relies on `List<Row>.Remove` to
remove elements from a list when a row delete is received.
`List<Row>.Remove` relies on `Row.Equals` to determine when elements are
equal.

`Row.Equals` formerly was not implemented for `[SpacetimeDB.Type]`s or
for generated Row types. So, this didn't work.

Now it does: it was fixed by
https://github.com/clockworklabs/SpacetimeDB/pull/239 . So all this PR
does to address this issue is add a regression test.

## API

 - [x] This is an API breaking change to the SDK

The interface IDbConnection was changed; however, this changed part of
the interface is `internal`, so this should be entirely invisible to
users.

## Requires SpacetimeDB PRs
https://github.com/clockworklabs/SpacetimeDB/pull/239 (merged)

## Testsuite
*If you would like to run the your SDK changes in this PR against a
specific SpacetimeDB branch, specify that here. This can be a branch
name or a link to a PR.*

SpacetimeDB branch name: master

## Testing
*Write instructions for a test that you performed for this PR*

- [x] Added a repro for both issues
- [x] Added the repro to CI
- [x] Fixed both issues
2025-03-28 20:15:51 +00:00
james gilles 083531e319 SubscribeMulti + UnsubscribeMulti, multiplicities (#249)
## Description of Changes
Add SubscribeMulti and UnsubscribeMulti from upstream.
Fix unsubscribe bug found by testing against Bitcraft: Calling
`UnsubscribeThen` with any (non-null) callback would result in an
exception incorrectly telling the user that `Unsubscribe` had been
called twice.
Multiplicity support is implemented with unit tests + manual testing of
quickstart-chat.
Also, rows in the client cache are now looked up by primary key if
available, which I suspect is going to be a large performance boost.

## API

 - [x] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

## Testsuite
*If you would like to run the your SDK changes in this PR against a
specific SpacetimeDB branch, specify that here. This can be a branch
name or a link to a PR.*

SpacetimeDB branch name: jgilles/final-cs-codegen-changes

## Testing
*Write instructions for a test that you performed for this PR*

- [x] unit tests
- [ ] Working with Ryan to add a test suite.
- [x] blackholio
2025-02-25 16:24:26 -05:00
Zeke Foppa 076d4ecbb1 Strip trailing / from URIs before connecting (#238)
## Description of Changes
We were not stripping `/` from the end of URIs provided to `Connect`. We
manually append `/...` to the provided addresses, so if we don't start
by stripping trailing `/`s, we end up with `//` in the URI and we get
errors.

Addresses part of
https://github.com/clockworklabs/SpacetimeDB/issues/1551.

## API

No breaking  changes. This fixes an error case.

## Requires SpacetimeDB PRs
None

## Testsuite
SpacetimeDB branch name: master

## Testing
- [x] Tested the quickstart chat client with a host containing a
trailing `/`
```
# start a server, publish the module, send some input
# I also updated one line in `client.csproj` to use `Net8.0` because I no longer have `Net7.0` installed

$ cd examples~/quickstart/client

$ dotnet run
[I] SpacetimeDBClient: Connecting to ws://localhost:3000 quickstart-chat
C200098E is online
Connected
C2007471: hello
C2007471: godo
C2007471: asdf

$ sed -i 's/localhost:3000/localhost:3000\//' Program.cs

$ dotnet run
[I] SpacetimeDBClient: Connecting to ws://localhost:3000 quickstart-chat
C2000601 is online
Connected
C2007471: hello
C2007471: godo
C2007471: asdf

$ git diff
diff --git a/examples~/quickstart/client/Program.cs b/examples~/quickstart/client/Program.cs
index 9eb43b1..289e736 100644
--- a/examples~/quickstart/client/Program.cs
+++ b/examples~/quickstart/client/Program.cs
@@ -7,8 +7,8 @@ using System.Threading;
 using SpacetimeDB;
 using SpacetimeDB.Types;
 
-const string HOST = "http://localhost:3000";
-const string DBNAME = "chatqs";
+const string HOST = "http://localhost:3000/";
+const string DBNAME = "quickstart-chat";
 
 // our local client SpacetimeDB identity
 Identity? local_identity = null;
diff --git a/examples~/quickstart/client/client.csproj b/examples~/quickstart/client/client.csproj
index 48917cc..ab7ce44 100644
--- a/examples~/quickstart/client/client.csproj
+++ b/examples~/quickstart/client/client.csproj
@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <OutputType>Exe</OutputType>
-    <TargetFramework>net7.0</TargetFramework>
+    <TargetFramework>net8.0</TargetFramework>
     <CheckEolTargetFramework>false</CheckEolTargetFramework>
     <ImplicitUsings>disable</ImplicitUsings>
     <Nullable>enable</Nullable>
```

---------

Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
2025-02-11 19:42:41 +00:00
james gilles 498b25f825 Emit Event.UnknownTransaction rather than throwing on unknown reducer (#244)
## Description of Changes
as described

## API

no breaks

## Requires SpacetimeDB PRs
https://github.com/clockworklabs/SpacetimeDB/pull/2241

## Testsuite

SpacetimeDB branch name: jgilles/unknown_reducer

## Testing

see SpacetimeDB PR
2025-02-11 13:21:06 -05:00
Phoebe Goldman 96d52c1a7b Rename Address to ConnectionId (#239)
## Description of Changes

Companion to [Rename `Address` to
`ConnectionId`](https://github.com/clockworklabs/SpacetimeDB/pull/2220).
See that PR's description for more.

Like all the SDKs, this PR does not change the SDK's behavior; the SDK
still generates a connection ID locally and passes it through the HTTP
API. This is not exposed to users, and can be changed in a follow-up.

Also, use `/usr/bin/env bash` instead of `/bin/bash` in tools, for
portability reasons.

## API

 - [x] This is an API breaking change to the SDK

`Address` is renamed to `ConnectionId`.

## Requires SpacetimeDB PRs

- https://github.com/clockworklabs/SpacetimeDB/pull/2220
- 
## Testsuite
*If you would like to run the your SDK changes in this PR against a
specific SpacetimeDB branch, specify that here. This can be a branch
name or a link to a PR.*

SpacetimeDB branch name: phoebe/rename-address-to-connection-id

## Testing

- [x] Pretty much just automated testing.
- [x] @kazimuth will need to update and run Blackholio.

---------

Co-authored-by: James Gilles <jameshgilles@gmail.com>
2025-02-10 00:29:18 +00:00
james gilles 9f58828caa Rework event contexts in C# (#240)
## Description of Changes
https://github.com/clockworklabs/SpacetimeDB/pull/2226

## API

 - [x] This is an API breaking change to the SDK

callbacks are better

## Requires SpacetimeDB PRs
https://github.com/clockworklabs/SpacetimeDB/pull/2226

## Testsuite

SpacetimeDB branch name: jgilles/csharp-better-events

## Testing

- [x] quickstart
- [x] blackholio
2025-02-07 22:03:55 +00:00
james gilles b4aa612239 Make Timestamp and TimeDuration special types (#233)
## Description of Changes

C# part of https://github.com/clockworklabs/SpacetimeDB/pull/1836
Needs to be rebased onto
https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/pull/220
once that is merged.

## API

 - [x] This is an API breaking change to the SDK

ScheduleAt is now constructed in slightly different ways.

## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

## Testsuite
*If you would like to run the your SDK changes in this PR against a
specific SpacetimeDB branch, specify that here. This can be a branch
name or a link to a PR.*

SpacetimeDB branch name: phoebe/timestamp-special-type

## Testing
Will need an update to blackholio as well.
2025-02-07 14:17:45 -05:00
Ingvar Stepanyan fed2a9db3e Fix handling of multi-tables (#229)
## Description of Changes

Unfortunately, none of our tests currently cover this, but while working
on the V9 upgrade, I noticed that this code still relies on `type(Row)`
as a unique table identifier.

That no longer holds with multi-tables as several tables can share the
same `Row` type. In that case, subscription updates would be grouped
incorrectly and always applied to the same first table that uses `Row`
for its data storage.

This PR fixes that by using the table handle itself as a key (compared
by reference).

If transaction updates are already grouped uniquely by table, it should
be possible to simplify this code much further, but I'm not sure if such
guarantee exists, so leaving that untouched.

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

## Testsuite
*If you would like to run the your SDK changes in this PR against a
specific SpacetimeDB branch, specify that here. This can be a branch
name or a link to a PR.*

SpacetimeDB branch name: master

## Testing
*Write instructions for a test that you performed for this PR*

- [x] I did `dotnet test`, but as mentioned in the description, this
requires adding tests for multi-table subscriptions, which I'm afraid I
won't have time to do, so have to leave to follow-up devs.

---------

Co-authored-by: james gilles <jameshgilles@gmail.com>
2025-02-06 17:54:12 +00:00
Ingvar Stepanyan cefc727b76 Rewrite C# codegen to the new Lang infra + fixes (#220)
## Description of Changes

This is the companion PR for
https://github.com/clockworklabs/SpacetimeDB/pull/2184, please see the
other PR for full description.

On the client side main changes are:

- Regenerate .NET and Unity test client bindings and test snapshot.
- Remove `IDatabaseRow` since V9 multi-tables splits data types from
actual table definitions, so those "table data types" are no longer
special. Just using `IStructuralReadWrite` in its place now.
- Add base index classes as mentioned in the other PR.
- As a sub-improvement, the non-unique index class actually does
indexing instead of iterating over the entire table like we did before.
- Remove internal-but-not-really `InternalInvokeValueDeleted` and
`InternalInvokeValueInserted` methods in favour of private events.

## API

 - [x] This is an API breaking change to the SDK

Removes some technically-visible but internal APIs.

## Requires SpacetimeDB PRs
https://github.com/clockworklabs/SpacetimeDB/pull/2184

## Testsuite
*If you would like to run the your SDK changes in this PR against a
specific SpacetimeDB branch, specify that here. This can be a branch
name or a link to a PR.*

SpacetimeDB branch name: ingvar/csharp-new-codegen

## Testing
*Write instructions for a test that you performed for this PR*

- [x] Manually tested Blackholio

---------

Co-authored-by: James Gilles <jameshgilles@gmail.com>
2025-02-05 16:48:15 -05:00
james gilles 6578f0563b Implement new subscription API (#219)
## Description of Changes

As proposed. No upstream codegen changes needed :)

## API

 - [x] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*
The subscription API is slightly different.

## Requires SpacetimeDB PRs
https://github.com/clockworklabs/SpacetimeDB/pull/2111

## Testsuite

SpacetimeDB branch name: jsdt/subscribe-sdk-3

## Testing
So far I have performed manual testing with the chat example. Working on
updating the unity and unit tests.

- [ ] Describe a test for this PR that you have completed
2025-01-23 16:22:29 -05:00
Ingvar Stepanyan 3d530ee248 Upgrade to new regenerated client-api bindings (#218)
## Description of Changes

Looks like client API bindings haven't been regenerated in a while, and
this is a necessary precursor to the new subscription work. This PR
fixes the generation script, regenerates the bindings and updates
affected code.

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

## Testsuite
*If you would like to run the your SDK changes in this PR against a
specific SpacetimeDB branch, specify that here. This can be a branch
name or a link to a PR.*

SpacetimeDB branch name: v1.0.0-rc3

## Testing
*Write instructions for a test that you performed for this PR*

- [x] Ran regular `dotnet test`.
- [x] Checked Unity tests via CI.
2025-01-16 17:29:27 +00:00
Phoebe Goldman 39e7ebbb9a Revise WithCredentials to WithToken (#212)
## Description of Changes

`WithCredentials` was designed for our old auth model, where tokens were
always issued by the SpacetimeDB host alongside an `Identity`, and
therefore the bearer always knew their `Identity`.

In our new auth model, a client may have a valid auth-able JWT but not
know what `Identity` it will result in,
as the `Identity` is computed based on the hash of some of the token's
contents, and this hashing algorithm is not included in our client SDKs.
As such, this PR revises `WithCredentials` to `WithToken`, which just
accepts the token.

## API

 - [x] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

`WithCredentials` is renamed and its signature changes.

## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

## Testsuite
*If you would like to run the your SDK changes in this PR against a
specific SpacetimeDB branch, specify that here. This can be a branch
name or a link to a PR.*

SpacetimeDB branch name: master

## Testing
*Write instructions for a test that you performed for this PR*

- [ ] @cloutiertyler should test this with the Unity tutorial, if
possible.

---------

Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
2025-01-14 18:43:34 +00:00
Ingvar Stepanyan 006087fb43 Add delegates for events (#201)
## Description of Changes

This is a requested DX improvement to make sure that IDE shows
reasonable argument names instead of `arg0`...`argN`.

Fixes
https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/issues/200.

## API

 - [x] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

Potentially breaking in obscure edge cases, if someone already had
`Action<...> myCallback;` that they passed to those APIs as C# won't
cast it automatically to our custom delegate type.

## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

## Testsuite
*If you would like to run against a specific SpacetimeDB branch in the
testsuite, specify that here. This can be a branch name or a link to a
PR.*

SpacetimeDB branch name: master

## Testing
*Write instructions for a test that you performed for this PR*

- [x] `dotnet test`
2025-01-14 14:28:29 +00:00
Ingvar Stepanyan 9b7f20cedb Migrate C# and Unity tests to the new API (#194)
## Description of Changes

Counterpart to https://github.com/clockworklabs/SpacetimeDB/pull/2033.

Also updated test settings to make sure that sum type variants
implemented via subclassing are shown as expected.

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

## Testsuite
*If you would like to run against a specific SpacetimeDB branch in the
testsuite, specify that here. This can be a branch name or a link to a
PR.*

SpacetimeDB branch name: master

## Testing
*Write instructions for a test that you performed for this PR*

- [ ] Describe a test for this PR that you have completed
2024-12-12 12:03:44 -05:00
Mazdak Farrokhzad 2ad31d65b4 Companion to SpacetimeDB#1812 (light tx, C#) (#170)
## Description of Changes

Adds C# sdk support for
https://github.com/clockworklabs/SpacetimeDB/pull/1812.

## Requires SpacetimeDB PRs

- https://github.com/clockworklabs/SpacetimeDB/pull/1812

## Testsuite

SpacetimeDB branch name: centril/websocket-light

---------

Co-authored-by: Tyler Cloutier <cloutiertyler@aol.com>
Co-authored-by: John Detter <4099508+jdetter@users.noreply.github.com>
2024-11-04 17:46:42 +01:00
John Detter f936c98b04 Fix Reconnection Logic (#168)
## Description of Changes
*Describe what has been changed, any new features or bug fixes*

- switched our "already connected" logic to using a reference to a
`MonoBehaviour` instead of just a bool. `MonoBehaviour`s are typically
destroyed when a scene reload happens and in this case we'll want to
allow developers to spawn a new `SpacetimeDBNetworkManager` if the
previous one has been destroyed.

## API

This is *not* an API break.

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

- https://github.com/clockworklabs/SpacetimeDB/pull/1869

## Testsuite

SpacetimeDB branch name: master

## Testing
*Write instructions for a test that you performed for this PR*

- [x] I have added in several new tests here, one of which is a
reconnection test. Also, the reason why we couldn't have more than 1
test before this is that it was required for reconnections to be working
in order to have multiple tests running in the testsuite. Now that we
have fixed reconnections I have enabled all of the tests.

Testsuite passes


![image](https://github.com/user-attachments/assets/09ef5835-f2c7-41f1-af6b-e612ac5e0497)

---------

Co-authored-by: John Detter <no-reply@boppygames.gg>
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
Co-authored-by: Jeremie Pelletier <jeremiep@gmail.com>
Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
2024-10-31 22:34:26 +00:00
Mazdak Farrokhzad ac45eacf37 Add gzip + none compression algos and let SDK pick compression (take 2) (#174)
## Description of Changes

Companion to https://github.com/clockworklabs/SpacetimeDB/pull/1802.

## Requires SpacetimeDB PRs

None

## Test suite

SpacetimeDB branch name: 0935b7346b

---------

Co-authored-by: Jeremie Pelletier <jeremiep@gmail.com>
Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
2024-10-31 19:08:52 +01:00
John Detter b2c5b41170 Fix Connection Error: Success (#166)
## Description of Changes
This PR edits the handling of errors related to websocket connections
and disconnections. In particular, clients and users would often run
into the dreaded `Connection Error: Success` message which was confusing
and frustrating. This PR better addresses the error by providing more
guidance and debug info for the user. It is unfortunately still
suboptimal because the `HttpStatusCode` is not available in the .NET
core version that Unity supports. We try to be as helpful as possible in
this scenario.

## API

- [x] This is an API breaking change to the SDK, because it changes the
returned values from the `OnDisconnect` and `OnConnectError` callbacks
to implement the API specification:
https://github.com/clockworklabs/SpacetimeDBPrivate/pull/866/files#diff-be533cc04817c33605a68d717c6ec320c4449904266ee8e1096971e9e17e8d31R424

## Requires SpacetimeDB PRs
No changes to SpacetimeDB required.

## Testing

I, Tyler, have tested this and confirmed it to be working with
CircleGame. Here is a sample of the output in the case of `Connection
Error: Success`:

<img width="1324" alt="image"
src="https://github.com/user-attachments/assets/2b98c69f-07e2-4d0b-a61f-0ae4f84d62f6">

---------

Co-authored-by: John Detter <no-reply@boppygames.gg>
Co-authored-by: Tyler Cloutier <cloutiertyler@aol.com>
Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
2024-10-30 18:08:36 -04:00
SteveGibson 5ccb5f99bf Fixed subscription updates not clearing tables with no subscribed values (#182)
## Description of Changes
*Describe what has been changed, any new features or bug fixes*

Context:
https://discord.com/channels/568217153853980682/669989878955638785/1301132060878049332
Currently, when we receive subscription updates, a table will only be
diffed if subscription has any rows for that table. If, however, there
are no subscribed values, that table will NOT be diffed, and therefore
will not get cleared. Values from previous subscription will still be
there, so the table is in incorrect state.

This PR fixes that by making sure that ALL tables are checked in state
diff

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

## Testing
*Write instructions for a test that you performed for this PR*

- [ ] Create a table A with an `val: i32` field
- [ ] Generate rows for table A with field values in the range (0..100)
- [ ] Connect client and subscribe to `SELECT * FROM A WHERE val > 0`
(will have all rows from table A)
- [ ] Change your subscription to `SELECT * FROM A WHERE val > 1000`
(should have no rows)
- [ ] Note that after subscription is applied, table A will have no
values

Co-authored-by: Steve Boytsun <steve@clockwokrlabs.io>
2024-10-30 16:33:54 +00:00
John Detter 035ee4beb9 Revert PR 155 (#173)
## Description of Changes
*Describe what has been changed, any new features or bug fixes*

PR 155 introduced a build issue in Unity:


![image](https://github.com/user-attachments/assets/7e88a813-93bd-4b74-ad87-a4c821a7fb98)

This PR reverts back to a known working commit. I have tested after
reverting the commit and the branch is back to working properly.

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

Not breaking

## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

## Testing
*Write instructions for a test that you performed for this PR*

- [x] Tested circle game against this commit and it builds + works

Co-authored-by: John Detter <no-reply@boppygames.gg>
2024-10-16 00:05:17 -05:00
Mazdak Farrokhzad 01a7e3f6e9 Add gzip + none compression algos and let SDK pick compression (#155)
## Description of Changes

Companion to https://github.com/clockworklabs/SpacetimeDB/pull/1802.

## Requires SpacetimeDB PRs

https://github.com/clockworklabs/SpacetimeDB/pull/1802
2024-10-15 19:47:40 +00:00
Jeremie Pelletier 1e13ab5b50 Jeremie/one off query decoupled from table (#163)
## Description of Changes
*Describe what has been changed, any new features or bug fixes*

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

---------

Co-authored-by: John Detter <no-reply@boppygames.gg>
2024-10-12 10:40:26 -04:00
John Detter d2143ccc88 Use SpacetimeDBNetworkManager everywhere (#157)
## Description of Changes
*Describe what has been changed, any new features or bug fixes*

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

Co-authored-by: John Detter <no-reply@boppygames.gg>
2024-10-03 18:15:37 -07:00
Ingvar Stepanyan 2d20acd06e Fix UnityNetworkManager (#141)
This got broken when we switched to a new DbConnection API.

Keep track of all the active connections and update/destroy them from a
singleton game object. Fixes #134.

Marked as a draft for now, because it's untested and because we're not
yet sure that singleton for all connections as requested is the right
approach.

## Description of Changes
*Describe what has been changed, any new features or bug fixes*

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

---------

Co-authored-by: John Detter <4099508+jdetter@users.noreply.github.com>
Co-authored-by: John Detter <no-reply@boppygames.gg>
2024-10-03 19:35:51 -05:00
Ingvar Stepanyan 434c5ffd8a Accept multiple queries in Subscribe (#153)
## Description of Changes

Turns out, we're not ready for single Subscribe per query, so bringing
back this ability.

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

Co-authored-by: John Detter <4099508+jdetter@users.noreply.github.com>
2024-10-04 00:25:05 +00:00
Jeremie Pelletier 1b0e843a98 Jeremie/remove break (#154)
## Description of Changes
*Describe what has been changed, any new features or bug fixes*

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*
2024-10-03 19:00:10 -04:00
Ingvar Stepanyan fa87e36308 Don't actually try to connect to network in tests (#144)
## Description of Changes
*Describe what has been changed, any new features or bug fixes*

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*
2024-10-02 23:19:12 +00:00
Ingvar Stepanyan 9d3336e6f5 Reduce public API surface further (#145)
## Description of Changes
*Describe what has been changed, any new features or bug fixes*

## API

 - [x] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*
2024-10-03 00:18:06 +01:00
Mazdak Farrokhzad b62a464384 Implement websocket changes atop C# sdk changes (#136)
## Requires SpacetimeDB PRs

This is the C# side of
https://github.com/clockworklabs/SpacetimeDB/pull/1761.
2024-10-02 17:18:24 +02:00
Ingvar Stepanyan cfd654f94c Hide more APIs (#140)
## Description of Changes

Removing unstable APIs that are not used by BitCraft; marking others
with [Obsolete] and renaming few others to match the proposal.

One exception is InternalCallReducer - it would need some further
changes to codegen; marking it as Obsolete right now would cause all
generated clients to show noisy warnings.

## API

 - [x] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*
2024-10-01 20:00:32 +01:00
Jeremie Pelletier 113e8dd972 Add DbConnection argument to OnConnect (#138)
## Description of Changes
*Describe what has been changed, any new features or bug fixes*

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*
2024-10-01 13:02:54 -04:00
Ingvar Stepanyan 87a13eb74f Merge table cache into table handle (#139)
## Description of Changes

Merges cache into the table handle as suggested on the original PR +
hides most table methods that shouldn't be part of the stable API.

Few remaining methods will need a codegen change to be available only to
subclasses, so for now that's out of scope.

Same for merging ClientCache into RemoteTables - we shouldn't need a
separate collection, and instead could autogenerate a switch expression
over table name.

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*
2024-10-01 17:37:42 +01:00
Ingvar Stepanyan 5c033a4e4d Subscription API (#137)
## Description of Changes

Implements the subscription builder (at least, the parts that are
possible to implement).

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*
2024-10-01 16:17:45 +00:00
Jeremie Pelletier 76d30fedee c# client SDK (DbConnection + SDK Callbacks) (#131)
Implementation of the db connection proposal for C#

---------

Co-authored-by: Ingvar Stepanyan <me@rreverser.com>
2024-09-30 21:06:33 -04:00