43 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
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 cb42225d0a connect/disconnect reducers called when executing reducer from from CLI (#334)
* SpacetimeDB is hanging, might be because of my changes

* Fixed issue - put connect/disconnect in right spot

* Tested, working

* Reverted changes that are irrelevant

* Added test for detecting connect/disconnect when calling from the CLI

* Smoketest fix

* Fix compilation issue with test

* Addressing some feedback

* Updated test for a better test case

* Addressing review

* connect is a substring of disconnect which was causing a failure

* Fixing another test bug, should be correct now 👍

---------

Co-authored-by: John Detter <no-reply@boppygames.gg>
2023-09-29 12:55:30 -05:00
Phoebe Goldman 0a3a9d63b5 Return the formatted error from log_and_500, so the CLI can report it (#338)
In the client API's log_and_500,
return an ErrorResponse with a body derived from the error,
rather than a bare 500 code.

Note that this exposes previously-internal error messages to users.
2023-09-28 21:06:13 +00: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
Mazdak Farrokhzad 12a7e7f572 use derive_more::From (#281) 2023-09-13 11:40:23 +00:00
joshua-spacetime cc36a2e87c perf: read DataKey instead of recomputing it in subscriptions (#276)
Fixes #259 

(1) Updates MemTable to use RelValue instead of ProductValue
(2) Adds a DataKey member to DataRef and RelValue
(3) Subscriptions compute DataKey only when not present on row
2023-09-12 15:16:09 -07:00
joshua-spacetime 987b0091f8 Revert "perf: subscriptions compute DataKey only when not present with row (#268)" (#274)
This reverts commit a328108a5e.
2023-09-11 19:08:27 +00:00
joshua-spacetime a328108a5e perf: subscriptions compute DataKey only when not present with row (#268)
Fixes #259 

(1) Updates MemTable to use RelValue instead of ProductValue
(2) Adds a DataKey member to DataRef and RelValue
(3) Subscriptions compute DataKey only when not present on row
2023-09-08 15:39:24 -07:00
Phoebe Goldman 5dcf616b69 Add /identity/public-key route to get ECDSA public key (#165)
This commit adds a new endpoint to the `/identity` block,
which returns the public key STDB uses to decode JWTs.
This will allow clients, incl. the CLI and SDKs,
to verify multiple identity/token pairs without spamming STDB with requests.

The public key can also be used as a "fingerprint", to identify the server.
This will allow clients to determine:
- When multiple URIs or addresses refer to the same STDB instance.
- When a STDB instance has rotated its keys, so past identities become invalid.
2023-09-01 10:40:03 -04:00
Noa d52d0dc7e1 Fix logspam (#229) 2023-08-28 12:21:53 -05:00
Piotr Sarnacki f1406e42b0 Cloud related fixes (#218)
* Remove unused datastore traits

We previously anticipated factoring the database in such a way that
the typed vs untyped distinctions, and the transactional vs not,
semantics would be more visible. We have not used these distinctions
and no longer need to expose these traits.

* Fix recovery of sequences after restart

* Debug

* More debug logs

* Export more tyeps

* More debug info and small changes

* More logs

* Change waiting on messages from client to be async

* Remove some trace lines

* Revert "Fix recovery of sequences after restart"

This reverts commit eef0089b78.

* Remove more trace lines

* cargo fmt

* clippy

---------

Signed-off-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
Co-authored-by: George Kulakowski <george@clockworklabs.io>
Co-authored-by: Mario Alejandro Montoya Cortés <mamcx@elmalabarista.com>
Co-authored-by: Tyler Cloutier <cloutiertyler@aol.com>
Co-authored-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
2023-08-24 10:40:03 -07: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
Phoebe Goldman 0badd5dd1e Add identity/:id/verify route to verify identity/token pairs (#155)
This commit adds a new route to the `/identity` HTTP block,
`/identity/:identity/verify`,
which requires a SpacetimeDB auth header.

If the token in the authorization header is valid
and corresponds to the identity in the path,
it returns `NO_CONTENT`.

If the token in the authorization header is valid
but does not correspond to the identity in the path,
it returns `BAD_REQUEST`.

If the token in the authorization header is invalid or unsupplied,
it returns `UNAUTHORIZED`.
2023-08-22 10:39:30 -04: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
Kim Altintop d011c6815c More compact representation of DomainName (#163)
* More compact representation of `DomainName`

* Apply suggestions from code review

---------

Signed-off-by: Kim Altintop <kim@eagain.io>
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2023-08-10 12:20:13 +02:00
Kim Altintop 99f876ba6c Return parsed DomainName alongside Address when resolving NameOrAddress (#161)
* Return parsed `DomainName` alongside `Address` when resolving `NameOrAddress`

Helps to avoid repeatedly parsing `DomainName`, and to simplify the
`/database/publish` handler (not included in this patch).
2023-08-10 11:31:07 +02:00
Kim Altintop 537b3c7e33 Implement Display for NameOrAddress (#160)
Mainly for debugging, but hesitant to override the `Debug` impl for
`Address` with the hex representation.
2023-08-09 11:55:32 +02: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
Phoebe Goldman 64fd268f3d In identity recovery routes, use IdentityForUrl (#139) 2023-08-03 17:16:09 +02:00
Tyler Cloutier 81525ba7ee Fixed license file thing 2023-08-03 02:28:16 +02:00
Tyler Cloutier 55cc919bf5 Add client api to publishable crates 2023-08-03 02:07:38 +02:00
Tyler Cloutier 3e0caff415 Updated version to 0.6.0 2023-08-03 01:39: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
Tyler Cloutier 3e9a555278 cargo fmt 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
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
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
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
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
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 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
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
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
Tyler Cloutier b186a21fb4 Added an info API route 2023-08-01 23:17:02 +02:00
John Detter 8cf9ed49ef Identity command improvements (#11)
* 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

* Fix output so testsuite passes

---------

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:02 +02:00
Tyler Cloutier 44df6c6e7d Initial commit 2023-08-01 23:16:37 +02:00