mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-05-11 10:29:21 -04:00
59159dbb3d
* 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>