diff --git a/Cargo.lock b/Cargo.lock index 1efc64b..27a1adf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -721,7 +721,7 @@ dependencies = [ "tokio", "tower", "trait-variant", - "ts-rs", + "ts-rs 9.0.1", "urlencoding", ] @@ -732,7 +732,7 @@ dependencies = [ "proc-macro2", "quote", "syn", - "ts-rs", + "ts-rs 8.1.0", ] [[package]] @@ -1119,7 +1119,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d3fa4606cdab1e9b668cc65ce2545941d01f52bc27536a195c66c55b91cb84" dependencies = [ "thiserror", - "ts-rs-macros", + "ts-rs-macros 8.1.0", +] + +[[package]] +name = "ts-rs" +version = "9.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b44017f9f875786e543595076374b9ef7d13465a518dd93d6ccdbf5b432dde8c" +dependencies = [ + "thiserror", + "ts-rs-macros 9.0.1", ] [[package]] @@ -1135,6 +1145,18 @@ dependencies = [ "termcolor", ] +[[package]] +name = "ts-rs-macros" +version = "9.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c88cc88fd23b5a04528f3a8436024f20010a16ec18eb23c164b1242f65860130" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "termcolor", +] + [[package]] name = "typenum" version = "1.17.0" diff --git a/Cargo.toml b/Cargo.toml index 47b405e..02b0a67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ serde = { version = "1.0.195", features = ["derive"] } serde_json = "1.0.117" tokio = { version = "1.38", features = ["rt", "rt-multi-thread"] } tower = "0.4" -ts-rs = "8.1.0" +ts-rs = "9.0.1" qubit-macros = { version = "0.6.4", path = "./crates/qubit-macros" } trait-variant = "0.1.2" serde_qs = "0.13.0" diff --git a/examples/authentication/Cargo.lock b/examples/authentication/Cargo.lock index 1a9b10e..12c8514 100644 --- a/examples/authentication/Cargo.lock +++ b/examples/authentication/Cargo.lock @@ -58,7 +58,7 @@ dependencies = [ "serde", "tokio", "tower", - "ts-rs", + "ts-rs 9.0.1", ] [[package]] @@ -767,7 +767,7 @@ dependencies = [ "tokio", "tower", "trait-variant", - "ts-rs", + "ts-rs 9.0.1", "urlencoding", ] @@ -778,7 +778,7 @@ dependencies = [ "proc-macro2", "quote", "syn", - "ts-rs", + "ts-rs 8.1.0", ] [[package]] @@ -1207,7 +1207,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d3fa4606cdab1e9b668cc65ce2545941d01f52bc27536a195c66c55b91cb84" dependencies = [ "thiserror", - "ts-rs-macros", + "ts-rs-macros 8.1.0", +] + +[[package]] +name = "ts-rs" +version = "9.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b44017f9f875786e543595076374b9ef7d13465a518dd93d6ccdbf5b432dde8c" +dependencies = [ + "thiserror", + "ts-rs-macros 9.0.1", ] [[package]] @@ -1223,6 +1233,18 @@ dependencies = [ "termcolor", ] +[[package]] +name = "ts-rs-macros" +version = "9.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c88cc88fd23b5a04528f3a8436024f20010a16ec18eb23c164b1242f65860130" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "termcolor", +] + [[package]] name = "typenum" version = "1.17.0" diff --git a/examples/authentication/Cargo.toml b/examples/authentication/Cargo.toml index 3915027..7ccf068 100644 --- a/examples/authentication/Cargo.toml +++ b/examples/authentication/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] qubit = { path = "../../" } -ts-rs = "8.1.0" +ts-rs = "9.0.1" serde = { version = "1.0", features = ["derive"] } futures = "0.3.30" diff --git a/examples/chaos/Cargo.lock b/examples/chaos/Cargo.lock index 51649ee..39310f3 100644 --- a/examples/chaos/Cargo.lock +++ b/examples/chaos/Cargo.lock @@ -183,7 +183,7 @@ dependencies = [ "serde_json", "tokio", "tower", - "ts-rs", + "ts-rs 9.0.1", ] [[package]] @@ -748,7 +748,7 @@ dependencies = [ "tokio", "tower", "trait-variant", - "ts-rs", + "ts-rs 9.0.1", "urlencoding", ] @@ -759,7 +759,7 @@ dependencies = [ "proc-macro2", "quote", "syn", - "ts-rs", + "ts-rs 8.1.0", ] [[package]] @@ -1146,7 +1146,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d3fa4606cdab1e9b668cc65ce2545941d01f52bc27536a195c66c55b91cb84" dependencies = [ "thiserror", - "ts-rs-macros", + "ts-rs-macros 8.1.0", +] + +[[package]] +name = "ts-rs" +version = "9.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b44017f9f875786e543595076374b9ef7d13465a518dd93d6ccdbf5b432dde8c" +dependencies = [ + "thiserror", + "ts-rs-macros 9.0.1", ] [[package]] @@ -1162,6 +1172,18 @@ dependencies = [ "termcolor", ] +[[package]] +name = "ts-rs-macros" +version = "9.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c88cc88fd23b5a04528f3a8436024f20010a16ec18eb23c164b1242f65860130" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "termcolor", +] + [[package]] name = "typenum" version = "1.17.0" diff --git a/examples/chaos/Cargo.toml b/examples/chaos/Cargo.toml index 92d7c89..a3b077d 100644 --- a/examples/chaos/Cargo.toml +++ b/examples/chaos/Cargo.toml @@ -15,4 +15,4 @@ serde = { version = "1.0.195", features = ["derive"] } serde_json = "1.0.111" tokio = { version = "1.35.1", features = ["rt", "rt-multi-thread"] } tower = "0.4.13" -ts-rs = "8.1.0" +ts-rs = "9.0.1" diff --git a/examples/chaos/bindings/Metadata.ts b/examples/chaos/bindings/Metadata.ts index 7243fca..58f4478 100644 --- a/examples/chaos/bindings/Metadata.ts +++ b/examples/chaos/bindings/Metadata.ts @@ -1,3 +1,3 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export type Metadata = { param_a: string, param_b: number, param_c: boolean, more_metadata: Metadata | null, }; \ No newline at end of file +export type Metadata = { param_a: string, param_b: number, param_c: boolean, more_metadata: Metadata | null, }; diff --git a/examples/chaos/bindings/MyEnum.ts b/examples/chaos/bindings/MyEnum.ts index c98b0d3..7532be5 100644 --- a/examples/chaos/bindings/MyEnum.ts +++ b/examples/chaos/bindings/MyEnum.ts @@ -1,4 +1,4 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. import type { NestedStruct } from "./NestedStruct"; -export type MyEnum = "A" | { "B": number } | { "C": { field: number, } } | { "D": NestedStruct }; \ No newline at end of file +export type MyEnum = "A" | { "B": number } | { "C": { field: number, } } | { "D": NestedStruct }; diff --git a/examples/chaos/bindings/NestedStruct.ts b/examples/chaos/bindings/NestedStruct.ts index eb38db0..b4184de 100644 --- a/examples/chaos/bindings/NestedStruct.ts +++ b/examples/chaos/bindings/NestedStruct.ts @@ -1,3 +1,3 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export type NestedStruct = { a: number, b: boolean, }; \ No newline at end of file +export type NestedStruct = { a: number, b: boolean, }; diff --git a/examples/chaos/bindings/Test.ts b/examples/chaos/bindings/Test.ts index 652e0e7..e6b2c9f 100644 --- a/examples/chaos/bindings/Test.ts +++ b/examples/chaos/bindings/Test.ts @@ -1,3 +1,3 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export type Test = { a: number, b: boolean, }; \ No newline at end of file +export type Test = { a: number, b: boolean, }; diff --git a/examples/chaos/bindings/User.ts b/examples/chaos/bindings/User.ts index 755c6c3..fb25f24 100644 --- a/examples/chaos/bindings/User.ts +++ b/examples/chaos/bindings/User.ts @@ -1,4 +1,4 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. import type { Metadata } from "./Metadata"; -export type User = { name: string, email: string, age: number, metadata: Metadata, }; \ No newline at end of file +export type User = { name: string, email: string, age: number, metadata: Metadata, }; diff --git a/examples/chat-room-react/src-rust/Cargo.lock b/examples/chat-room-react/src-rust/Cargo.lock index 5818895..31e8c4c 100644 --- a/examples/chat-room-react/src-rust/Cargo.lock +++ b/examples/chat-room-react/src-rust/Cargo.lock @@ -181,7 +181,7 @@ dependencies = [ "rand", "serde", "tokio", - "ts-rs", + "ts-rs 9.0.1", ] [[package]] @@ -735,7 +735,7 @@ dependencies = [ "tokio", "tower", "trait-variant", - "ts-rs", + "ts-rs 9.0.1", "urlencoding", ] @@ -746,7 +746,7 @@ dependencies = [ "proc-macro2", "quote", "syn", - "ts-rs", + "ts-rs 8.1.0", ] [[package]] @@ -1144,7 +1144,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d3fa4606cdab1e9b668cc65ce2545941d01f52bc27536a195c66c55b91cb84" dependencies = [ "thiserror", - "ts-rs-macros", + "ts-rs-macros 8.1.0", +] + +[[package]] +name = "ts-rs" +version = "9.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b44017f9f875786e543595076374b9ef7d13465a518dd93d6ccdbf5b432dde8c" +dependencies = [ + "thiserror", + "ts-rs-macros 9.0.1", ] [[package]] @@ -1160,6 +1170,18 @@ dependencies = [ "termcolor", ] +[[package]] +name = "ts-rs-macros" +version = "9.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c88cc88fd23b5a04528f3a8436024f20010a16ec18eb23c164b1242f65860130" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "termcolor", +] + [[package]] name = "typenum" version = "1.17.0" diff --git a/examples/chat-room-react/src-rust/Cargo.toml b/examples/chat-room-react/src-rust/Cargo.toml index a54ee42..00a007f 100644 --- a/examples/chat-room-react/src-rust/Cargo.toml +++ b/examples/chat-room-react/src-rust/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] qubit = { path = "../../../" } -ts-rs = "8.1.0" +ts-rs = "9.0.1" serde = { version = "1.0", features = ["derive"] } futures = "0.3.30" diff --git a/examples/chat-room-react/src/bindings/ChatMessage.ts b/examples/chat-room-react/src/bindings/ChatMessage.ts index 21dc94b..36da0cb 100644 --- a/examples/chat-room-react/src/bindings/ChatMessage.ts +++ b/examples/chat-room-react/src/bindings/ChatMessage.ts @@ -1,3 +1,3 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export type ChatMessage = { user: string, content: string, }; \ No newline at end of file +export type ChatMessage = { user: string, content: string, }; diff --git a/examples/counter/Cargo.lock b/examples/counter/Cargo.lock index b1b34c6..17520e2 100644 --- a/examples/counter/Cargo.lock +++ b/examples/counter/Cargo.lock @@ -180,7 +180,7 @@ dependencies = [ "qubit", "serde", "tokio", - "ts-rs", + "ts-rs 9.0.1", ] [[package]] @@ -734,7 +734,7 @@ dependencies = [ "tokio", "tower", "trait-variant", - "ts-rs", + "ts-rs 9.0.1", "urlencoding", ] @@ -745,7 +745,7 @@ dependencies = [ "proc-macro2", "quote", "syn", - "ts-rs", + "ts-rs 8.1.0", ] [[package]] @@ -1143,7 +1143,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d3fa4606cdab1e9b668cc65ce2545941d01f52bc27536a195c66c55b91cb84" dependencies = [ "thiserror", - "ts-rs-macros", + "ts-rs-macros 8.1.0", +] + +[[package]] +name = "ts-rs" +version = "9.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b44017f9f875786e543595076374b9ef7d13465a518dd93d6ccdbf5b432dde8c" +dependencies = [ + "thiserror", + "ts-rs-macros 9.0.1", ] [[package]] @@ -1159,6 +1169,18 @@ dependencies = [ "termcolor", ] +[[package]] +name = "ts-rs-macros" +version = "9.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c88cc88fd23b5a04528f3a8436024f20010a16ec18eb23c164b1242f65860130" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "termcolor", +] + [[package]] name = "typenum" version = "1.17.0" diff --git a/examples/counter/Cargo.toml b/examples/counter/Cargo.toml index 9767888..ebe4ea7 100644 --- a/examples/counter/Cargo.toml +++ b/examples/counter/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] qubit = { path = "../../" } -ts-rs = "8.1.0" +ts-rs = "9.0.1" serde = { version = "1.0", features = ["derive"] } futures = "0.3.30" diff --git a/examples/hello-world/Cargo.lock b/examples/hello-world/Cargo.lock index 48a1758..e7e6507 100644 --- a/examples/hello-world/Cargo.lock +++ b/examples/hello-world/Cargo.lock @@ -371,7 +371,7 @@ dependencies = [ "qubit", "serde", "tokio", - "ts-rs", + "ts-rs 9.0.1", ] [[package]] @@ -734,7 +734,7 @@ dependencies = [ "tokio", "tower", "trait-variant", - "ts-rs", + "ts-rs 9.0.1", "urlencoding", ] @@ -745,7 +745,7 @@ dependencies = [ "proc-macro2", "quote", "syn", - "ts-rs", + "ts-rs 8.1.0", ] [[package]] @@ -1143,7 +1143,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d3fa4606cdab1e9b668cc65ce2545941d01f52bc27536a195c66c55b91cb84" dependencies = [ "thiserror", - "ts-rs-macros", + "ts-rs-macros 8.1.0", +] + +[[package]] +name = "ts-rs" +version = "9.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b44017f9f875786e543595076374b9ef7d13465a518dd93d6ccdbf5b432dde8c" +dependencies = [ + "thiserror", + "ts-rs-macros 9.0.1", ] [[package]] @@ -1159,6 +1169,18 @@ dependencies = [ "termcolor", ] +[[package]] +name = "ts-rs-macros" +version = "9.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c88cc88fd23b5a04528f3a8436024f20010a16ec18eb23c164b1242f65860130" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "termcolor", +] + [[package]] name = "typenum" version = "1.17.0" diff --git a/examples/hello-world/Cargo.toml b/examples/hello-world/Cargo.toml index 748b963..aa08741 100644 --- a/examples/hello-world/Cargo.toml +++ b/examples/hello-world/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] qubit = { path = "../../" } -ts-rs = "8.1.0" +ts-rs = "9.0.1" serde = { version = "1.0", features = ["derive"] } futures = "0.3.30" diff --git a/src/builder/ty/util/exporter.rs b/src/builder/ty/util/exporter.rs index a54a045..dd24845 100644 --- a/src/builder/ty/util/exporter.rs +++ b/src/builder/ty/util/exporter.rs @@ -1,9 +1,6 @@ use std::path::{Path, PathBuf}; -use ts_rs::{ - typelist::{TypeList, TypeVisitor}, - Dependency, ExportError, TS, -}; +use ts_rs::{Dependency, ExportError, TypeVisitor, TS}; /// Visitor for [`ts_rs::TypeList`], which will export each type and any dependent types. It will /// also save a list of top level [`Dependency`]s that must be imported in order for the original @@ -15,10 +12,10 @@ struct TypeListExporter { impl TypeListExporter { /// Create a new empty instance. - pub fn new(out_dir: impl AsRef) -> Self { + pub fn new(out_dir: impl AsRef, dependencies: Vec) -> Self { Self { out_dir: out_dir.as_ref().to_owned(), - dependencies: Vec::new(), + dependencies, } } @@ -26,23 +23,12 @@ impl TypeListExporter { pub fn into_inner(self) -> Vec { self.dependencies } - - /// Export the provided type list, and return the dependency list. - pub fn export(type_list: impl TypeList, out_dir: impl AsRef) -> Vec { - let mut visitor = Self::new(out_dir); - - type_list.for_each(&mut visitor); - - visitor.into_inner() - } } impl TypeVisitor for TypeListExporter { fn visit(&mut self) { let Some(dep) = Dependency::from_ty::() else { // Type must be a primitive, so recurse to ensure all generics are properly exported. - T::dependency_types().for_each(self); - T::generics().for_each(self); return; }; @@ -67,8 +53,10 @@ pub fn export_with_dependencies( out_dir: impl AsRef, ) -> Result, ExportError> { // Ensure any generics used in the type are exported - let mut dependencies = - TypeListExporter::export(T::dependency_types().extend(T::generics()), &out_dir); + let mut exporter = TypeListExporter::new(&out_dir, T::dependencies()); + T::visit_generics(&mut exporter); + + let mut dependencies = exporter.into_inner(); // Make sure the top-level type isn't a primitive, so it can be exported. if T::output_path().is_some() {