Skip to content

Commit 4a4988f

Browse files
Merge pull request #206 from rofinn/rf/specta-updates
Specta updates
2 parents 16d1f51 + c082b7c commit 4a4988f

22 files changed

Lines changed: 1351 additions & 692 deletions

Cargo.lock

Lines changed: 449 additions & 255 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ rustdoc-args = ["--cfg", "docsrs"]
2020
[features]
2121
default = []
2222
derive = ["dep:tauri-specta-macros"]
23-
javascript = ["dep:specta-typescript"]
24-
typescript = ["dep:specta-typescript"]
23+
javascript = ["dep:specta-typescript", "dep:specta-tags"]
24+
typescript = ["dep:specta-typescript", "dep:specta-tags"]
2525

2626
[lints]
2727
workspace = true
@@ -38,6 +38,8 @@ tauri = { workspace = true, features = ["specta"] }
3838

3939
# Private
4040
heck = "0.5"
41+
specta-serde = { workspace = true }
42+
specta-tags = { workspace = true, optional = true }
4143

4244
[workspace]
4345
members = [
@@ -65,13 +67,13 @@ tauri-build = { version = "2" }
6567
tauri-plugin = { version = "2" }
6668
specta = { version = "=2.0.0-rc.23", features = ["derive"] }
6769
specta-typescript = { version = "0.0.10" }
70+
specta-serde = { version = "0.0.10" }
71+
specta-tags = { version = "0.0.0" }
6872

69-
# TODO: Drop patches
70-
[patch.crates-io]
71-
specta = { git = "https://github.com/oscartbeaumont/specta", rev = "09878718731efefd74329b593b29305800906e60" }
72-
specta-typescript = { git = "https://github.com/oscartbeaumont/specta", rev = "09878718731efefd74329b593b29305800906e60" }
73-
specta-serde = { git = "https://github.com/oscartbeaumont/specta", rev = "09878718731efefd74329b593b29305800906e60" }
7473

75-
# specta = { path = "/Users/oscar/Desktop/specta17/specta" }
76-
# specta-typescript = { path = "/Users/oscar/Desktop/specta17/specta-typescript" }
77-
# specta-serde = { path = "/Users/oscar/Desktop/specta17/specta-serde" }
74+
# TODO: remove these once released as `.rc-24`
75+
[patch.crates-io]
76+
specta = { git = "https://github.com/specta-rs/specta", rev = "2e769e745686e37b83f7240f2def4360e8113713" }
77+
specta-typescript = { git = "https://github.com/specta-rs/specta", rev = "2e769e745686e37b83f7240f2def4360e8113713" }
78+
specta-serde = { git = "https://github.com/specta-rs/specta", rev = "2e769e745686e37b83f7240f2def4360e8113713" }
79+
specta-tags = { git = "https://github.com/specta-rs/specta", rev = "2e769e745686e37b83f7240f2def4360e8113713" }

examples/app/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"@tauri-apps/api": "^2.10.1"
1414
},
1515
"devDependencies": {
16-
"@tauri-apps/cli": "^2.10.0",
17-
"typescript": "^5.9.3",
18-
"vite": "^7.3.1"
16+
"@tauri-apps/cli": "^2.10.1",
17+
"typescript": "^6.0.2",
18+
"vite": "^8.0.3"
1919
}
2020
}

examples/app/src-tauri/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ tauri-build = { workspace = true, features = [] }
1313

1414
[dependencies]
1515
serde_json = "1.0"
16-
specta = { workspace = true }
16+
specta = { workspace = true, features = ["bytes", "chrono"] }
1717
serde = { version = "1.0", features = ["derive"] }
1818
tauri = { workspace = true, features = [] }
1919
tauri-specta = { path = "../../../", features = ["derive", "typescript", "javascript"] }
2020
specta-typescript = { workspace = true }
2121
tauri-plugin-os = "^2.3.2"
2222
thiserror = "2"
23+
bytes = { version = "1.11.1", features = ["serde"] }
24+
chrono = { version = "0.4.44", features = ["serde"] }
2325

2426
[features]
2527
default = ["custom-protocol"]

examples/app/src-tauri/src/main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use serde::{Deserialize, Serialize};
77
use specta::Type;
88
use specta_typescript::Typescript;
9+
use tauri::{AppHandle, ipc::Channel};
910
use tauri_specta::*;
1011
use thiserror::Error;
1112

@@ -49,6 +50,18 @@ fn deprecated() {}
4950
#[specta::specta]
5051
fn with_channel(_channel: tauri::ipc::Channel<i32>) {}
5152

53+
#[derive(Serialize, Deserialize, Type)]
54+
struct PhaseSpecificRename {
55+
#[serde(rename(serialize = "serialized_value", deserialize = "deserialized_value"))]
56+
value: String,
57+
}
58+
59+
#[tauri::command]
60+
#[specta::specta]
61+
fn phase_specific_rename(input: PhaseSpecificRename) -> PhaseSpecificRename {
62+
input
63+
}
64+
5265
mod nested {
5366
use super::*;
5467

@@ -134,6 +147,7 @@ fn main() {
134147
generic::<tauri::Wry>,
135148
deprecated,
136149
with_channel,
150+
phase_specific_rename,
137151
typesafe_errors_using_thiserror,
138152
typesafe_errors_using_thiserror_with_value,
139153
])

