* generate types to SpacetimeDB.Types namespace
* Fix the way we look for Reducer class
* Fix using Identity as Primary Key
* Performance improvement for Del/Ins -> Update conversion
* Fix
* work
* fixes
* Remove accidental commit
* Fix indentation
---------
Co-authored-by: Derek Brinkmann <dbrinkmann@citadelstudios.net>
Prior to this commit, it was possible for certain CLI `spacetime sql` invocations
to crash SpacetimeDB by including unsupported features.
This was due to the SQL parser using the `todo!` macro,
where it should have returned a `PlanError::Unsupported` error.
With this commit, several uses of `todo!` are rewritten
to instead return errors,
which are translated appropriately into 400 responses,
rather than crashing SpacetimeDB.
* Refactoring some stuff for energy
* Fix an issue with i128 query params
* Infinite budget in Standalone
* Energy and crash fixes
* Hopefully fixed the test that now has energy
* Addresses Centril's comments
* Cargo fmt
---------
Signed-off-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
* Identity: use identity_bytes in SpacetimeType
* Use SDK's version of Identity instead
Signed-off-by: John Detter <4099508+jdetter@users.noreply.github.com>
* make CI happy
* make axum happy<
* make axum happy v2
* Identity Codegen Impl C# (#100)
* Changes required for identity generation in csharp
* Clippy fix
* Seems to be working
* Fixes based on Mazdak suggestions
---------
Co-authored-by: Boppy <no-reply@boppygames.gg>
Co-authored-by: Derek Brinkmann <dbrinkmann@citadelstudios.net>
* Fix compile error that somehow got merged in from https://github.com/clockworklabs/SpacetimeDB/pull/100
* Minor changes to allow `Identity` columns and reducer args in the SDK
- `sdk::identity::Identity` must now be `Hash`,
because declaring a `#[primarykey]` column with type `Identity`
will cause the SDK to generate code that uses `Identity` as a `HashMap` key.
This instance was previously not necessary because the key would be `Vec<u8>`,
but probably should've been included anyway.
- The codegen can just refer to `Identity` without path-qualifying,
because it already imports the `Identity` type into all files it generates.
* address pheobe's review
* pacify clippy
---------
Signed-off-by: John Detter <4099508+jdetter@users.noreply.github.com>
Co-authored-by: John Detter <4099508+jdetter@users.noreply.github.com>
Co-authored-by: Boppy <no-reply@boppygames.gg>
Co-authored-by: Derek Brinkmann <dbrinkmann@citadelstudios.net>
Co-authored-by: Phoebe Goldman <phoebe@goldman-tribe.org>
* generate types to SpacetimeDB.Types namespace
* Add Reducer partial class to csharp codegen to tag it with the ReducerClass attribute
* Changes based on feedback
* Fix SpacetimeDB tests
* One more smoketest fix
---------
Co-authored-by: Derek Brinkmann <dbrinkmann@citadelstudios.net>
* Document most of SATS
* sats: simplify Serialize impls
* sats: simplify Deserialize impls
* improve sats::de docs
* document sats::bsatn
* simplify sats fmt/map notation
* value serializer: docs + opt
* docs/refactor sats::algebraic_value::{ser,de}
* sats: document serde conversions
* cargo fmt
* small fixes
* fix tests
* fix serde feature
* sats: address pheobe's review
* fix doc comment
* fix test failure
* Remove unusued import
* Fix a borrowing issue introduced by the merge of master
The definitions of these were tweaked in some way, I think,
such that references to them are no longer automatically 'static?
---------
Co-authored-by: George Kulakowski <george@clockworklabs.io>
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...))]
```
Prior to this commit, the error messages returned by reducers
were unavailable to clients; `Status::Failed` was a singleton.
With this commit, `Status::Failed` holds a `String`,
the string representation of the `Err` returned by the reducer.
This means that `Status` is no longer `Copy`,
and must be passed by reference to callbacks instead of by value.
* [SDK] For each reducer, generate `on_{reducer}` and `once_{on_reducer}`
Prior to this commit, to register an on-reducer callback for a reducer `set_name`,
a client author would write `SetNameArgs::on_reducer(...)`,
with their callback accepting a reference to a `SetNameArgs`
which contained the reducer arguments.
Now, in addition to that interface, we generate a function `on_set_name`,
which accepts a callback that takes the arguments unpacked,
rather than as a struct.
That is, for the quickstart's `set_name` reducer, we generate:
```rust
pub fn on_set_name(
mut __callback: impl FnMut(&Identity, Status, &String) + Send + 'static,
) -> ReducerCallbackId<SetNameArgs> {
SetNameArgs::on_reducer(move |__identity, __status, __args| {
let SetNameArgs { name } = __args;
__callback(__identity, __status, name);
})
}
```
Note the use of double-underscored variable names to avoid name collisions,
since we can't `gensym` a unique name.
We also generate `once_on_set_name`, which is like `on_set_name`,
but takes a `FnOnce` instead of a `FnMut`;
and `remove_on_set_name`, which un-registers a callback.
* Also generate `remove_on_{reducer}` functions to un-register callbacks.
Thin LTO should be about as good as far LTO, but much faster, and debug info is something that takes enormous amount of time to handle throughout build pipeline but something we don't usually need in release builds (symbol information should be enough if it's backtraces that we're interested in).
This cuts `cargo build --release` for the CLI from 9m 40s to 5m 20s on my machine.
[SDK] Functions for saving and loading `Credentials` to/from disk
This commit adds two functions to the Rust SDK, identity::save_credentials and identity::load_credentials, which abstract over the common desire to save a user's credentials to a file in (a subdir of) ~, and load it when re-connecting.
In addition to de-duplicating common functionality, this allows us to remove a relatively complex section of the Rust SDK Quickstart guide.
This commit adds support for the `on_subscription_applied` callback,
which runs when the initial rows of a subscription become available
after a `subscribe` call.
Prior to this commit,
all interfaces for registering and de-registering callbacks returned `Result`,
with an error when attempting to register a callback before `connect`ing.
This was due to a quirk in the SDK's implementation,
where callbacks were stored alongside information
supplied by `connect`, e.g. autogenerated dispatch functions.
With this commit, the SDK stores a partially-initialized `BackgroundDbConnection`
in a `lazy_static`,
into which callbacks can be registered.
The autogenerated `connect` function finishes initializing the `BackgroundDbConnection`,
setting various `Option` fields to `Some`.
This means it is now possible to register callbacks before calling `connect`.
In particular, this prevents a race condition where `on_connect` callbacks
might never be invoked
because credentials might have become available after calling `connect`,
but before registering the callback.
Many user-facing functions which interact with callbacks
have had their return types changed;
where they previously returned a `Result`,
they now return the "success" type unwrapped.
The Rust SDK lives in this repository
and exposes an API on which Rust clients will depend,
distinct from both the module API
and the ClientAPI (which is the protocols all SDKs use to commuticate with a module).
This commit adds a checkbox to the PR template,
in the style of the two existing checkboxes,
to identify breaking changes to the SDK API.