github clockworklabs/SpacetimeDB v1.9.0
Release v1.9.0 - Project Collaborators

7 hours ago

Today we have a long overdue feature we're releasing, project collaborators! 👯

Project Collaborators

Now you can invite other members of your team to join your projects that you deploy to Maincloud.

image

In order to add collaborators, navigate to your project on the website and go to Settings > Collaborators, and then press Add People to add a new collaborator to your project.

Depending on the role you assign the user, they will be able to perform actions that were previously only possible for the database owner to run, including updating the module, viewing logs, and editing tables.

TypeScript (Beta) - API Update

We also have the first major update to our TypeScript API. This change dramatically improves usability in a few key areas and fixes some critical bugs in the TypeScript and React SDKs.

Important

This update also comes with a few breaking changes to the TypeScript API, which are detailed below. In general, we will try to minimize the number of changes to the existing API, but while TypeScript is in Beta we will be making a few important changes until we stabilize the API completely.

TypeScript Modules

TypeScript modules only get a modest change from the previous API:

  • Table accessor names and index accessor names are converted to camelCase on the ctx, so if your table name is foo_bar, the accessor changes from ctx.db.foo_bar to ctx.db.fooBar. This allows you to use whatever table name you want for your tables without running afoul of TypeScript linters.
  • Infer<> now also does InferTypeOfRow<> if applicable which means you can forget about InferTypeOfRow and just use Infer in all cases to get the type of a type builder.

TypeScript SDK

The TypeScript SDK has now been unified with the API of server modules. Code generation now uses the same types and functions that you use on the server. The eventual goals is to allow you to use your actual server types in your TypeScript client without needing to do any code generation. This leads to the following changes:

  • All types exported by generated files are now TypeBuilders, meaning that if you were previously using a type from a generated file, you will now have to do const x: Infer<typeof MyType> instead of const x: MyType. This may seem like an inconvenience, but it vastly improves a lot of the other APIs and is very flexible to extend and is inspired by the very powerful Zod library.
  • We no longer generate and export MyTypeVariants for sum types (these are now accessed by Infer<typeof MyType.variants.myVariant>)
  • Your module_bindings now export a tables object with references to all the TableDefs
  • Your module_bindings now export a reducers object with references to all the ReducerDefs
  • On the client my_table.iter() now returns IterableIterator instead of an Array
  • MyType.getTypeScriptAlgebraicType() has been replaced with MyType.algebraicType
  • Reducers are now called with the same format on the server and clients. e.g. ctx.reducers.createPlayer(argA, argB) -> ctx.reducers.createPlayer({ argA, argB })
  • Reducer callbacks now also take arguments the same way: ctx.reducers.onCreatePlayer(ctx, argA, argB) -> ctx.reducers.onCreatePlayer(ctx, { argA, argB }) & ctx.reducers.removeOnCreatePlayer(ctx, argA, argB) -> ctx.reducers.removeOnCreatePlayer(ctx, { argA, argB })
  • count() now returns a bigint instead of a number to match the server API e.g. myTable.count(): number -> myTable.count(): bigint. This may be changed in the future as it is unlikely that you will have a table with more than 2^53 rows.

Notable things that did not change:

  • MyType.serialize(writer: BinaryWriter, value: Infer<typeof MyType>) and MyType.deserialize(reader: BinaryReader): Infer<typeof MyType> are still supported exactly as before.
  • The MyType.MyVariant(...) constructor function on sum types is still present, but implemented with the private MyType.create('MyVariant', ...). We could choose to move away from this API later if we didn't like the variants polluting the namespace

Warning

You will need to regenerate your module bindings for your TypeScript clients with the latest version of the spacetime CLI tool.

React SDK

The React SDK gets a major improvement in both usability and correctness.

  • useSpacetimeDB() no longer takes type parameters
  • useSpacetimeDB() now returns a ConnectionState. All fields on the ConnectionState are not React state and will cause a rerender any time they change
  • useTable() now takes a TableDef parameter and type params are inferred
  • useTable() now just returns a tuple with the first element being an Array instead of a object with { rows }
  • Added a useReducer() React hook

So now you can write this in your React client:

  import { reducers, tables } from "./module_bindings";

  const { identity, isActive: connected } = useSpacetimeDB();
  const setName = useReducer(reducers.setName);
  const sendMessage = useReducer(reducers.sendMessage);
  const [onlineUsers] = useTable(tables.user, where(eq('online', true)));

The API for using a view is the same as using a table:

  const [myViewRows] = useTable(tables.myView);

What's Changed

New Contributors

Full Changelog: v1.8.0...v1.9.0

Don't miss a new SpacetimeDB release

NewReleases is sending notifications on new releases.