examples/app/src/bindings-js-files/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export const commands = {
4848
* @returns {string} myName
4949
*/
5050
withChannel: (channel) => __TAURI_INVOKE("with_channel", { channel }),
51+
/**
52+
* @param {tauri_specta_example_app.PhaseSpecificRename_Deserialize} input
53+
* @returns {string} myName
54+
*/
55+
phaseSpecificRename: (input) => __TAURI_INVOKE("phase_specific_rename", { input }),
5156
/**
5257
* @returns {string} myName
5358
*/

examples/app/src/bindings-js-files/tauri_specta_example_app.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,27 @@
88
*
99
* @typedef {null} EmptyEvent
1010
*
11-
* @typedef {{ type: "IoError"; data: { type: "IoError" } } | { type: "AnotherError"; data: string }} MyError
12-
* @property {{ type: "IoError"; data: { type: "IoError" } }} IoError
11+
* @typedef {{ type: "IoError" } | { type: "AnotherError"; data: string }} MyError
12+
* @property {{ type: "IoError" }} IoError
1313
* @property {{ type: "AnotherError"; data: string }} AnotherError
1414
*
1515
* @typedef {{ type: "IoError"; data: string }} MyError2
1616
* @property {{ type: "IoError"; data: string }} IoError
1717
*
18+
* @typedef {PhaseSpecificRename_Serialize | PhaseSpecificRename_Deserialize} PhaseSpecificRename
19+
* @property {PhaseSpecificRename_Serialize} Serialize
20+
* @property {PhaseSpecificRename_Deserialize} Deserialize
21+
*
22+
* @typedef {{
23+
* deserialized_value: string,
24+
* }} PhaseSpecificRename_Deserialize
25+
* @property {string} deserialized_value
26+
*
27+
* @typedef {{
28+
* serialized_value: string,
29+
* }} PhaseSpecificRename_Serialize
30+
* @property {string} serialized_value
31+
*
1832
* @typedef {{
1933
* a: string,
2034
* }} Testing

examples/app/src/bindings-js.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ export const commands = {
4444
* @returns {string} myName
4545
*/
4646
withChannel: (channel) => __TAURI_INVOKE("with_channel", { channel }),
47+
/**
48+
* @param {PhaseSpecificRename_Deserialize} input
49+
* @returns {string} myName
50+
*/
51+
phaseSpecificRename: (input) => __TAURI_INVOKE("phase_specific_rename", { input }),
4752
/**
4853
* @returns {string} myName
4954
*/
@@ -79,8 +84,8 @@ export const universalConstant = 42;
7984
*
8085
* @typedef {null} EmptyEvent
8186
*
82-
* @typedef {{ type: "IoError"; data: { type: "IoError" } } | { type: "AnotherError"; data: string }} MyError
83-
* @property {{ type: "IoError"; data: { type: "IoError" } }} IoError
87+
* @typedef {{ type: "IoError" } | { type: "AnotherError"; data: string }} MyError
88+
* @property {{ type: "IoError" }} IoError
8489
* @property {{ type: "AnotherError"; data: string }} AnotherError
8590
*
8691
* @typedef {{ type: "IoError"; data: string }} MyError2
@@ -91,6 +96,20 @@ export const universalConstant = 42;
9196
* }} MyStruct
9297
* @property {string} some_field
9398
*
99+
* @typedef {PhaseSpecificRename_Serialize | PhaseSpecificRename_Deserialize} PhaseSpecificRename
100+
* @property {PhaseSpecificRename_Serialize} Serialize
101+
* @property {PhaseSpecificRename_Deserialize} Deserialize
102+
*
103+
* @typedef {{
104+
* deserialized_value: string,
105+
* }} PhaseSpecificRename_Deserialize
106+
* @property {string} deserialized_value
107+
*
108+
* @typedef {{
109+
* serialized_value: string,
110+
* }} PhaseSpecificRename_Serialize
111+
* @property {string} serialized_value
112+
*
94113
* @typedef {{
95114
* a: string,
96115
* }} Testing

examples/app/src/bindings-ts-files/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const commands = {
2424
*/
2525
deprecated: () => __TAURI_INVOKE<void>("deprecated"),
2626
withChannel: (channel: Channel<number>) => __TAURI_INVOKE<void>("with_channel", { channel }),
27+
phaseSpecificRename: (input: tauri_specta_example_app.PhaseSpecificRename_Deserialize) => __TAURI_INVOKE<tauri_specta_example_app.PhaseSpecificRename_Serialize>("phase_specific_rename", { input }),
2728
typesafeErrorsUsingThiserror: () => typedError<null, tauri_specta_example_app.MyError>(__TAURI_INVOKE("typesafe_errors_using_thiserror")),
2829
typesafeErrorsUsingThiserrorWithValue: () => typedError<null, tauri_specta_example_app.MyError2>(__TAURI_INVOKE("typesafe_errors_using_thiserror_with_value")),
2930
};

examples/app/src/bindings-ts-files/tauri_specta_example_app.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@ export type DemoEvent = string;
55

66
export type EmptyEvent = null;
77

8-
export type MyError = { type: "IoError"; data: { type: "IoError" } } | { type: "AnotherError"; data: string };
8+
export type MyError = { type: "IoError" } | { type: "AnotherError"; data: string };
99

1010
export type MyError2 = { type: "IoError"; data: string };
1111

12+
export type PhaseSpecificRename = PhaseSpecificRename_Serialize | PhaseSpecificRename_Deserialize;
13+
14+
export type PhaseSpecificRename_Deserialize = {
15+
deserialized_value: string,
16+
};
17+
18+
export type PhaseSpecificRename_Serialize = {
19+
serialized_value: string,
20+
};
21+
1222
export type Testing = {
1323
a: string,
1424
};

0 commit comments

Comments
 (0)