|
1 |
| -use std::{borrow::Cow, collections::HashMap, path::Path}; |
2 |
| - |
3 |
| -use specta::datatype::DataType; |
4 |
| -use specta_typescript::ExportError; |
5 |
| - |
6 |
| -use crate::{procedure::ProcedureType, types::TypesOrType, ProcedureKind, Types}; |
7 |
| - |
8 |
| -pub struct Rust(()); // TODO: specta_rust::Rust |
9 |
| - |
10 |
| -// TODO: Traits - `Debug`, `Clone`, etc |
11 |
| - |
12 |
| -impl Default for Rust { |
13 |
| - fn default() -> Self { |
14 |
| - Self(()) // TODO: specta_typescript::Typescript::default().framework_header("// This file was generated by [rspc](https://github.com/specta-rs/rspc). Do not edit this file manually.") |
15 |
| - } |
16 |
| -} |
17 |
| - |
18 |
| -impl Rust { |
19 |
| - // TODO: Clone all methods from `specta_rust::Rust` |
20 |
| - |
21 |
| - pub fn export_to(&self, path: impl AsRef<Path>, types: &Types) -> Result<(), ExportError> { |
22 |
| - std::fs::write(path, self.export(types)?)?; |
23 |
| - // TODO: Format file |
24 |
| - Ok(()) |
25 |
| - } |
26 |
| - |
27 |
| - pub fn export(&self, types: &Types) -> Result<String, ExportError> { |
28 |
| - println!("WARNING: `rspc::Rust` is an unstable feature! Use at your own discretion!"); |
29 |
| - |
30 |
| - let mut s = "//! This file was generated by [rspc](https://github.com/specta-rs/rspc). Do not edit this file manually.\n\npub struct Procedures;\n\n".to_string(); |
31 |
| - |
32 |
| - // TODO: Move to `specta_rust::Rust` which should handle this like we do with Typescript. |
33 |
| - for (_, ty) in types.types.into_iter() { |
34 |
| - s.push_str(&specta_rust::export_named_datatype(ty).unwrap()) |
35 |
| - } |
36 |
| - |
37 |
| - // TODO: disabling warning on the output??? |
38 |
| - |
39 |
| - for (key, item) in types.procedures.clone().into_iter() { |
40 |
| - export(&mut s, key.to_string(), key, item); |
41 |
| - } |
42 |
| - |
43 |
| - Ok(s) |
44 |
| - } |
45 |
| -} |
46 |
| - |
47 |
| -fn export(s: &mut String, full_key: String, ident: Cow<'static, str>, item: TypesOrType) { |
48 |
| - match item { |
49 |
| - TypesOrType::Type(ty) => { |
50 |
| - let kind = match ty.kind { |
51 |
| - ProcedureKind::Query => "Query", |
52 |
| - ProcedureKind::Mutation => "Mutation", |
53 |
| - ProcedureKind::Subscription => "Subscription", |
54 |
| - }; |
55 |
| - |
56 |
| - let input = specta_rust::datatype(&ty.input).unwrap(); |
57 |
| - let output = specta_rust::datatype(&ty.output).unwrap(); |
58 |
| - let error = "()"; // TODO: specta_rust::datatype(&ty.error).unwrap(); |
59 |
| - |
60 |
| - s.push_str(&format!( |
61 |
| - r#"pub struct {ident}; |
62 |
| -
|
63 |
| -impl rspc_client::Procedure for {ident} {{ |
64 |
| - type Input = {input}; |
65 |
| - type Output = {output}; |
66 |
| - type Error = {error}; |
67 |
| - type Procedures = Procedures; |
68 |
| - const KIND: rspc_client::ProcedureKind = rspc_client::ProcedureKind::{kind}; |
69 |
| - const KEY: &'static str = "{ident}"; |
70 |
| -}} |
71 |
| -
|
72 |
| -"# |
73 |
| - )); |
74 |
| - } |
75 |
| - TypesOrType::Types(inner) => { |
76 |
| - for (key, item) in inner { |
77 |
| - s.push_str(&format!("\npub mod {key} {{\n")); |
78 |
| - s.push_str(&"\tpub use super::Procedures;\n"); |
79 |
| - export(s, format!("{full_key}.{key}"), key, item); // TODO: Inset all items by the correct nuber of tabs |
80 |
| - s.push_str("}\n"); |
81 |
| - } |
82 |
| - } |
83 |
| - } |
84 |
| -} |
| 1 | +//! TODO: Bring this back when published. |
| 2 | +// use std::{borrow::Cow, collections::HashMap, path::Path}; |
| 3 | + |
| 4 | +// use specta::datatype::DataType; |
| 5 | +// use specta_typescript::ExportError; |
| 6 | + |
| 7 | +// use crate::{procedure::ProcedureType, types::TypesOrType, ProcedureKind, Types}; |
| 8 | + |
| 9 | +// pub struct Rust(()); // TODO: specta_rust::Rust |
| 10 | + |
| 11 | +// // TODO: Traits - `Debug`, `Clone`, etc |
| 12 | + |
| 13 | +// impl Default for Rust { |
| 14 | +// fn default() -> Self { |
| 15 | +// Self(()) // TODO: specta_typescript::Typescript::default().framework_header("// This file was generated by [rspc](https://github.com/specta-rs/rspc). Do not edit this file manually.") |
| 16 | +// } |
| 17 | +// } |
| 18 | + |
| 19 | +// impl Rust { |
| 20 | +// // TODO: Clone all methods from `specta_rust::Rust` |
| 21 | + |
| 22 | +// pub fn export_to(&self, path: impl AsRef<Path>, types: &Types) -> Result<(), ExportError> { |
| 23 | +// std::fs::write(path, self.export(types)?)?; |
| 24 | +// // TODO: Format file |
| 25 | +// Ok(()) |
| 26 | +// } |
| 27 | + |
| 28 | +// pub fn export(&self, types: &Types) -> Result<String, ExportError> { |
| 29 | +// println!("WARNING: `rspc::Rust` is an unstable feature! Use at your own discretion!"); |
| 30 | + |
| 31 | +// let mut s = "//! This file was generated by [rspc](https://github.com/specta-rs/rspc). Do not edit this file manually.\n\npub struct Procedures;\n\n".to_string(); |
| 32 | + |
| 33 | +// // TODO: Move to `specta_rust::Rust` which should handle this like we do with Typescript. |
| 34 | +// for (_, ty) in types.types.into_iter() { |
| 35 | +// s.push_str(&specta_rust::export_named_datatype(ty).unwrap()) |
| 36 | +// } |
| 37 | + |
| 38 | +// // TODO: disabling warning on the output??? |
| 39 | + |
| 40 | +// for (key, item) in types.procedures.clone().into_iter() { |
| 41 | +// export(&mut s, key.to_string(), key, item); |
| 42 | +// } |
| 43 | + |
| 44 | +// Ok(s) |
| 45 | +// } |
| 46 | +// } |
| 47 | + |
| 48 | +// fn export(s: &mut String, full_key: String, ident: Cow<'static, str>, item: TypesOrType) { |
| 49 | +// match item { |
| 50 | +// TypesOrType::Type(ty) => { |
| 51 | +// let kind = match ty.kind { |
| 52 | +// ProcedureKind::Query => "Query", |
| 53 | +// ProcedureKind::Mutation => "Mutation", |
| 54 | +// ProcedureKind::Subscription => "Subscription", |
| 55 | +// }; |
| 56 | + |
| 57 | +// let input = specta_rust::datatype(&ty.input).unwrap(); |
| 58 | +// let output = specta_rust::datatype(&ty.output).unwrap(); |
| 59 | +// let error = "()"; // TODO: specta_rust::datatype(&ty.error).unwrap(); |
| 60 | + |
| 61 | +// s.push_str(&format!( |
| 62 | +// r#"pub struct {ident}; |
| 63 | + |
| 64 | +// impl rspc_client::Procedure for {ident} {{ |
| 65 | +// type Input = {input}; |
| 66 | +// type Output = {output}; |
| 67 | +// type Error = {error}; |
| 68 | +// type Procedures = Procedures; |
| 69 | +// const KIND: rspc_client::ProcedureKind = rspc_client::ProcedureKind::{kind}; |
| 70 | +// const KEY: &'static str = "{ident}"; |
| 71 | +// }} |
| 72 | + |
| 73 | +// "# |
| 74 | +// )); |
| 75 | +// } |
| 76 | +// TypesOrType::Types(inner) => { |
| 77 | +// for (key, item) in inner { |
| 78 | +// s.push_str(&format!("\npub mod {key} {{\n")); |
| 79 | +// s.push_str(&"\tpub use super::Procedures;\n"); |
| 80 | +// export(s, format!("{full_key}.{key}"), key, item); // TODO: Inset all items by the correct nuber of tabs |
| 81 | +// s.push_str("}\n"); |
| 82 | +// } |
| 83 | +// } |
| 84 | +// } |
| 85 | +// } |
0 commit comments