Skip to content

Releases: oscartbeaumont/rspc

v0.2.0

17 Mar 17:06
Compare
Choose a tag to compare

This release comes with a bunch of breaking changes to prepare existing rspc projects for the upcoming 0.3.0 release.

This release is only possible due to the support of my sponsors!

A huge thanks to @scottwey, @michael-dm and @TmLev for supporting me. If you are using rspc and you or your company is able to support the project it would be greatly appreciated as it ensures the product is sustainable long-term!

tldr of changes

  • Fix websocket when using the Axum integration which I broke in the 0.1.4 release earlier today
  • Drop httpz from rspc core. I have deprecated this crate as I don't think it's serving it's purpose very well. All integrations are moving into rspc_* crates.
  • Remove Specta reexports and Specta features from the rspc crate
  • Restart subscriptions and in-progress requests when the websocket connection reconnects.
  • Websocket support is now optional and requires the ws feature to be enabled on the rspc_axum crate.
  • Expose AppHandle to Tauri context function as the first argument - fixes #244

These changes should hopefully fix the most comments issues I hear when talking with people about rspc.

Upgrade Guide:

Bump dependency versions

# Backend
cargo add [email protected]

# Frontend
pnpm install @rspc/[email protected]
pnpm install @rspc/[email protected]
pnpm install @rspc/[email protected]
pnpm install @rspc/[email protected]

Removal of rspc::Type

rspc::Type is currently a reexport of specta::Type and to make versioning easier we have removed it in this rspc release. To upgrade:

Make sure you have Specta installed in your project.

cargo add specta

Then replace all rspc::Type imports with specta::Type.

Removal of many features from rspc crate

This release drops a lot of features from the rspc crate. I have documented them by category below:

Specta-related flags

This includes uuid, chrono, time, bigdecimal, rust_decimal, indexmap, ipnetwork, mac_address, bit-vec and bson.

You should instead move the feature onto the specta crate.

Eg.

- rspc = { version = "0.1.4", features = ["chrono"] }
+ rspc = "0.2.0"
+ specta = { version = "1", features = ["chrono"] }

Webservers

This includes httpz, tauri, axum, lambda, workers. You should follow the guide for your integration under the next heading.

Break out integrations into dedicated crates

This is going to make versioning significantly easier which would mean more frequent bug fixes and depedency upgrades.

This included removing .endpoint and the rspc::integrations module in favor of splitting the logic over multiple crates.

Follow the guide below based on your chosen integration:

Axum

First, remove the old feature flag and add the new rspc_axum crate.

- rspc = { version = "0.1.4", features = ["axum"] }
+ rspc = "0.2.0"
+ rspc_axum = { version = "0.1.1", features = ["ws"] } # Websocket support is now optional

Next, upgrade the code in your project:

let app = axum::Router::new()
        .route("/", get(|| async { "Hello 'rspc'!" }))
        .nest(
            "/rspc",
-           router
-                .clone()
-                .endpoint(|| { ... })
-                .axum(),
+            rspc_axum::endpoint(router.clone(), | | { ... }),
        )
        .layer(cors);

Tauri

First, remove the old feature flag and add the new rspc_tauri crate.

- rspc = { version = "0.1.4", features = ["tauri"] }
+ rspc = "0.2.0"
+ rspc_tauri = { version = "0.0.1" }

Next, upgrade the code in your project:

tauri::Builder::default()
-    .plugin(rspc::integrations::tauri::plugin(router.arced(), || { ... }))
+    .plugin(rspc_tauri:plugin(router.arced(), |_| { ... }))

Lambda

This feature has been removed. It's recommend you use the Axum integration with cargo-lambda like this example.

Workers

This feature has been removed. It currently has no direct replacement but will be brought back in the near future.

If you are actively using it, please contact me on the rspc/PCR Discord and we can get something sorted.

Tanstack Query v5

This release requires you upgrade to Tanstack Query v5. You can follow their upgrade guide here.

Solid Query

Solid Query has changed the way its arguments are parsed upstream so we decided to copy this. You will need to update all of your createQuery, createMutation, etc hooks to the new syntax.

For queries you will need to make the following changes:

