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.
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
camelCaseon thectx, so if your table name isfoo_bar, the accessor changes fromctx.db.foo_bartoctx.db.fooBar. This allows you to use whatever table name you want for your tables without running afoul of TypeScript linters. Infer<>now also doesInferTypeOfRow<>if applicable which means you can forget aboutInferTypeOfRowand just useInferin 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 doconst x: Infer<typeof MyType>instead ofconst 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
MyTypeVariantsfor sum types (these are now accessed byInfer<typeof MyType.variants.myVariant>) - Your
module_bindingsnow export atablesobject with references to all theTableDefs - Your
module_bindingsnow export areducersobject with references to all theReducerDefs - On the client
my_table.iter()now returnsIterableIteratorinstead of anArray MyType.getTypeScriptAlgebraicType()has been replaced withMyType.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 abigintinstead 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>)andMyType.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 privateMyType.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 parametersuseSpacetimeDB()now returns aConnectionState. All fields on theConnectionStateare not React state and will cause a rerender any time they changeuseTable()now takes aTableDefparameter and type params are inferreduseTable()now just returns a tuple with the first element being anArrayinstead 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
- [teams 4/5] SQL authorization by @kim in #3525
- CI - TypeScript quickstart works properly in the face of version bumps by @bfops in #3634
- [TS] Specify the name of a view in an options object by @coolreader18 in #3642
- Reference docs for views by @joshua-spacetime in #3641
- Update views on auto-migrate by @Shubham8287 in #3631
- Upgrade to version 1.8.0 by @jdetter in #3633
- [teams 5/5] Identity routes by @kim in #3526
- PR merge discord post includes all non-successful checks by @bfops in #3594
- Switch Internal Tests to reuse CI job by @bfops in #3625
- Tweak DNS resolution error message by @bfops in #3647
- Fix noisy Discord notifications on PR merge by @bfops in #3650
- CI - Fix "Check that packages are publishable" check by @bfops in #3660
- Scheduled reducer: use timestamp from reducer params for next run by @Shubham8287 in #3657
- client-api: Make
ControlStateReadAccessan async trait by @kim in #3357 - Remove the middle man thread the JS worker thread by @Centril in #3577
- Use new runner for testsuite by @jdetter in #3656
- CI - Cancel internal tests if cancelled by @bfops in #3674
- CI - Ping PR author directly if checks fail by @bfops in #3671
- Fix the basic-rust client template for CLI's init command by @drogus in #3646
- C#: Add confirmed reads configuration by @kim in #3282
- Fix test with change on defaults by @mamcx in #3683
- commitlog: Change default max-records-in-commit to 1 by @kim in #3681
- Fix
spacetime generaterunningdotnet formatin the wrong directory by @bfops in #3687 - CI - Fix empty lookup by @bfops in #3693
- fix plan caching for client-specific views by @joshua-spacetime in #3672
- Unifies server module library and client SDK for TypeScript (and fixes several bugs) by @cloutiertyler in #3559
- Fix #3687 by @bfops in #3692
- Adds flag to publish to allow clearing on migration conflict. by @cloutiertyler in #3601
- Client codegen fixes for views by @joshua-spacetime in #3690
- CI - Cache more of our build outputs by @bfops in #3521
- Add
ProcedureContext::with_txby @Centril in #3638 anyonymousView->anonymousViewby @bfops in #3697- Add check for .env.local and module bindings generations to only write on changes by @aceysmith in #3604
- Move typescript tests to new runner by @jdetter in #3696
- Add
smoketests/requirements.txtby @bfops in #3701 - Fix C# module bindings codegen for namespaces with view dispatcher by @JasonAtClockwork in #3668
- Fix running
smoketests --listby @bfops in #3700 - Views: ephemeral tables by @Shubham8287 in #3670
- Change
spacetime_worker_wasm_instance_errors_totalmetric's labels by @drogus in #3614 - Views: cleanup unsubscribed views by @Shubham8287 in #3651
- Export call_view in C# by @rekhoff in #3691
- Views: blocking thread for views cleanup by @Shubham8287 in #3707
- Add extra claims to v1/identity/websocket-token by @JulienLavocat in #3705
New Contributors
- @aceysmith made their first contribution in #3604
Full Changelog: v1.8.0...v1.9.0