Skip to content

v0.1.1

Compare
Choose a tag to compare
@oscartbeaumont oscartbeaumont released this 29 Sep 23:43
· 258 commits to main since this release

This release comes with a huge amount of breaking changes. These changes are going to allow for many benefits in the future such as a rich plugin ecosystem. If you're having trouble upgrading open a GitHub Issue or jump in the Discord server.

New vscode extension

If you use Visual Studio Code and rspc you should definitely check out the new vscode extension!

Httpz integration

This update moves from offering a direct Axum integration to using httpz. This change is going to allow rspc to support other HTTP servers and serverless environments in the near future.

Rust Changes:

let app = axum::Router::new()
    .route("/", get(|| async { "Hello 'rspc'!" }))
-   .route("/rspc/:id", router.clone().axum_handler(|| ()))
-   .route("/rspcws", router.axum_ws_handler(|| ()))
+   .route("/rspc/:id", router.endpoint(|req, cookies| ()).axum())

Typescript Changes:

const client = createClient<Operations>({
-   transport: new WebsocketTransport("ws://localhost:8080/rspcws"),
+   transport: new WebsocketTransport("ws://localhost:8080/rspc/ws"),
});

New Typescript bindings format

The internal format of the generated Typescript bindings has changed. The import has also changed so ensure you update your code as follows.

- import type { Operations } from "./my-bindings";
+ import type { Procedures } from "./my-bindings";

New middleware syntax

let router = Router::new()
- .middleware(|ctx| async move {
-     println!("MIDDLEWARE TWO");
-     ctx.next("hello").await
- })
+ .middleware(|mw| {
+    mw.middleware(|mw| async move {
+        let state = (mw.req.clone(), mw.ctx.clone(), mw.input.clone());
+        // state allows sharing data between the two closures and is optional.
+        Ok(mw.with_state(state).with_ctx("hello"))
+    })
+    // The .resp() part is optional and only required if you need to modify the return value.
+    // Be aware it will be called for every value in a subscription stream.
+    .resp(|state, result| async move {
+        println!(
+            "[LOG] req='{:?}' ctx='{:?}'  input='{:?}' result='{:?}'",
+            state.0, state.1, state.2, result
+        );
+        Ok(result)
+    })
+})

New procedure syntax

The new procedure syntax is one of the biggest changes with this release. It is reccomended you install the Visual Studio Code extension which will provide many snippets to make working with rspc as easy as possible.

Query

let router = Router::new()
- .query("version", |ctx, input: ()| "1.0.0")
+ .query("version", |t| t(|ctx, input: ()| "1.0.0"))

Mutation

let router = Router::new()
- .mutation("demo", |ctx, input: ()| async move { todo!() })
+ .mutation("demo", |t| t(|ctx, input: ()| async move { todo!() })

Subscription

Rust:

let router = Router::new()
- .subscription("version", |ctx, input: ()| stream! { yield 42; })
+ .subscription("version", |t| t(|ctx, input: ()| stream! { yield 42; }))

Typescript:

rspc.useSubscription(['my.subscription'], {
-    onNext: (data) => {
+    onData: (data) => {
        console.log(data)
    }
});

Minor changes/new features

  • ws, rpc.* and rspc.* are now reserved names for procedures
  • @rspc/solid has been upgraded to the new @tanstack/solid-query.
  • router.execute now returns a serde_json::Value and does not support subscriptions. Use router.execute_subscription to execute a subscription.
  • The Axum body type is now Vec<u8> not hyper::Body. This may cause issues if your extractors aren't generic enough.
  • Support for up to 5 Axum extractors. This limit will increase to 16 in a future release.

Warning on unstable APIs

  • Support for Axum extractors will likely change or be removed in the future when support for other HTTP servers is added. It exists in this release for backward compatibility.