Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ First, add the following crates to your `Cargo.toml`:
# src-tauri/Cargo.toml

[dependencies]
taurpc = "0.5.2"
taurpc = "0.6.0"

specta = { version = "=2.0.0-rc.22", features = ["derive"] }
# specta-typescript = "0.0.9"
Expand Down
6 changes: 3 additions & 3 deletions example/src-tauri/Cargo.lock

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

6 changes: 3 additions & 3 deletions taurpc/Cargo.lock

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

34 changes: 16 additions & 18 deletions taurpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "taurpc"
authors = ["MatsDK"]
version = "0.5.2"
version = "0.6.0"
edition = "2021"
description = "A type-safe IPC layer for tauri commands"
documentation = "https://docs.rs/taurpc"
Expand All @@ -10,30 +10,28 @@ repository = "https://github.com/MatsDK/TauRPC"
license = "MIT OR Apache-2.0"
readme = "../README.md"
categories = []
rust = "1.71"
rust-version = "1.77.2"

[package.metadata."docs.rs"]
all-features = true
rustc-args = ["--cfg", "docsrs"]
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
taurpc-macros = { path = "./taurpc-macros", version = "=0.5.2" }

itertools = "0.13.0"
tauri = { version = "2.2.5", features = ["specta"] }
serde = { version = "1.0.215", features = ["derive"] }
serde_json = "1.0.133"
tokio = { version = "1", features = ["full"] }

specta = { version = "=2.0.0-rc.22", features=["export", "function"] }
specta-serde = { version = "0.0.9", features = [] }
specta-typescript = { version = "0.0.9", features = ["function"] }
specta-macros = { version = "2.0.0-rc.17" }
heck = "0.5.0"
anyhow = "1.0.95"

[workspace]
members = [
"taurpc-macros",
]

