85 Commits

Author SHA1 Message Date
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
Mario Montoya d456ce4a2e Print the elapsed time & # of returned rows in the interactive repl (#344)
* Print the elapsed time & # of returned rows in the interactive repl

* Fixed clippy warning

* Change formatting of timings to be like psql & remove it from direct sql calls

---------

Co-authored-by: Tyler Cloutier <cloutiertyler@aol.com>
2023-10-02 17:43:45 -07:00
Phoebe Goldman f0e4b004da Commit test clients' module_bindings (#346)
* Commit test clients' module_bindings

Having discussed with the team, I've come around to it being correct
to commit the `module_bindings` for the SDK tests' two test clients.

This way, people not working on codegen can run `cargo test --workspace` &c,
and open the test clients with rust-analyzer without any additional rigamarole.

The downside is that any time codegen changes,
we'll see very large commits touching all of these files,
but consensus is we don't really care.

An additional upside is that now we can run clippy against the bindings in CI,
which will incentivize ensuring that the bindings generate lint-free code.

* Add linguist-generated=true for generated module bindings

* Top-level .gitattributes sets `module_bindings` as generated
2023-10-02 16:56:52 -07:00
dbrinkmanncw 4349370f68 Add filter_by autogen functions for option types in csharp and python SDKs (#275)
* Add filterby autogen functions for option types in csharp and python sdks

* Clippy

* Fixed lint

---------

Signed-off-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
Co-authored-by: Boppy <no-reply@boppygames.gg>
Co-authored-by: Tyler Cloutier <cloutiertyler@aol.com>
Co-authored-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
2023-09-30 07:12:45 +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
John Detter 905da73dd0 Added Git Commit Hash to Version Command (#340)
* Added git commit hash to version command

* Fixed clippy warning

---------

Co-authored-by: Boppy <no-reply@boppygames.gg>
Co-authored-by: Tyler Cloutier <cloutiertyler@aol.com>
2023-09-30 06:25:20 +00:00
Phoebe Goldman b51e5516cf [SDK] generate struct Module to hold dispatch functions (#239)
Prior to this commit, the Rust SDK passed autogenerated dispatch functions around as
function pointers (i.e. values of `fn` types).
This was brittle and inextensible; adding a new dispatch function
or changing the type of a dispatch function
required threading a new argument through `BackgroundDbConnection::connect`,
and a new field to whatever struct was supposed to invoke the dispatch function.

This commit adds a new trait `SpacetimeModule`,
which has a method for each autogenerated function.
`BackgroundDbConnection::connect` accepts an `Arc<dyn SpacetimeModule>`,
which it passes to various components which need access to the autogenerated methods.
The CLI's `generate` with `--lang rust` generates a unit struct `Module`,
which implements the trait.
The generated `connect` function passes `Arc::new(Module)` to the internal connect method.

This greatly reduces the maintenance burden of adding new dispatch functions.
Now, we only need to alter:
- The definition of `trait SpacetimeModule`.
- The generation of the instance.
- Whatever internals call the method.
2023-09-29 09:54:38 -04:00
Piotr Sarnacki 205ad6b2d7 Client binaries builds (#337)
This PR adds builds for client binaries for all of the platforms that we support. The binaries are uploaded to a DO Spaces bucket.
2023-09-28 19:16:43 +00:00
John Detter 5cf76927a9 Positional Arguments (#322)
* Working on this but found another bug

* Fixing describe

* Working on this but found another bug

* Tested working, have to update tests

* Updated tests, hopefully I caught everything

* Clippy fix

* Addressing more clippy issues

* Cargo fmt

* Implementing Phoebe's feedback

---------

Co-authored-by: John Detter <no-reply@boppygames.gg>
2023-09-27 12:44:24 -05:00
John Detter befbc5c64a Fixing describe (#323)
Co-authored-by: John Detter <no-reply@boppygames.gg>
2023-09-27 12:43:49 -05:00
Phoebe Goldman fca7c27946 Clippy: forbid println and friends (#305)
We've had recurring issues with `println` calls sneaking in
where `log` crate macros would be more appropriate.
This commit adds a Clippy warning for uses of the global I/O macros,
i.e. `print`, `println`, `eprint`, `eprintln` and `dbg`.

The lint is disabled by a more-specific `clippy.toml` in the `cli` and `sqltest` crates,
as well as using `allow` attributes in `standalone`'s `subscommands` module.

Additionally, this commit converts a handful of prints in `core/utils` to `log::info`.
2023-09-20 13:24:26 -04:00
Kim Altintop ea2bae4583 Cloud next (#173)
* Client API changes to accomodate new cloud architecture

The exact trait interfaces for `client-api` is TBD

* Ensure we're not blocking when accessing the filesystem

* Derive Clone for SendGridController

* Add YOLO error variant to InsertDomainResult

* Rebase

* fixup! Rebase

* Fix SpacetimeType for Address

* Temporarily disable message / frame size limits for SDK WS

* Remove get_database_instance_state from API trait

It's an internal (worker db) thing, which does not need to be satisfied
by impls.

* Update indexes when updating a database

It turns out that the order of the index definitions in the proposed
schema may differ from those returned from the catalog, causing valid
(i.e. no-op) updates to be rejected. While at it, allow updating table
indexes so as long as the (column) schema remains unchanged.

* Update indexes when updating a database

It turns out that the order of the index definitions in the proposed
schema may differ from those returned from the catalog, causing valid
(i.e. no-op) updates to be rejected. While at it, allow updating table
indexes so as long as the (column) schema remains unchanged.

* Fix -S instead of -s for update-module smoke test

-s now means "server", -S "skip clippy", changed in:

a1e9984 (Multiple server configurations for CLI (#214), 2023-09-01)

* Invalidate schema cache when committing a tx

* Use long options in update-module.sh, fix unused warning

* Add test asserting schema_for_table reflects index updates
2023-09-20 07:42:37 +02:00
Ingvar Stepanyan c47e571d2d Avoid relying on global CLI in tests (#294)
This switches tests from invoking a spacetimedb CLI found on PATH to always using up-to-date version by depending on the CLI crate as a library.

---------

Signed-off-by: Phoebe Goldman <phoebe@goldman-tribe.org>
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
2023-09-14 09:15:32 -04:00
Ingvar Stepanyan 676dfbe10c Refactor Option<Vec<_>> in Config (#292) 2023-09-13 19:10:43 +00:00
Ingvar Stepanyan f98694f707 Add C# integration test (#291) 2023-09-13 15:53:07 +01:00
Ingvar Stepanyan b1c69834da Bump C# for ABI 4.0 (#282) 2023-09-13 14:30:51 +02: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
SteveBoytsun 9dc90bb04c Fixed json serializer getting progressively slower (#226)
Co-authored-by: Steve <steve@codefics.com>
2023-09-11 12:35:01 -05:00
Phoebe Goldman a1e9984840 Multiple server configurations for CLI (#214)
Alters the CLI's configuration format to support storing multiple server configurations,
and having each server configuration store an (optional) default identity.
Many CLI commands take an additional -s argument, the server on which to operate,
which defaults to the configured default_server.
Using -s consistently requires renaming the publish skip-clippy short flag to -S.

Per discussion with @jdetter , this PR does not directly associate identities with servers.
Instead, each server configuration stores the server's "fingerprint" (i.e. PEM-formatted ECDSA public key),
and the CLI uses that public key to decode tokens to determine if they apply to a given server.
This architecture allows the CLI to behave reasonably
when multiple server configurations use the same set of tokens,
e.g. if multiple distinct URLs resolve to the same SpacetimeDB instance.
For example, one could imagine a configuration with server configurations for both http://127.0.0.1:3000
and http://localhost:3000, which should use the same set of identities.
2023-09-01 17:29:20 +00:00
George Kulakowski be289daf6f Update wasmer (#220)
* we need wasmer 4.1.1 or newer

* Add a newly required dependency on wasmer-types

* from_trap -> from::<Trap>

* Finish upgrading to wasmer 4

* Bump to Rust 1.72.0

---------

Co-authored-by: Noa <coolreader18@gmail.com>
2023-08-29 18:07:35 +00:00
Phoebe Goldman 9b084950cf [CLI] Report text of error response in logs (#241)
Prior to this commit, the `logs` subcommand would print an unhelpfully generic HTTP error
on failure. Notably, this error did not include the actual response body.

With this commit, the error includes the HTTP response body.
For example, trying to print logs for a server you don't own shows:

Error: Identity does not own database, expected: 69c07c49846bcf11d7b7cb411018ded585a5a6d9045f8a1a39fa638e9db48436 got: 915cff645f94f52467c43734d54a26d565abb69c7506e30127dd616ca4790414
2023-08-26 08:58:42 -04:00
George Kulakowski 66a8f22e94 Remove the bitrotted trace replay functionality (#219)
* Remove the bitrotted trace replay functionality

* cargo fmt

* Remove unused tracelogging feature from ci actions

* Remove unneeded clone
2023-08-22 21:29:05 +00:00
John Detter 8eb1743b75 Better Version Logging (#206)
* Added path to `spacetime version`, added version and path to `spacetime
start`

* Removed comment

---------

Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-08-21 14:00:32 -05:00
dbrinkmanncw e65cb89f25 Python sdk was assuming table members and reducer names were in Snake case. This converts them for the c# modules where public members are generally camel case. (#166) 2023-08-12 08:58:00 -07:00
John Detter 116bdee090 Version upgrade to 0.6.1 (#180)
* Version upgrade to 0.6.1

* Upgrade version used by CLI

---------

Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-08-12 08:56:28 -07:00
Mario Montoya 80a0a29704 Move cargo deps to the workspace (#172)
* Moving deps to workspace

* Merge
2023-08-11 15:24:31 -07:00
Ingvar Stepanyan ceb1f4330e Auto-upgrade C# deps on installation (#147) 2023-08-08 11:00:04 +01:00
George Kulakowski b436ce6847 Remove sendgrid from standalone (#142)
* Remove sendgrid support from the standalone stdb controller

* Make name_or_identity resolution falliable
2023-08-04 10:57:09 -07:00
George Kulakowski 26c49f2571 Allow spacetimedb to run in an in-memory mode (#137)
* Allow spacetimedb to run in an in-memory mode

* cargo fmt and review comments

* Fix test code

* Ensure the db directory is always created
2023-08-04 10:56:57 -07:00
Tyler Cloutier 3e0caff415 Updated version to 0.6.0 2023-08-03 01:39:03 +02:00
Ingvar Stepanyan 495c07d831 C# CLI integration (#126)
Co-authored-by: Derek Brinkmann <dbrinkmann@citadelstudios.net>
2023-08-02 22:11:23 +01:00
George Kulakowski 7d5764b181 Don't panic when an identity does not exist (#135) 2023-08-02 20:01:14 +02:00
John Detter 0f63e70694 spacetime start 2 (#125)
* spacetime start

README revert

Reverted stuff that shouldn't have changed

* Build fix

* Cargo fmt

* Cargo clippy

---------

Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-08-02 11:21:49 -05: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 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
Tyler Cloutier b941cc66b9 Fixed branding on the CLI 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
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
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
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