Commit Graph

3186 Commits

Author SHA1 Message Date
Mario Montoya a9e3c842b4 Removing 'repl' as a distinct option for the 'cli' (#62)
* Removing 'repl' as a distinct option for the 'cli' and move into the 'sql' invocation with --interactive

* Move up the logic for parsing in repl
2023-08-01 23:17:03 +02:00
John Detter 0b0c533830 Smoketests run in parallel (#49)
* Working on improving commands that use identities

* Fix lints

* Reverted file that shouldn't have changed

* Found and fixed all other todos

* Addressed more CLI TODOs

* Fixes for formatting issues

* Set names of identities

* Set name of identities + clippy

* Small fix

* Added the start of a doc comment, switching over to another PR

* Fixed tests that needed to be updated

* Addressed more feedback and fixed several clippy issues

* Small fix

* Apply suggestions from code review

Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
Signed-off-by: John Detter <4099508+jdetter@users.noreply.github.com>

* Added more doc comments

* Addressing more feedback

* Fixed really old bug in SpacetimeDB

* Tests to verify new functionality

* Fix clippy lints

* Email during identity creation is optional

* Some work

* Getting smoketests working on mac

* All tests are passing except known failing tests

* Working on parallel smoketests

* Fixed some bugs in saving configs that was preventing this from working

* Fixes required for parallel tests

* Tests are working in parallel

* Pruned changes

* retab

* re-retab

* retab the lib file

* Cargo profile for building more quickly

* I have to rebase on another PR

* smoketest fixes

* create_project and reset_project are now the same thing, removed
create_project

* More fixes

* Removed print statement

* Small fix

* Another fix

* Tons of improvements to the smoketests

* Have to rebase on master

* Small fixes

* More progress

* Finally working correctly!

* Apparently we're missing this

* Enable command output

* Listing installed targets

* Clean before building

* What is going on

* Something super wonky going on

* Another test

* Skip building containers for now

* Small fix

* Test using cargo instead

* Changed workflow a bit

* CI is stuck

* Small fix

* Another fix

* Try cargo run instead of building spacetime CLI

* Removed workflow step

* Fixing all of the tests

* Identity test

* Tests should finally be working

* Enable debug

* Remove spacetime from path

* Another try

* Logic fix

* Another fix

* Another fix

* Working now?

* Another fix

* Finally working again

* Adding github containers back in

* CI fix

* Use SpacetimeDB Large Runner

* Updated test to get more output

* Changed 0ms to 10ms to improve parallel test stability

* Removed unused logs

Signed-off-by: John Detter <4099508+jdetter@users.noreply.github.com>

* Removed unnecessary reset_project

* Removed reset_config where its not needed

* Reset template

---------

Signed-off-by: John Detter <4099508+jdetter@users.noreply.github.com>
Co-authored-by: Boppy <no-reply@boppygames.gg>
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2023-08-01 23:17:03 +02:00
John Detter 047f06382e Use SpacetimeDB Large Runner (#81)
Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-08-01 23:17:03 +02:00
John Detter 5cbfd63893 Cargo Fmt on Generated Rust Files (#79)
* Run cargo fmt on all rust output files

* Lint fix

---------

Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-08-01 23:17:03 +02:00
Phoebe Goldman f87a08942d [SDK] Small changes from review of Rust client quickstart draft (#78)
* SDK: Convert `http[s]` uri schemes to `ws[s]`

Prior to this commit, the Rust SDK would reject host URIs which began with `http://` or
`https://`, requiring exactly one of `ws://` or `wss://`.
Now, the SDK converts `http` URI schemes to their websocket equivalents,
so clients can do `connect("http://localhost:3000", "my-database", my-creds)`.

* SDK: Append `Args` suffix to generated reducer args structs

This reduces the liklihood of name collisions,
e.g. when a user has both a table `Guess` and a reducer `guess`.
Prior to this commit, in that case, the SDK would generate
a `struct guess::Guess` for the table, and
a `struct guess_reducer::Guess` for the reducer args.
Now, the latter is `struct guess_reducer::GuessArgs`.
This will allow the CLI's codegen to re-export all generated structs
from its main `mod.rs` file.

* SDK: generated `mod.rs` re-exports all other files

The `mod.rs` generated by `spacetime generate --lang rust`
now re-exports all of the types and functions
defined in other files it generates.

This allows users to write e.g. `spacetime_types::Player`,
rather than `spacetime_types::player::Player`.
2023-08-01 23:17:03 +02:00
Phoebe Goldman f2c0d1ab52 Return an error when scheduling a reducer with a long delay (#77)
Prior to this commit, it was possible for a module to crash SpacetimeDB
by scheduling a reducer with a delay longer than ~2yrs.
This was due to our use of `tokio_utils::time::DelayQueue` to handle scheduling.
`DelayQueue`'s internal data structure imposes a limit of 64^6 ms on delays,
a little more than two years.
Attempting to insert with a delay longer than that panics.

With this commit, we avoid the panic by checking ourselves that the requested delay
is not longer than 64^6 ms.
This requires bubbling a `ScheduleError` up from `Scheduler::schedule`
to `WasmInstanceEnv::schedule`, where it is converted into a `RuntimeError`
which crashes the module.

`Scheduler::schedule` could also fail because its transaction to compute a new id
was fallible. This seems unlikely to ever fail, and if it does, we have bigger problems,
so `unwrap`ping might still be reasonable for that case,
but this commit converts it into a handle-able `Err`or anyway,
as there's essentially no cost in complexity to doing so.
2023-08-01 23:17:03 +02:00
Mario Montoya 6f041dbde9 Fix bug in assigment of PK constraints & creation of associated indexes. Upgrade SQL parsing (#74) 2023-08-01 23:17:03 +02:00
John Detter 187cc74dd4 Spacetime Server Show + Ping (#75)
* Added commands for spacetime server list and spacetime server ping

* Small fix

* Updated test

---------

Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-08-01 23:17:03 +02:00
Phoebe Goldman 1d56acc906 SDK: Correctly encode auth header, and ser/de Credentials (#68)
* SDK: Correctly encode auth header, and ser/de `Credentials`

Prior to this commit, the Rust SDK incorrectly encoded a `Token` passed to `connect`,
making it impossible to re-connect an existing user.
(Shows what I get for never testing that.)
With this commit, auth tokens are correctly base64-encoded
in an `Authorization: Basic` header with the username `token`,
which allows re-connecting as an existing user.

Also, it was difficult to re-use `Credentials` from the Rust SDK, as:
- they were opaque types with non-exported members
- they did not implement any serialization / deserialization
This commit makes `token.string` and `identity.bytes` public fields,
and implements SATN `Serialize` and `Deserialize`
for `Identity`, `Token` and `Credentials`,
allowing clients to save their credentials for re-use, e.g. to a file.

* SDK: Handful of small changes

- `subscribe_owned` accepts `Vec<String>`; behaves like `subscribe`.
  - While developing `letrs`, a demo game, we needed to generate query strings at runtime,
    and passing them to `subscribe` would have involved an unergonomic dance
    of taking references which would then be converted to owned containers
    by the SDK.
    `subscribe_owned` eliminates that, allowing client authors
    to construct a set of queries at runtime and pass it directly to the SDK,
    without intervening referencies and copies.
- Docstrings for `subscribe` and `subscribe_owned`.
- Methods on `Identity` and `Token` for converting to/from strings and byte-vectors.
- Removed long-forgotten `println` within `connect`
  which wrote the computed URI to stdout.
2023-08-01 23:17:03 +02:00
John Detter a1d4852f89 Crate name rust-wasm-test was renamed to rust-wasm-test-module, fixed (#71)
script

Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-08-01 23:17:03 +02:00
dbrinkmanncw 5e37596b20 Fix case on primary_key for typescript (#63)
Fix name of python sdk package for python

Co-authored-by: Derek Brinkmann <dbrinkmann@citadelstudios.net>
2023-08-01 23:17:03 +02:00
Mario Montoya a723b742df Fix bench crate, preserve TmpDir (#69) 2023-08-01 23:17:03 +02:00
John Detter 627b3513c8 Fixed issue where [SpacetimeDB.Enum] tag was not being generated in C# (#70)
Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-08-01 23:17:03 +02:00
John Detter 4f253d6337 Fixed clippy lint issue (#64)
Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-08-01 23:17:03 +02:00
Tyler Cloutier 18705bc3d8 Fix potential panic bug 2023-08-01 23:17:03 +02:00
Tyler Cloutier 4425fdd01f Bumped vm version number 2023-08-01 23:17:03 +02:00
Tyler Cloutier c237e09d2d Small text updates 2023-08-01 23:17:03 +02:00
Phoebe Goldman b447457847 Update Rust client codegen to refer to renamed client sdk crate (#60) 2023-08-01 23:17:02 +02:00
Mario Montoya 88911e2c8e Upgrade ABI version (#56) 2023-08-01 23:17:02 +02:00
Piotr Sarnacki 720f51307d [TypeScript] Change serializing args for a reducer call (#53) 2023-08-01 23:17:02 +02:00
Mario Montoya 60bea782e2 Remove crash if fails to decode ModuleDef from bsatn (#55) 2023-08-01 23:17:02 +02:00
John Detter 8bc2391ddc Commit publish-crates script (#52)
* Script for publishing crates to crates.io

* Added sdk to the publish-crates script, renamed client-sdk to sdk

* Updated Cargo.lock and added 2 crates to the upgrade version script

* Small fix

* Actual fix

* Updated client API messages crate to be publishable

* Added LICENSE file to sdk

* Chose specific version for tokio-tungstenite

---------

Co-authored-by: Boppy <no-reply@boppygames.gg>
Co-authored-by: Tyler Cloutier <cloutiertyler@aol.com>
2023-08-01 23:17:02 +02:00
Piotr Sarnacki e35f5c4bda Allow to authenticate with a short lived token for websocket (#51)
* Allow to authenticate with a short lived token for websocket

* Add CORS

* Lints

* Name errors properly

* lint
2023-08-01 23:17:02 +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
Tyler Cloutier cb3d6862ca Merged in Piotr's changes from the Private repo 2023-08-01 23:17:02 +02:00
John Detter 0e04ebab6c Cargo profile for building CLI more quickly (#50)
* Cargo profile for building more quickly

* opt level is redundant

---------

Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-08-01 23:17:02 +02:00
John Detter 0cc72cbb5f Nits: More specific error responses when authorization fails (#48)
* Restoring Mazdak's nits

* Update auth.rs

Small issue

Signed-off-by: John Detter <4099508+jdetter@users.noreply.github.com>

---------

Signed-off-by: John Detter <4099508+jdetter@users.noreply.github.com>
Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-08-01 23:17:02 +02:00
Piotr Sarnacki 02b67e98db [TypeScript] Remove entries from filtering (#31)
* [TypeScript] Remove entries from filtering

In the TypeScript SDK we keep "entries" - an algebraic value of records.
I added them because they were also used in the C# SDK, but we don't
really need them. This commit changes generated filtering functions so
that they compare actual instances instead of product values.
2023-08-01 23:17:02 +02:00
John Detter 757719e7b4 Enable restart tests (#35)
* Fixes the restart problem (i.e. rebuilding the datastore from the message log)

* Remove logging

* Enable restart tests

* Fixed small issues with tests

* Fixed restart-repeating-reducer test probably

---------

Co-authored-by: Tyler Cloutier <cloutiertyler@aol.com>
Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-08-01 23:17:02 +02:00
George Kulakowski 230da8c4ea Remove the ever growing pile of memory in locking_tx_datastore (#38)
* Remove the ever growing pile of memory in locking_tx_datastore

* Clippy lint

* cargo fmt

* Cleanups

* Fix lint

* Rename TxRecord::pv to product_value

---------

Co-authored-by: Boppy <no-reply@boppygames.gg>
Co-authored-by: Tyler Cloutier <cloutiertyler@aol.com>
2023-08-01 23:17:02 +02:00
John Detter 41dc128533 Upgrade Version to 0.5.0 (#47)
* Committing version upgrade script

* Fixes to the upgrade script

* Upgrade version to 0.5.0

* Update Cargo.toml

No longer optional

Signed-off-by: John Detter <4099508+jdetter@users.noreply.github.com>

* Fixed small issue in the version upgrade script

---------

Signed-off-by: John Detter <4099508+jdetter@users.noreply.github.com>
Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-08-01 23:17:02 +02:00
John Detter e4a741af50 Pretty CLI Banner (#43)
* Pretty banner

* Updated the CLI ascii art

---------

Co-authored-by: Boppy <no-reply@boppygames.gg>
Co-authored-by: Tyler Cloutier <cloutiertyler@aol.com>
2023-08-01 23:17:02 +02:00
Piotr Sarnacki 9b93100e3f [Typescript] Change in reducer args (#36) 2023-08-01 23:17:02 +02:00
Phoebe Goldman 29b1db663b Filtering on non-unique fields uses indexes when available (#40)
With this commit, module-side `filter_by_{non-unique-field}` methods will use an index on the non-unique-field, if one exists.

This is accomplished by altering `query::filter_by_field` to call `iter_by_col_eq` (formerly `seek_eq`), and having the returned `FilterByIter` gradually deserialize the returned buffer in a `Cursor`.
2023-08-01 23:17:02 +02:00
Kim Altintop aa122fa753 More specific error responses when authorization fails (#46) 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
dbrinkmanncw 98e112a2de Derek/csharp sdk (#37)
* Change NetworkManager to SpacetimeDBClient

* Update csharp gen for ReducerEventBase

* More fixes for ReducerEventBase

* Remove commented out code

---------

Co-authored-by: Derek Brinkmann <dbrinkmann@citadelstudios.net>
2023-08-01 23:17:02 +02:00
Phoebe Goldman 51a0bcf791 Rust client SDK ReducerInfo enum (#25)
* `ReducerEvent` enum in Rust client SDK

With this commit, row callbacks (`on_insert`, `on_delete`, `on_update`)
in the Rust client SDK take an additional argument,
`Option<&ReducerEvent>`, where `ReducerEvent` is an enum
generated by the CLI's codegen
with a variant for each reducer defined in the module.

Having the SDK pass around an autogenerated type in this way
(without adding a bunch of `<ReducerEvent>` generic parameters everywhere)
requires storing the `ReducerEvent` in an `Arc<dyn Any>`.
This has the added tangential benefit of avoiding cloning the `ReducerEvent`
for each row callback.
2023-08-01 23:17:02 +02:00
dbrinkmanncw 1571ccecb1 Add primary key class variable to table autogen in python (#19)
* Add primary key class variable to table autogen in python

* Fix lint error

---------

Co-authored-by: Derek Brinkmann <dbrinkmann@citadelstudios.net>
2023-08-01 23:17:02 +02:00
Phoebe Goldman e06af992df CLI generate: friendlier error message when module compilation fails (#44)
When running `spacetime generate` on a module which fails to compile,
the last line of the output is now a human-readable error message
which includes the module path and instructions to review the build errors.
2023-08-01 23:17:02 +02:00
Kim Altintop a20b75b82c Fix schema equivalence check when updating a module (#39)
`IndexDef` contains a table id, which is not yet known (i.e. zero) when
constructing `TableDef` from the module describers. But it /is/ known
for the schema obtained from the database catalog, so schemas compare
inequal even if they're structurally equivalent.

Fixed by just updating the proposed schema for known tables before
comparing. Also update the smoke test to contain an indexed column.
2023-08-01 23:17:02 +02:00
John Detter 9c3b4d6e3f Keys are now stored in docker named volume so they survive down/up (#42)
Co-authored-by: Boppy <no-reply@boppygames.gg>
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 756e891688 CLI: dedup some code (#29)
* simplify is_address

* cli: dedup some code
2023-08-01 23:17:02 +02:00
Tyler Cloutier d8576bfcc9 Fixes the restart problem (i.e. rebuilding the datastore from the message log) (#34)
* Fixes the restart problem (i.e. rebuilding the datastore from the message log)

* Remove logging
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
John Detter 7510b83c1a Fix Spacetime Identity Remove (#33)
* Fix bug and added a test

* Test updates

* Fix tests

---------

Co-authored-by: Boppy <no-reply@boppygames.gg>
2023-08-01 23:17:02 +02:00
Phoebe Goldman caf039ddd2 Rust client SDK consistent state views for callbacks (#16)
Prior to this commit, callbacks in the Rust client SDK shared access to the global
ClientCache while running asynchronously. This meant that a long-running or delayed
callback could observe the ClientCache in a state later than the one that caused the
callback's invocation, and had no way to access the specific state for which it was
invoked.

With this commit, each `Invoke` message to the callback worker includes an
`Arc<ClientCache>` snapshot of the DB state when that callback was invoked. The callback
worker stores that state in a `thread_local`, and methods that inspect
tables (e.g. `TableType::iter`) read the state out of the `thread_local` when it is
present. This allows callbacks to observe exactly the state which caused their invocation,
never a later state, while maintaining the C#-like API where `ClientCache` access is based
on free functions or static trait methods.

---------

Co-authored-by: John Detter <4099508+jdetter@users.noreply.github.com>
2023-08-01 23:17:02 +02:00
Piotr Sarnacki 5669f58730 Add reducerEvent in callbacks (#23) 2023-08-01 23:17:02 +02:00
Mazdak Farrokhzad 949f9f57f0 bindings: address review comments (#20)
* integrate jdetter's review

* address phoebe's comments

* improve errnos naming
2023-08-01 23:17:02 +02:00