Skip to content

Commit

Permalink
🎉 Release 2.0.0-rc.9 with Specta 2.0.0-rc.12
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed May 9, 2024
1 parent 772a43c commit 3c5d9e4
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tauri-specta"
description = "Completely typesafe Tauri commands"
version = "2.0.0-rc.8"
version = "2.0.0-rc.9"
authors = ["Oscar Beaumont <[email protected]>"]
edition = "2021"
license = "MIT"
Expand All @@ -23,7 +23,7 @@ typescript = ["specta/typescript", "specta/js_doc"]

[dependencies]
# Public
specta = { version = "=2.0.0-rc.11", features = ["function"] }
specta = { version = "=2.0.0-rc.12", features = ["function"] }
tauri-specta-macros = { version = "=2.0.0-rc.5", path = "./macros" }
serde = "1"
serde_json = "1"
Expand Down
4 changes: 2 additions & 2 deletions docs/v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
```bash
cargo add tauri@=2.0.0-beta.17
cargo add specta@=2.0.0-rc.11
cargo add specta@=2.0.0-rc.12
cargo add tauri-specta@=2.0.0-rc.5 --features javascript,typescript
```

Expand Down Expand Up @@ -186,7 +186,7 @@ let builder = ts::builder()
.types(TypeCollection::default().register::<Custom>()); // < call `register` as much as you want.
```

`register` only supports [named types](https://docs.rs/specta/2.0.0-rc.11/specta/type/trait.NamedType.html) as otherwise you would run into the following problem:
`register` only supports [named types](https://docs.rs/specta/2.0.0-rc.12/specta/type/trait.NamedType.html) as otherwise you would run into the following problem:
```rust
// vvv - What would this be without a name?
export ... = {};
Expand Down
2 changes: 1 addition & 1 deletion examples/app/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tauri-build = { version = "2.0.0-beta.13", features = [] }

[dependencies]
serde_json = "1.0"
specta = "=2.0.0-rc.11"
specta = "=2.0.0-rc.12"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "2.0.0-beta", features = [] }
tauri-specta = { path = "../../../", features = ["typescript", "javascript"] }
Expand Down
25 changes: 24 additions & 1 deletion examples/app/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ mod nested {
}

#[derive(Error, Debug, Serialize, Type)]
#[serde(tag = "type", content = "data")]
pub enum MyError {
// On the frontend this variant will be "IoError" with no data.
#[error("io error: {0}")]
Expand All @@ -78,6 +79,27 @@ fn typesafe_errors_using_thiserror() -> Result<(), MyError> {
)))
}

#[derive(Error, Debug, Serialize, Type)]
#[serde(tag = "type", content = "data")]
pub enum MyError2 {
#[error("io error: {0}")]
IoError(String),
}

impl From<std::io::Error> for MyError2 {
fn from(error: std::io::Error) -> Self {
Self::IoError(error.to_string())
}
}

#[tauri::command]
#[specta::specta]
fn typesafe_errors_using_thiserror_with_value() -> Result<(), MyError2> {
// some_method()?; // This will work because `?` does `From` conversion.

Err(std::io::Error::new(std::io::ErrorKind::Other, "oh no!").into()) // We use `into` here to do the `From` conversion.
}

#[derive(Serialize, Deserialize, Debug, Clone, specta::Type, tauri_specta::Event)]
pub struct DemoEvent(String);

Expand All @@ -97,7 +119,8 @@ fn main() {
nested::some_struct,
generic::<tauri::Wry>,
deprecated,
typesafe_errors_using_thiserror
typesafe_errors_using_thiserror,
typesafe_errors_using_thiserror_with_value
])
.events(tauri_specta::collect_events![DemoEvent, EmptyEvent])
.types(TypeCollection::default().register::<Custom>())
Expand Down
11 changes: 10 additions & 1 deletion examples/app/src/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ try {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async typesafeErrorsUsingThiserrorWithValue() : Promise<Result<null, MyError2>> {
try {
return { status: "ok", data: await TAURI_INVOKE("typesafe_errors_using_thiserror_with_value") };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
}
}

Expand All @@ -55,7 +63,8 @@ emptyEvent: "empty-event"
export type Custom = string
export type DemoEvent = string
export type EmptyEvent = null
export type MyError = "IoError" | { AnotherError: string }
export type MyError = { type: "IoError" } | { type: "AnotherError"; data: string }
export type MyError2 = { type: "IoError"; data: string }
export type MyStruct = { some_field: string }

/** tauri-specta globals **/
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-plugin/plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ tauri-plugin = { version = "=2.0.0-beta.13", features = ["build"] }
[dependencies]
rand = "0.8.5"
serde = "1"
specta = "=2.0.0-rc.11"
specta = "=2.0.0-rc.12"
tauri = "=2.0.0-beta.17"
tauri-specta = { path = "../../../", features = ["typescript"] }

0 comments on commit 3c5d9e4

Please sign in to comment.