Commit Graph

3186 Commits

Author SHA1 Message Date
Tyler Cloutier bdf4bd1c65 Add files via upload
Signed-off-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
2023-08-02 14:52:19 +02:00
Tyler Cloutier 0b039cf388 Fixed README.md formatting 2023-08-02 14:51:11 +02:00
Tyler Cloutier fc3b9efbbd Updated the README with content 2023-08-02 14:49:41 +02:00
Tyler Cloutier a77f97654a Added basic architecture diagram
Signed-off-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
2023-08-02 12:13:28 +02:00
Alessandro Asoni 1a95b387db Performance improvement for Del/Ins -> Update conversion (#47)
* 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>
2023-08-02 10:31:11 +02:00
John Detter c7dbe3540c Created PR Template (#38)
* Added PR Template

* Changed headers a bit

---------

Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-08-01 21:43:09 -05:00
Tyler Cloutier 1e29725584 Added README.md 2023-08-01 23:17:03 +02:00
Phoebe Goldman 157aeaa499 Avoid panicking in certain unsupported SQL paths (#121)
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.
2023-08-01 23:17:03 +02:00
dbrinkmanncw 7c215ed367 Stop generating OnUpdate if there is no primary key (#120)
Co-authored-by: Derek Brinkmann <dbrinkmann@citadelstudios.net>
2023-08-01 23:17:03 +02:00
Tyler Cloutier 399f1b26d2 Reimplemented the energy tracking for identities (#115)
* 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>
2023-08-01 23:17:03 +02: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
Mario Montoya 20ecb98360 Fix bug in locating fields when a JOIN clause is present (#102)
* Fix bug in locating fields when a JOIN clause is present

* Update crates/lib/src/relation.rs

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

* Update crates/lib/src/relation.rs

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

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

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

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

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

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

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

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

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

* Small doc nits

* Fix test

---------

Signed-off-by: Mario Montoya <mamcx@elmalabarista.com>
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2023-08-01 23:17:03 +02:00
Phoebe Goldman 8230301e5a Rename host argument in SDK's connect to spacetimedb_uri (#119)
This commit renames the first argument to connect from host to spacetimedb_uri. It's not just a host(name), it's the URI of the SpacetimeDB instance.
2023-08-01 23:17:03 +02:00
John Detter a2c712ab38 Default is now testnet.spacetimedb.com instead of (#95)
spacetimedb.com/spacetimedb

Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-08-01 23:17:03 +02:00
Alessandro Asoni 0942a36989 Add get primary key value/type functions to csharp autogen code (#118) 2023-08-01 23:17:03 +02:00
Mazdak Farrokhzad 7e2e62f66d sats: address george's review (#107) 2023-08-01 23:17:03 +02:00
Alessandro Asoni 483704033c Fix/improve incorrect serialization/deserialization of commit messages (#117) 2023-08-01 23:17:03 +02:00
Tyler Cloutier 3e9a555278 cargo fmt 2023-08-01 23:17:03 +02:00
Tyler Cloutier b941cc66b9 Fixed branding on the CLI 2023-08-01 23:17:03 +02:00
Tyler Cloutier c2042e3950 Energy related updates 2023-08-01 23:17:03 +02:00
Tyler Cloutier 4c5e65d5ac Fixed issues with identity token encoding caused by Identity type serialization changes 2023-08-01 23:17:03 +02:00
Tyler Cloutier 9fd9709f3c Fixes to broken energy routes and stuff 2023-08-01 23:17:03 +02:00
dbrinkmanncw 141d1fdd9d Identity generation python (#111)
* Python changes for identity codegen

* Fix bug in identity codegen

* Fix unwrapping identity in codegen

---------

Co-authored-by: Derek Brinkmann <dbrinkmann@citadelstudios.net>
2023-08-01 23:17:03 +02:00
dbrinkmanncw 3f9e1e73af Identity generation typescript (#113)
* no message

* Some fixes

* Fix whitespace issue that was failing tests

---------

Co-authored-by: Derek Brinkmann <dbrinkmann@citadelstudios.net>
2023-08-01 23:17:03 +02:00
Tyler Cloutier 6a7dc32bd9 Update README 2023-08-01 23:17:03 +02:00
Tyler Cloutier 9e90a8ffb1 Added logos 2023-08-01 23:17:03 +02:00
Mazdak Farrokhzad ed9a84641a Identity: use identity_bytes in SpacetimeType (#89)
* 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>
2023-08-01 23:17:03 +02:00
George Kulakowski 3b1c313fa2 Remove unused imports in spacetimedb lib (#106) 2023-08-01 23:17:03 +02:00
dbrinkmanncw ccf3de833a generate types to SpacetimeDB.Types namespace (#88)
* 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>
2023-08-01 23:17:03 +02:00
Mario Montoya 799e1fcb29 Revert toolchain to 1.69 because upstream bug on wasmer. Remove unnecesary lints (#103) 2023-08-01 23:17:03 +02:00
Mazdak Farrokhzad d5b37e9c90 Document + Refactor SATS (#66)
* 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>
2023-08-01 23:17:03 +02:00
dbrinkmanncw efa61148d2 Add ReducerEvent to Reducer callbacks to match C# SDK and provide error message (#94)
Co-authored-by: Derek Brinkmann <dbrinkmann@citadelstudios.net>
2023-08-01 23:17:03 +02:00
Mario Montoya 300e9050a1 Remove implicit transactions and thread the Tx instead (#65)
* Remove implicit transactions and thread the Tx instead

* Split logic for proper Tx handling
2023-08-01 23:17:03 +02:00
George Kulakowski 2e7b2e973c Actually use indexes (#73)
* Actually use indexes

* Get rid of unneeded references
2023-08-01 23:17:03 +02:00
j gilles 432438a0cd Inject logs into module on failure to invoke reducer (#98)
https://www.notion.so/clockworklabs/Print-in-module-logs-when-calling-a-reducer-with-wrong-arguments-8a25d6dd90be443d92d848bbca7c1862
2023-08-01 23:17:03 +02:00
Phoebe Goldman 2926ebc8ec Update client_api.proto docs based on my new understanding. (#101)
Edit a few doc comments in client_api.proto to resolve questions I asked myself while writing the initial docs.
2023-08-01 23:17:03 +02:00
dbrinkmanncw 78f9483702 Switch identities to identity type, Add ReducerEvent to row updates, remove check_callback_signature (#85)
Co-authored-by: Derek Brinkmann <dbrinkmann@citadelstudios.net>
2023-08-01 23:17:03 +02:00
j gilles 751da204e0 Run cargo fmt (#99) 2023-08-01 23:17:03 +02:00
Phoebe Goldman de9b3ea323 Check authorization when attempting to delete a database (#96)
In the ClientAPI /database/delete/:address endpoint, require authorization before deleting a database.
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
Phoebe Goldman 2a520f7293 [SDK] Expose reducer error messages as a field in Status::Failed. (#93)
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.
2023-08-01 23:17:03 +02:00
Phoebe Goldman 36e6dae5f5 [SDK] Generated on-reducer callback register functions. (#86)
* [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.
2023-08-01 23:17:03 +02:00
Mazdak Farrokhzad ec36973acb bindings-macro: add note re. autoinc (#59)
* bindings-macro: add note re. autoinc

* Update crates/bindings-macro/src/lib.rs

Co-authored-by: Kim Altintop <kim@eagain.io>
Signed-off-by: Mazdak Farrokhzad <twingoow@gmail.com>

* spacetimedb_tabletype: minor docs tweaks

* address pheobe's review

---------

Signed-off-by: Mazdak Farrokhzad <twingoow@gmail.com>
Co-authored-by: Kim Altintop <kim@eagain.io>
2023-08-01 23:17:03 +02:00
John Detter 6381d8cf42 Increase some values for canceling reducers (#92)
Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-08-01 23:17:03 +02:00
Ingvar Stepanyan 831a265dc5 Improve release build times (#67)
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.
2023-08-01 23:17:03 +02:00
Mario Montoya 3330ccbb87 Fix output of multiple queries & commands that not return a table like INSERT (#76) 2023-08-01 23:17:03 +02:00
Phoebe Goldman e4eb10a457 [SDK] Functions for saving and loading Credentials to/from disk (#84)
[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.
2023-08-01 23:17:03 +02:00
Phoebe Goldman 7ec32db202 [SDK] on_subscription_applied callbacks (#82)
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.
2023-08-01 23:17:03 +02:00
Phoebe Goldman d70e71d1d5 [SDK] Permit registering callbacks before calling connect (#80)
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.
2023-08-01 23:17:03 +02:00
Phoebe Goldman 5a60c24d50 Add SDK API breakage checkbox to PR template (#83)
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.
2023-08-01 23:17:03 +02:00