[dependencies]
anyhow = "1"
heck = "0"
itertools = "0"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
specta = { version = "2.0.0-rc.22", features = ["export", "function"] }
specta-macros = { version = "2.0.0-rc.18" }
specta-serde = { version = "0", features = [] }
specta-typescript = { version = "0", features = ["function"] }
tauri = { version = "2", features = ["specta"] }
taurpc-macros = { path = "./taurpc-macros", version = "=0.6.0" }
tokio = { version = "1", features = ["full"] }
12 changes: 6 additions & 6 deletions taurpc/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ pub(super) fn export_types(
.context("Cannot open bindings file")?;

try_write(&mut file, &export_config.header);
try_write(&mut file, &framework_header);
try_write(&mut file, &BOILERPLATE_TS_IMPORT);
try_write(&mut file, &body);
try_write(&mut file, framework_header);
try_write(&mut file, BOILERPLATE_TS_IMPORT);
try_write(&mut file, body);

let args_entries: String = args_map
.iter()
Expand All @@ -90,7 +90,7 @@ pub(super) fn export_types(
try_write(&mut file, &format!("const ARGS_MAP = {router_args}\n"));
let functions_router = generate_functions_router(functions, type_map, &export_config);
try_write(&mut file, &functions_router);
try_write(&mut file, &BOILERPLATE_TS_EXPORT);
try_write(&mut file, BOILERPLATE_TS_EXPORT);

if export_path.ends_with("node_modules\\.taurpc\\index.ts") {
let package_json_path = Path::new(&export_path)
Expand All @@ -116,7 +116,7 @@ fn generate_functions_router(
) -> String {
let functions = functions
.iter()
.filter_map(|(path, path_functions)| {
.map(|(path, path_functions)| {
let mut function_names_and_funcs: Vec<_> =
path_functions.iter().map(|f| (f.name(), f)).collect();
function_names_and_funcs.sort_by(|a, b| a.0.cmp(b.0));
Expand All @@ -129,7 +129,7 @@ fn generate_functions_router(
.unwrap_or_default()
.join(", \n");

Some(format!(r#""{path}": {{{functions}}}"#))
format!(r#""{path}": {{{functions}}}"#)
})
.collect::<Vec<String>>()
.join(",\n");
Expand Down
46 changes: 23 additions & 23 deletions taurpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub trait TauRpcHandler<R: Runtime>: Sized {
///
///
/// # Examples
/// ```rust
/// ```rust,ignore
/// #[taurpc::procedures]
/// trait Api {
/// async fn hello_world();
Expand All @@ -75,7 +75,7 @@ pub trait TauRpcHandler<R: Runtime>: Sized {
/// async fn main() {
/// tauri::Builder::default()
/// .invoke_handler(
/// taurpc::create_ipc_handler(ApiImpl.into_handler());
/// taurpc::create_ipc_handler(ApiImpl.into_handler())
/// )
/// .run(tauri::generate_context!())
/// .expect("error while running tauri application");
Expand Down Expand Up @@ -185,14 +185,14 @@ impl<RT: Runtime> EventTrigger<RT> {
/// The trait must have the `#[taurpc::procedures]` macro and the nested routes should have `#[taurpc::procedures(path = "path")]`.
///
/// # Examples
/// ```rust
/// ```rust,ignore
/// #[taurpc::procedures]
/// trait Api { }
///
/// #[derive(Clone)]
/// struct ApiImpl;
///
/// #[taurpc::resolveres]
/// #[taurpc::resolvers]
/// impl Api for ApiImpl { }
///
/// #[taurpc::procedures(path = "events")]
Expand All @@ -201,12 +201,12 @@ impl<RT: Runtime> EventTrigger<RT> {
/// #[derive(Clone)]
/// struct EventsImpl;
///
/// #[taurpc::resolveres]
/// #[taurpc::resolvers]
/// impl Events for EventsImpl { }
///
/// #[tokio::main]
/// async fn main() {
/// let router = Router::new()
/// let router = taurpc::Router::new()
/// .merge(ApiImpl.into_handler())
/// .merge(EventsImpl.into_handler());
///
Expand Down Expand Up @@ -242,14 +242,14 @@ impl<R: Runtime> Router<R> {
/// `specta_typescript::Typescript` for all the configuration options.
///
/// Example:
/// ```rust
/// let router = Router::new()
/// .export_config(
/// specta_typescript::Typescript::default()
/// .header("// My header\n")
/// .bigint(specta_typescript::BigIntExportBehavior::String),
/// )
/// .merge(...);
/// ```rust,ignore
/// let router = taurpc::Router::new()
/// .export_config(
/// specta_typescript::Typescript::default()
/// .header("// My header\n")
/// .bigint(specta_typescript::BigIntExportBehavior::String),
/// )
/// .merge(ApiImpl.into_handler());
/// ```
pub fn export_config(mut self, config: specta_typescript::Typescript) -> Self {
self.export_config = config;
Expand All @@ -258,10 +258,10 @@ impl<R: Runtime> Router<R> {

/// Add routes to the router, accepts a struct for which a `#[taurpc::procedures]` trait is implemented
///
/// ```rust
/// let router = Router::new()
/// .merge(ApiImpl.into_handler())
/// .merge(EventsImpl.into_handler());
/// ```rust,ignore
/// let router = taurpc::Router::new()
/// .merge(ApiImpl.into_handler())
/// .merge(EventsImpl.into_handler());
/// ```
pub fn merge<H: TauRpcHandler<R>>(mut self, handler: H) -> Self {
if let Some(path) = H::EXPORT_PATH {
Expand All @@ -282,11 +282,11 @@ impl<R: Runtime> Router<R> {
/// Create a handler out of the router that allows your IPCs to be called from the frontend,
/// and generate the corresponding types. Use this inside `.invoke_handler()` on the tauri::Builder.
///
/// ```rust
/// tauri::Builder::default()
/// .invoke_handler(router.into_handler())
/// .run(tauri::generate_context!())
/// .expect("error while running tauri application");
/// ```rust,ignore
/// tauri::Builder::default()
/// .invoke_handler(router.into_handler())
/// .run(tauri::generate_context!())
/// .expect("error while running tauri application");
/// ```
pub fn into_handler(self) -> impl Fn(Invoke<R>) -> bool {
// Only export in development mode
Expand Down
13 changes: 6 additions & 7 deletions taurpc/taurpc-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
[package]
name = "taurpc-macros"
version = "0.5.2"
version = "0.6.0"
edition = "2021"
description = "Macros for the taurpc crate"
documentation = "https://docs.rs/taurpc"
readme = "README.md"
homepage = "https://github.com/MatsDK/TauRPC"
repository = "https://github.com/MatsDK/TauRPC"
license = "MIT OR Apache-2.0"
readme = "README.md"

[lib]
proc-macro = true

[dependencies]
syn = { version = "2.0.15", features = ["full"] }
quote = "1.0.26"
proc-macro2 = "1.0.56"
proc-macro2 = "1"
quote = "1"
serde = { version = "1", features = ["derive"] }

serde_json = "1.0.96"
serde_json = "1"
syn = { version = "2", features = ["full"] }
# convert_case = "0.6"