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. 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 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::>()