rspc.createQuery(
-  () => ["echo", "somevalue"],
-  () => ({
-    enabled: true,
-  })
+ () => ({
+  queryKey: ["echo", "somevalue"],
+  enabled: true
+ })
);

For mutations, you will need to use the mutationKey property to choice the mutation is the same style.

Usage with Prisma Client Rust

If your using Prisma Client Rust 0.6.x you can use the rspc-0.2.0 branch:

prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust", rev = "8faf98013d0d2c7fab68fad387305a55979e777d" }
prisma-client-rust-cli = { git = "https://github.com/Brendonovich/prisma-client-rust", rev = "8faf98013d0d2c7fab68fad387305a55979e777d" }

v0.1.4

17 Mar 05:36
Compare
Choose a tag to compare

Changes:

  • Support Axum 0.7
  • Fix rspc Tauri can only handle one request at a time - #260 - Thanks @campbellcole

Using Axum 0.7

To use Axum 0.7 you must use the rspc_axum crate. You will need to install it by running:

and then make the following changes:

let app = axum::Router::new()
        .route("/", get(|| async { "Hello 'rspc'!" }))
        .nest(
            "/rspc",
-           router
-                .clone()
-                .endpoint(|| { ... })
-                .axum(),
+            rspc_axum::endpoint(router.clone().endpoint(|| { ... })),
        )
        .layer(cors);

Warning

I noticed after publishing this release, it's got a major bug with Websockets due to mistake on my end. If you are using websockets please jump straight to 0.2.0 instead, sorry for the inconvenience!

I also forgot to publish to npm for this release.

😊

v1.0.0-rc.4

19 Jul 17:27
Compare
Choose a tag to compare

Foreshadowing: I really hope no more bugs exist.

v1.0.0-rc.3

19 Jul 15:15
Compare
Choose a tag to compare

The bugs just don't stop coming.

v1.0.0-rc.2

19 Jul 09:43
Compare
Choose a tag to compare

Bug fixes

v1.0.0-rc.1

19 Jul 05:43
Compare
Choose a tag to compare

Right now this release is undocumented and comes with many breaking changes.

If your feeling brave referring to Spacedrive upgrade 1 & 2 will give you an idea of changes required.

Docs are coming soon! Join the Discord for updates!

v0.1.3

05 Mar 14:48
Compare
Choose a tag to compare

Fixes:

Changes

  • Specta has been relocated from the specta subdirectory to oscartbeaumont/specta
  • Specta has been upgraded to v1.0.0
  • Support for Axum v0.6
  • Multithreaded Tauri executor
  • Upgraded all Rust and backend deps
  • Remove async-stream dependency

Breaking changes

Axum integration

When upgrading you will get the error expected struct "MethodRouter", found struct "axum::Router". To fix this you need to update your code as follows:

+ use rspc::integrations::httpz::Request;

-  .route(
    "/rspc/:id",
+  .nest(
    "/rspc",
    router
-        .endpoint(|path: Path<String>| {
-            println!("Client requested operation '{}'", *path);
+        .endpoint(|req: Request| {
+            println!("Client requested operation '{}'", req.uri().path());
            ()
        })
        .axum(),
)

If you were using a full Axum extractor, support for them has been deprecated as Axum 0.6 has broken the way it works. Please refer to this example for the workaround to use an Axum extractor. This workaround will be removed in the future so please open a GitHub issue to let me know your usecases for it!

Merge behavior

The behavior .merge has changed. If you want to restore the old behavior rename .merge to .legacy_merge. I am going to drop .legacy_merge in a future update so please open a GitHub Issue if you have a use case that doesn't work with .merge.

Other Dependencies

You may be required to upgrade over dependencies such as:

  • Tokio
  • Axum

I would highly recommend installing cargo-edit and running cargo upgrade --compatible --recursive to upgrade everything.

v0.1.2

01 Oct 16:41
Compare
Choose a tag to compare

Fixes:

  • Fix Typescript types for client.subscription function.

Features:

  • Undocumented helpers for building custom hooks on top of rspc

v0.1.1

29 Sep 23:43
Compare
Choose a tag to compare

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.