From 19c51f74d28ab975bebf4f51d137e3661506a249 Mon Sep 17 00:00:00 2001 From: Tom Anderson Date: Mon, 2 Dec 2024 18:38:55 +1100 Subject: [PATCH 1/3] update router TS type to re-export all imported types --- src/server/router.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/server/router.rs b/src/server/router.rs index 818619a..acaa55f 100644 --- a/src/server/router.rs +++ b/src/server/router.rs @@ -63,7 +63,7 @@ where let header = String::from(include_str!("../header.txt")); // Export all the dependencies, and create their import statements - let (imports, _types) = self + let (imports, exports, _types) = self .get_handlers() .into_iter() .flat_map(|handler| { @@ -79,10 +79,10 @@ where .chain((handler.qubit_types)().into_iter().map(|ty| ty.to_ts())) }) .fold( - (String::new(), HashSet::new()), - |(mut imports, mut types), ty| { + (String::new(), String::new(), HashSet::new()), + |(mut imports, mut exports, mut types), ty| { if types.contains(&ty) { - return (imports, types); + return (imports, exports, types); } let (package, ty_name) = ty; @@ -93,9 +93,15 @@ where ) .unwrap(); + writeln!( + &mut exports, + r#"export type {{ {ty_name} }} from "{package}";"#, + ) + .unwrap(); + types.insert((package, ty_name)); - (imports, types) + (imports, exports, types) }, ); @@ -105,7 +111,7 @@ where // Write out index file fs::write( out_dir.join("index.ts"), - [header, imports, server_type] + [header, imports, exports, server_type] .into_iter() .filter(|part| !part.is_empty()) .collect::>() From 4ab9183dc8af4a225c592471b2601f7ff69bcf35 Mon Sep 17 00:00:00 2001 From: Tom Anderson Date: Mon, 2 Dec 2024 18:39:24 +1100 Subject: [PATCH 2/3] update examples --- .../authentication/auth-demo/src/bindings/index.ts | 2 ++ examples/chaos/bindings/index.ts | 10 ++++++++++ examples/chat-room-react/src/bindings/index.ts | 5 +++++ examples/counter/bindings/index.ts | 4 ++++ examples/hello-world/bindings/index.ts | 2 ++ 5 files changed, 23 insertions(+) diff --git a/examples/authentication/auth-demo/src/bindings/index.ts b/examples/authentication/auth-demo/src/bindings/index.ts index be8a071..6d23030 100644 --- a/examples/authentication/auth-demo/src/bindings/index.ts +++ b/examples/authentication/auth-demo/src/bindings/index.ts @@ -12,4 +12,6 @@ import type { Query } from "@qubit-rs/client"; +export type { Query } from "@qubit-rs/client"; + export type QubitServer = { echo_cookie: Query<[], string>, secret_endpoint: Query<[], string> }; \ No newline at end of file diff --git a/examples/chaos/bindings/index.ts b/examples/chaos/bindings/index.ts index 798f29a..e56c8f6 100644 --- a/examples/chaos/bindings/index.ts +++ b/examples/chaos/bindings/index.ts @@ -20,4 +20,14 @@ import type { Metadata } from "./Metadata.ts"; import type { User } from "./User.ts"; import type { Test } from "./Test.ts"; +export type { Query } from "@qubit-rs/client"; +export type { Mutation } from "@qubit-rs/client"; +export type { Subscription } from "@qubit-rs/client"; +export type { NestedStruct } from "./NestedStruct.ts"; +export type { MyEnum } from "./MyEnum.ts"; +export type { UniqueType } from "./UniqueType.ts"; +export type { Metadata } from "./Metadata.ts"; +export type { User } from "./User.ts"; +export type { Test } from "./Test.ts"; + export type QubitServer = { version: Query<[], string>, count: Mutation<[], number>, countdown: Subscription<[min: number, max: number, ], number>, array: Query<[], Array>, enum_test: Query<[], MyEnum>, array_type: Query<[], Array>, user: { someHandler: Query<[_id: string, ], User>, create: Mutation<[name: string, email: string, age: number, ], User>, list: Query<[], Array>, asdf: Query<[], null> } }; \ No newline at end of file diff --git a/examples/chat-room-react/src/bindings/index.ts b/examples/chat-room-react/src/bindings/index.ts index 9b8b02f..46001dc 100644 --- a/examples/chat-room-react/src/bindings/index.ts +++ b/examples/chat-room-react/src/bindings/index.ts @@ -15,4 +15,9 @@ import type { Mutation } from "@qubit-rs/client"; import type { Subscription } from "@qubit-rs/client"; import type { ChatMessage } from "./ChatMessage.ts"; +export type { Query } from "@qubit-rs/client"; +export type { Mutation } from "@qubit-rs/client"; +export type { Subscription } from "@qubit-rs/client"; +export type { ChatMessage } from "./ChatMessage.ts"; + export type QubitServer = { get_name: Query<[], string>, send_message: Mutation<[message: string, ], null>, list_online: Subscription<[], Array>, list_messages: Subscription<[], Array> }; \ No newline at end of file diff --git a/examples/counter/bindings/index.ts b/examples/counter/bindings/index.ts index 68bd1c8..1781b80 100644 --- a/examples/counter/bindings/index.ts +++ b/examples/counter/bindings/index.ts @@ -14,4 +14,8 @@ import type { Mutation } from "@qubit-rs/client"; import type { Query } from "@qubit-rs/client"; import type { Subscription } from "@qubit-rs/client"; +export type { Mutation } from "@qubit-rs/client"; +export type { Query } from "@qubit-rs/client"; +export type { Subscription } from "@qubit-rs/client"; + export type QubitServer = { increment: Mutation<[], null>, decrement: Mutation<[], null>, add: Mutation<[n: number, ], null>, get: Query<[], number>, countdown: Subscription<[], number> }; \ No newline at end of file diff --git a/examples/hello-world/bindings/index.ts b/examples/hello-world/bindings/index.ts index 16c2d43..3dd79d2 100644 --- a/examples/hello-world/bindings/index.ts +++ b/examples/hello-world/bindings/index.ts @@ -12,4 +12,6 @@ import type { Query } from "@qubit-rs/client"; +export type { Query } from "@qubit-rs/client"; + export type QubitServer = { hello_world: Query<[], string> }; \ No newline at end of file From 69982570ec2183ff1e639f78d71281de91bb733f Mon Sep 17 00:00:00 2001 From: Tom Anderson Date: Mon, 2 Dec 2024 18:40:13 +1100 Subject: [PATCH 3/3] add changelog --- .changes/index-barrel-file.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changes/index-barrel-file.md diff --git a/.changes/index-barrel-file.md b/.changes/index-barrel-file.md new file mode 100644 index 0000000..35010c3 --- /dev/null +++ b/.changes/index-barrel-file.md @@ -0,0 +1,5 @@ +--- +"qubit": patch +--- + +Alter router type generation to re-export all types.