Commit Graph

150 Commits

Author SHA1 Message Date
Mazdak Farrokhzad 5e47b61f8a Tables only become public explicitly via #[spacetimedb(table(public))] (#1278)
* make user tables private by default and define privacy via attribute

* switch to spacetimedb(table(public)) syntax

* accept codegen snap changes

* sdk: use public in define_tables!

* bindings-macro: adjust some doc comments

* sdk-test-connect-disconnect: make Connected/Disconnected public tables

* Make Public Private again
2024-06-03 11:22:58 +00:00
Noa f8beb699c7 Implement new rand api (#1283)
* Implement new rand api

* Address comments
2024-05-31 17:42:58 +00:00
Piotr Sarnacki d08e9845a4 Always send TransactionUpdate to the sender (#1111)
* Always send TransactionUpdate to the sender

This commit changes transaction update broadcast to always send an
update to the sender, even if the sender is not subscribed to any
data that was committed. In such case the transaction update is sent
with an empty database update.

* Remove debug printlns

* Update code after rebase

* Fix test

* Update crates/core/src/subscription/module_subscription_manager.rs

Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
Signed-off-by: Piotr Sarnacki <drogus@gmail.com>

* Extract sending message with error handing in module_subscription_manager

* Bring back a new line

* SDK test that the client is notified of a reducer it called

* cleanup subscription code a bit

* Fix merge problem

* Lint + fmt

* Fix test

---------

Signed-off-by: Piotr Sarnacki <drogus@gmail.com>
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
Co-authored-by: Phoebe Goldman <phoebe@goldman-tribe.org>
2024-05-16 12:35:03 +00:00
Ingvar Stepanyan 125ca70959 Switch to a better API for tagged enums for C# (#1177)
With C# records - which are available since C# 9, so covers Unity requirements as well - we can use subclassing and pattern matching to get sum types that look a lot more like Rust tagged enums.

This is a breaking change but IMO worth it for the better API going forward.
2024-05-10 22:05:18 +00:00
Ingvar Stepanyan fe44011e4f C#: rename DbEventArgs to ReducerContext (#1191)
* C#: rename DbEventArgs to ReducerContext

This is no longer an event type, so remove subclassing and rename to match the Rust API.

* Update ReducerContext argument name
2024-05-08 14:00:32 +00:00
Mazdak Farrokhzad 8f85da598c Remove #[spacetimedb(reducer, repeat = _)] support (#1095) 2024-04-22 09:58:39 +00:00
Ingvar Stepanyan 02d0428151 C#: add experimental NativeAOT-LLVM support (#713)
* Add experimental NativeAOT-LLVM support

* Fix codegen ambiguity

* Restore logging redirect
2024-04-03 18:23:39 +00:00
Noa 7d3bdc308b Prune deps from bindings dependency tree (#1014) 2024-04-03 01:54:36 +00:00
joshua-spacetime 47e787877f test(1099): Multi-column index selection through query macro (#1001) 2024-03-21 23:33:13 +00:00
james gilles a0a18ddd57 Rename types in benchmarks (#803)
* Rename types in benchmarks, modify benches run in action

* Fix lints
2024-02-23 20:30:59 +00:00
Phoebe Goldman 3a31c33e81 Add delete_by_{nonunique_column} method to #[spacetimedb(table)] (#859)
- Refactor `bindings::query::delete_by_field` to require `FilterableValue`
  and return `u32` count of deleted rows.
- Add `bindings::query::delete_by_unique_field`
  with the previous behavior of `delete_by_field`,
  i.e. requiring `UniqueValue` and returning `bool` with `true = deleted`.
  This is implemented in terms of `delete_by_field`.
- Macro-generated unique filter funcs call `delete_by_unique_field`
  rather than `delete_by_field`.
- The table macro now generates non-unique delete functions
  alongside the existing non-unique filter functions
  for non-unique fields with primitive types.
- Add uses of `::delete_by_{field}` for both unique and non-unique columns
  to the `rust-wasm-test` module.

Note that this PR does not include any host-side changes;
the diff is localized to the `bindings` and `bindings-macro` crates.
2024-02-16 18:42:05 +00:00
Noa 295ae3dd82 Fix benchmarks (#819) 2024-02-12 20:45:55 +00:00
Noa 37658aae7e Add rust-version to Cargo.toml (#802)
* Add rust-version to Cargo.toml

* Use workspace inheritance to make bumping the spacetime version easier
2024-02-07 20:02:05 +00:00
james gilles fa93200397 1_000_000 insert + update benchmarks (#764)
* Add 1_000_000 insert benches, disabled by default.

* memory architecture fix
2024-02-07 18:24:08 +00:00
John Detter 8524d244f3 Version upgrade to 0.8.1 (#729)
Co-authored-by: John Detter <no-reply@boppygames.gg>
2024-01-18 18:16:58 +00:00
Ingvar Stepanyan 79b2d04210 C# SDK tests (#706)
* Add C# SDK tests

* Add memoization

* Increase timeout

* Mark module_bindings as LF

* Regenerate from Rust again

* Sort tables & reducers for determinism

* cargo fmt

* Lint & fmt fixups

* Lint fixups

* Allow dirs ending in .wasm
2024-01-16 18:09:43 +00:00
Ingvar Stepanyan 7143f25163 Fixes for SpacetimeDB.Runtime package (#654)
As usual, NuGet / MSBuild behaving differently for local projects vs published ones causes build issues that are not revealed by testing...

This is published to NuGet now and verified to work on an empty project.

Also changed the way `SpacetimeDB.Runtime.{props,targets}` are referenced locally by test projects by moving them to `Directory.Build.{props,targets}` at the top level of `modules/` directory. This should simulate behaviour of published NuGet packages a bit more closely - in particular, I verified that it can reproduce the bug in question before the fix, while the previous `<Import />` approach succeeded regardless - and also makes it easier to share the same configs between multiple projects.
2023-12-12 14:42:06 +00:00
Ingvar Stepanyan e9724fc8d0 Add .unwrap() to Rust quickstart 2023-12-07 12:18:52 +00:00
Ingvar Stepanyan 2a33e47179 Add autoinc primary key to integration tests 2023-12-07 12:18:52 +00:00
Ingvar Stepanyan afbd49fe58 Emit codegen files 2023-12-07 12:18:52 +00:00
Ingvar Stepanyan ab63654dab Support arbitrary RHS in C# Query (#586) 2023-12-05 17:28:46 +00:00
John Detter 79ff6dffc6 Version upgrade to 0.8.0 (#622)
Co-authored-by: John Detter <no-reply@boppygames.gg>
2023-12-04 13:19:25 -06:00
Mario Montoya 4ef1bd5296 Refactoring bootstrapping and adding full support for constraints & multi-column indexes (#596)
* Refactoring bootstrapping and adding full support for constraints & multi-column indexes

* Removed deleted code and add some comments

* Add comment for Constraints

* Update crates/core/src/db/datastore/locking_tx_datastore/mod.rs

Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
Signed-off-by: Mario Montoya <mamcx@elmalabarista.com>

* Update crates/core/src/db/datastore/locking_tx_datastore/mod.rs

Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
Signed-off-by: Mario Montoya <mamcx@elmalabarista.com>

* Addressing some PR comments & remove cloning

* Adding details for when fail to decode rows in replay

* Apply Kim's fix for replay bug

* Addressing some PR comments

* Merge

* Fix conflicts

* Fix conflicts

* Fix test

* Fix generation of code for csharp & typescript, now it generate FilterBy for all columns

* Fix for index generation

* Fixing C# index generation

* Merge

* Fix compilation on csharp bindings

---------

Signed-off-by: Mario Montoya <mamcx@elmalabarista.com>
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
Co-authored-by: John Detter <no-reply@boppygames.gg>
2023-12-04 12:04:38 -05:00
Ingvar Stepanyan 4f74a5c5c6 Move to .NET 8 WASI support (#587) 2023-11-30 14:54:26 +00:00
Mario Montoya f3a5dc2228 Move 'constraints' markers to primitive and fix incompatibility with deploy (#561)
* Move 'constraints' markers to primitive and fix 'Multiple primary columns defined for table'

* Fix integration test

* Merge
2023-11-15 11:26:35 -05:00
Mario Montoya 321da54db7 Add integration test for the query macro (#538) 2023-11-13 11:30:48 -08:00
John Detter dff23de939 Version upgrade to v0.7.3 (#536)
Co-authored-by: John Detter <no-reply@boppygames.gg>
2023-11-07 21:55:14 -06:00
Tyler Cloutier 8ba8dba598 Added multi column index usage to the rust-wasm-test module (#500)
Added multi column index usage to the rust-wasm-test module

This also updates integration test.

The number of lines in the output changes as there is 1 additional
line corresponding to the new table.
2023-11-07 16:59:17 +00:00
John Detter b35e184051 Version Upgrade to v0.7.2-beta (#498)
Co-authored-by: John Detter <no-reply@boppygames.gg>
2023-10-30 16:53:06 -05:00
Ingvar Stepanyan 6eff34b7d9 Fix C# generics support (#475) 2023-10-26 14:42:49 +00:00
Mazdak Farrokhzad cba518d90e Use newtypes ColId, TableId, IndexId, SequenceId everywhere (*) (#408)
* Use newtypes ColId, TableId, IndexId, SequenceId everywhere (*)

* Addressing some PR comments

---------

Co-authored-by: Mario Alejandro Montoya Cortés <mamcx@elmalabarista.com>
2023-10-19 11:18:50 -05:00
John Detter 5864bfa8d7 Version upgrade: v0.7.1-beta (#441)
Co-authored-by: John Detter <no-reply@boppygames.gg>
2023-10-17 16:57:36 -07:00
Ingvar Stepanyan ba535f24d1 Move connection events to reducers (#309)
* Move connection events to reducers

* More rebase fixups

* Avoid double-reference

* Filter out special reducers in generate cli

This updates filtering of `__init__` to exclude all special reducers, as well as moves the filtering to centralised place before calling language-specific generate command.

* Incrememted ABI version number

---------

Co-authored-by: Tyler Cloutier <cloutiertyler@aol.com>
2023-10-03 23:19:49 +00:00
John Detter de43e96b11 Version Upgrade to 0.7.0 (#355)
* Saving because I'm testing writing files

* New upgrade program working quite well

* Update license file as well

* Tool seems good to go

* Cargo check is passing, new upgrade-version is ready, old version
removed

* Updating lock file is required for CI to pass

* main.rs clippy lints

* More sensible default

* Version upgrade to 0.7.0 via new version-upgrade util

---------

Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-10-03 22:27:11 +00:00
Phoebe Goldman 59159dbb3d Add address: Address to ReducerContext (#299)
* Add `address: Address` to `ReducerContext`

Initial support for identifying connections via an `Address`,
passed as the caller address in `ReducerContext`.

Notable design choices:

- The same type `Address` is used for clients and dbs,
  as opposed to having distinct `DbAddress` and `ClientAddress` types.
- For automatic reducers (init, scheduled, &c), the passed `Address`
  is the database's address, not the address of the client which called `publish`.
- Clients may specify an `Address` as a query parameter
  to the `subscribe` and `call` endpoints.
  If they do not, an `Address` will be randomly generated for them.

Still to do:

- Send the client's `Address` alongside their `Identity` and token
  upon WebSocket init in `IdentityToken`,
  so the client can save its `Address` for re-connection.
- SDK support.
- C# module support.
- Documentation.
- Refuse new connections if an existing connection
  with the same `(Identity, Address)` pair exists.
- Ensure we can store `Address` in tables,
  so modules can track connected clients,
  and ser/de `Address`, so those tables can be synced to clients.

* Use `None` in `ReducerContext` for HTTP calls without client address

* Fix typo in trait argument name

* `Address` representation amenable to SDK usage

Similar to `Identity`, make `Address` a product type with a double-underscored field name.

This will allow SDKs to distinguish `Address` from `Vec<u8>`,
but does necessitate some ugly `AddressForUrl` hackery
to get ser/de working correctly in different contexts.

This commit does not yet include SDK support for `Address`,
only the server-side machinery necessary for it.

* Add client_address parameter to /publish; pass to init and update reducers

Per discussion with Kim, it's useful for SpacetimeDB-cloud
for the client_address passed to the init reducer
to be that of the caller of /database/publish,
rather than the database's address.

This commit implements that behavior. Now:
- `init` and `update` take the client_address passed to publish, if any,
  or `None` if no client_address was supplied.
- Scheduled reducers never receive a client_address.
- Reducers invoked by HTTP /call take the client_address passed to /call, if any,
  or `None` if no client_address was supplied.
- Reducers invoked by WebSocket always receive the address of the WebSocket connection.

* `Address` support in Rust client SDK

* Add test that addresses are stable within a client process

* Run rustfmt against merge changes

* Not sure why my local `cargo fmt` didn't get this...

* Add caller_address argument to reducer arguments in Rust SDK

* rustfmt again...

* Add caller address to `EventJson` message

* Python codegen for client addresses

* C# module support for client addresses

* Fix scoping error

* Add `Address`-related stuff to C# codegen

- Emit `SpacetimeDB.Address` for address types
- Add `callerAddress` field to `ReducerEvent`

* TypeScript codegen changes

* Fix merge conflict with new test

* Run rustfmt

---------

Co-authored-by: Ingvar Stepanyan <me@rreverser.com>
2023-09-29 23:39:34 -07:00
Noa d8395fe138 Fix derive(Deserialize) on void enum (#330)
* Fix derive(Deserialize) on void enum

* Also fix derive(Serialize) for empty enums; remove empty reducers from tests

---------

Co-authored-by: Phoebe Goldman <phoebe@goldman-tribe.org>
2023-09-29 23:27:37 -07:00
james gilles 010c7e3c1e Wrangle benchmarks (#289)
Refactor benchmarks framework to allow direct comparison of spacetime modules, the spacetime datastore not through a module, and sqlite.
2023-09-29 23:12:12 +00:00
Phoebe Goldman 5f8615a367 Add SDK test that verifies connect/disconnect callbacks happen (#326)
* Add SDK test that verifies connect/disconnect callbacks happen

* Add C# connect/disconnect test

---------

Co-authored-by: Ingvar Stepanyan <me@rreverser.com>
2023-09-27 11:29:09 -04:00
Ingvar Stepanyan 1b9e35129c Move C# bindings into the tree (#324)
This allows to make and test ABI-breaking changes much more easily than before.

For now moved them under crates/bindings-csharp - on one hand, it's not a crate, but on another it's the most logical place within our current project structure if we think of `crates` folder as general `projects` folder.
2023-09-26 15:33:30 +00:00
Ingvar Stepanyan f98694f707 Add C# integration test (#291) 2023-09-13 15:53:07 +01:00
Phoebe Goldman 32ac808804 SDK test suites (#258)
* Simple SDK test harness; SDK test module

Yet to come: actual SDK tests.

* Quiet clippy lint about "too many arguments"

* Lints are named with underscores, not dashes...

* Will this make clippy shut up?

* Go nuclear on disabling `too_many_attributes` lint. Sigh.

* WIP SDK test client, and fix bugs in Rust codegen

Compiling the module_bindings for the sdk-test module revealed two bugs:

- Enums holding structs generated incorrectly,
  unpacking the struct into the enum's payload.

- Recursive types would cause the codegen to attempt to recursively import
  the current module into itself.

* One (1) actual runnable test in the sdk crate

* Exclude test-client from CI

The sdk tests already build this crate (though they don't clippy or fmt it).

Attempting to build, test, fmt or clippy it as-is will fail
because the module_bindings are not committed.
This is intentional, as the SDK test suite wants to generate the module_bindings
during its run.

* Rustfmt ignore generated module_bindings

It turns out `cargo fmt` doesn't actually support the `--exclude` option
the way `cargo clippy` does.

Instead, just `#[rustfmt::skip]` the `mod module_bindings;` decl.

* Actually commit test file...

God, I'm so bad at remembering to commit new files.

Anyway, add a test for deleting rows with primitive unique fields.

* Make CLI tool available in tests workflow

The SDK tests need to run `spacetime start`, `spacetime generate` and `spacetime publish`.

* Test update events with primitive pk types; split test-client into files

* Tests with `Identity` fields in tables

* Tests for reducer callbacks, both successful and failing

* Tests with vecs of stuff, with structs, with enums

* Test that should fail, test that uses a large table with many columns

* Test for resubscribe functionality

* Test of reauth; fix major bug in `TestCounter`

I misread `Condvar::wait_timeout_while` as `Condvar::wait_timeout_until`,
and flipped my predicate.
This led to false negatives (i.e. tests that passed that shouldn't have).

* A fistful of doc comments

* Avoid race condition running multiple tests with same client project

This commit fixes a race condition which sometimes caused the SDK tests to fail
because multiple `spacetime generate` processes running concurrently
would clobber each others' output,
potentially deleting it while a `cargo build` or `cargo run` process was running.

Now, the test harness will only run `spacetime generate` at most once
for any given directory.

* Add env_logger to SDK test client

* RUST_LOG=trace when running test clients

* quieter logs in test client: only warn-level and higher
2023-09-12 12:50:47 -05:00
Mario Montoya 80a0a29704 Move cargo deps to the workspace (#172)
* Moving deps to workspace

* Merge
2023-08-11 15:24:31 -07:00
Phoebe Goldman 5cc11d8b06 Add quickstart-chat example module and client (#116)
This commit adds the `quickstart-chat` Rust module and client to the appropriate examples dirs.
2023-08-01 23:17:03 +02:00
Phoebe Goldman 3e215322e5 [Modules] spacetimedb(index) macro now uses more consistent parens. (#97)
Prior to this comment, the `#[spacetimedb(index)]` attribute accepted its arguments like:

```rust
\#[spacetimedb(index(btree), name = "NAME", FIELD_NAMES...)]
```

Putting the `NAME` and `FIELD_NAMES` arguments outside of the
inner parens was uninutitive. With this commit, the syntax is changed to:

```rust

\#[spacetimedb(index(btree, name = "NAME", FIELD_NAMES...))]
```
2023-08-01 23:17:03 +02:00
Mario Montoya c154e3a6df Private tables (#17)
* Initial bootstrap for private tables

* Separate Access (private, public) for kind o table (system, user)

* Validates the access to private tables

* Check auth for drop table
2023-08-01 23:17:02 +02:00
Mazdak Farrokhzad b2e4d371e8 CLI: Improves errors for call + misc refactoring (#45)
* cli: refactor + improve call errors

* cli: improve call errors

* cli: simplify tasks

* misc improvements

* cargo fmt + clippy
2023-08-01 23:17:02 +02:00
Mazdak Farrokhzad 39dbc381e2 rename the APIs (#41) 2023-08-01 23:17:02 +02:00
Mazdak Farrokhzad 5cfafd3da7 make API call errors convertible to String (#27) 2023-08-01 23:17:02 +02:00
Tyler Cloutier 0b6cddca13 test (#1)
* test

* Fixed CI

* Fixed tests

* Fixed formatting

* Fixed test error by removing chrono default features

* Rename smoketests CI thing

* Hopefully fix the testing issue

* Fix typos

* Fixed install git-hooks

* Fixed formatting

* Fixed compile error

* fixed testing issues
2023-08-01 23:17:02 +02:00
Tyler Cloutier 44df6c6e7d Initial commit 2023-08-01 23:16:37 +02:00