Commit Graph

30 Commits

Author SHA1 Message Date
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
Alex Nemeth ce90583f6b Update quickstart-chat client module bindings from server (#2976)
Co-authored-by: rekhoff <r.ekhoff@clockworklabs.io>
Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
2025-07-24 23:38:24 +00: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
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 f32754b3c7 Fix row deduplication issues (#294)
## Description of Changes
Addresses
https://github.com/clockworklabs/SpacetimeDBPrivate/issues/1585

There was an issue with row deduplication when a TransactionUpdate of
the form:

```
+ k1: v1
- k1: v1
- k1: v1
+ k1: v2
```
appeared, where `k1` is the primary key of a row and `v1`, `v2` are the
full values of that row. The old manner of processing updates would see
this as a no-op. I've updated the logic to handle this case correctly,
at the cost of an extra equality comparison per row in an update.
(Actually it's slightly cheaper than this, it skips the equality
comparison if there is only row with a particular primary key in an
update. This may help speed up processing of large updates e.g. chunk
data in BitCraft.)

## 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] Added a failing test, then fixed it
2025-04-18 08:59:08 -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
rekhoff 9523ba3d27 Adds tests of GenericEqualityComparer (#271)
Adds an additional test of the `GenericEqualityComparer` function for
`Integer`, `String`, `Byte Array`, `Identity`, `User` and `TaggedEnum` type
comparisons.

This PR resolves additional checks as reported in by [Issue
230](https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/issues/230)
that where not-yet covered elsewhere.

## API

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

## Requires SpacetimeDB PRs
No other PR are needed for this to work.

## Testsuite
SpacetimeDB branch name: master

## Testing
- [X] Locally ran `dotnet test` against the `tests.csproj` project and
it passed all tests
2025-03-13 16:50:18 -07:00
rekhoff 25689c14bd Update C# server and client quickstart examples to match tutorial document. (#258)
# Description of Changes
Update the C# server and client SDK quickstart-chat example to match the
code presented in the tutorial, as of
https://github.com/clockworklabs/spacetime-docs/pull/170 .
Also renamed the directory from `quickstart` to `quickstart-chat` in
order to be more specific.

# API and ABI breaking changes

If this is an API or ABI breaking change, please apply the
corresponding GitHub label.

# Expected complexity level and risk

1

## Requires SpacetimeDB PRs
SpacetimeDB branch name: master
com.clockworklabs.spacetimedbsdk: master

# 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!*

- [x] Ran `quickstart-chat` C# server and C# client locally and:
  - Set my name.
  - Sent a message.
  - Restarted and viewed the message backlog.
  - Sent a few more messages.
- Exited, deleted my local token, restarted and connected as a new
identity.
  - Set my new identity's name.
  - Sent a message as my new identity.

---------

Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
Co-authored-by: John Detter <no-reply@boppygames.gg>
Co-authored-by: james gilles <jameshgilles@gmail.com>
2025-03-03 13:35:30 -08: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
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 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
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
Jeremie Pelletier c3be5b08c3 Update to tests/examples follow codegen changes (#160)
## 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 21:12:43 -07:00
Ingvar Stepanyan 2c95bee7b2 Try to catch flaky bugs (#150)
## Description of Changes

We have some flaky bug where Events are getting modified while we're
already iterating over them in the snapshot.

I think this might've been fixed by #144, but add extra checks just in
case so that the exception is thrown in a concrete event that causes it,
and not inside snapshot serialization.

## 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 17:17:06 +00:00
Zeke Foppa affa2af7db Add script to generate nuget.config (#115)
## Description of Changes
Adds a utility script to generate `nuget.config` given a path to the
`SpacetimeDB` repo.

## API
No

## Requires SpacetimeDB PRs
None

## Testing
- [x] CI
- [x] Ran locally

---------

Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
2024-10-03 13:03:29 +01: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
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
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
SteveGibson 589d40480f Logging API (#132)
## Description of Changes
*Describe what has been changed, any new features or bug fixes*

Changed logging based on [this
proposal](https://github.com/clockworklabs/SpacetimeDBPrivate/pull/981)

## API

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

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

Logging interface is different now. `Logger` has been renamed to `Log`,
and its methods have been renamed as well (ex. `Logger.LogError` is now
`Log.Error`)


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

---------

Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
Co-authored-by: Jeremie Pelletier <jeremiep@gmail.com>
Co-authored-by: Steve Boytsun <steve@clockwokrlabs.io>
Co-authored-by: Ingvar Stepanyan <me@rreverser.com>
2024-09-23 13:52:50 -04:00
Mazdak Farrokhzad 2422b8cce1 Nix Primitives.cs - types now defined in main repo (#120)
## Description of Changes

These types have been moved to the main repo, where they are used by
bindings-csharp as well.

## Requires SpacetimeDB PRs

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

---------

Co-authored-by: Ingvar Stepanyan <me@rreverser.com>
Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
2024-08-29 09:32:11 -07:00
Zeke Foppa e28849e22c Revert master to a stable state (#123)
## Description of Changes
Revert `master` to the original state of this PR:
https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/issues/53.

We should prevent merging into `master` from now on, since the
repositories are now merged.

## 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
I loaded a bitcraft world and ran around.

I used the versions listed here:
https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk-archive/pull/57

---------

Co-authored-by: Ingvar Stepanyan <me@rreverser.com>
Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
2024-08-29 12:21:48 -04:00
Ingvar Stepanyan cb59ebac99 Merge Unity SDK into C# SDK (#117)
## Description of Changes

This creates a frankenstein monster of a repo that is compatible with
both .NET / MSBuild as well as can be consumed as a Unity package.

- `.meta` files, Unity manifests and Unity README were copied over from
the Unity repo.
- `examples` and `tests` folders were renamed to `examples~` and
`tests~` correspondingly, as the `~` suffix is the only way to get
entire folders ignored by Unity.
- MSBuild was configured to change `bin` and `obj` to `bin~` and `obj~`
for the same reasons. This doesn't matter for the Git repo, but helpful
for local development where you don't want Unity to try and load local
DLL artifacts.
- NuGet was configured to restore Unity-compatible NuGet DLLs (and
delete others) in a local folder and committed to the repo - so, from
now on, we can easily update them by modifying `.csproj` and via
standard `dotnet restore` / `dotnet build`.

After this change, this repo should be compatible with both .NET CLI
(e.g. `dotnet test`) as well as consumable from Unity, but due to amount
of metadata changes, it needs further testing before we merge repos
properly.

Fixes #114.

## 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: Zeke Foppa <bfops@users.noreply.github.com>
2024-08-28 11:13:33 -07:00