diff --git a/Cargo.lock b/Cargo.lock index 759afe3..8ea15e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -105,7 +105,7 @@ dependencies = [ "miniz_oxide", "object", "rustc-demangle", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -193,6 +193,16 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +[[package]] +name = "colored" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" +dependencies = [ + "lazy_static", + "windows-sys 0.59.0", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -210,13 +220,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] -name = "ctor" -version = "0.2.8" +name = "deranged" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edb49164822f3ee45b17acd4a208cfc1251410cf0cad9a833234c9890774dd9f" +checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" dependencies = [ - "quote", - "syn", + "powerfmt", ] [[package]] @@ -228,29 +237,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "env_filter" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" -dependencies = [ - "log", - "regex", -] - -[[package]] -name = "env_logger" -version = "0.11.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" -dependencies = [ - "anstream", - "anstyle", - "env_filter", - "humantime", - "log", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -456,12 +442,6 @@ version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "hyper" version = "1.4.1" @@ -587,6 +567,7 @@ dependencies = [ "clap", "libjrpc", "log", + "simple_logger", "walkdir", ] @@ -629,8 +610,6 @@ name = "libjrpc" version = "0.1.0" dependencies = [ "anyhow", - "ctor", - "env_logger", "lazy_static", "log", "regex", @@ -700,6 +679,21 @@ dependencies = [ "tempfile", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + [[package]] name = "object" version = "0.36.4" @@ -792,6 +786,12 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "proc-macro2" version = "1.0.86" @@ -1060,6 +1060,18 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "simple_logger" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c5dfa5e08767553704aa0ffd9d9794d527103c736aba9854773851fd7497eb" +dependencies = [ + "colored", + "log", + "time", + "windows-sys 0.48.0", +] + [[package]] name = "slab" version = "0.4.9" @@ -1166,6 +1178,39 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "time" +version = "0.3.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" +dependencies = [ + "deranged", + "itoa", + "libc", + "num-conv", + "num_threads", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" + +[[package]] +name = "time-macros" +version = "0.2.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tinyvec" version = "1.8.0" @@ -1478,7 +1523,7 @@ checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" dependencies = [ "windows-result", "windows-strings", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -1487,7 +1532,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -1497,7 +1542,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" dependencies = [ "windows-result", - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", ] [[package]] @@ -1506,7 +1560,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -1515,7 +1569,22 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] @@ -1524,28 +1593,46 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -1558,24 +1645,48 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" diff --git a/Cargo.toml b/Cargo.toml index 531b562..463da14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,5 +12,6 @@ anyhow = "1" clap = { version = "4", features = ["derive"] } libjrpc = { path = "libjrpc" } log = "0.4" +simple_logger = { version = "5.0.0", features = ["threads"] } [dev-dependencies] walkdir = "2" diff --git a/libjrpc/Cargo.toml b/libjrpc/Cargo.toml index 6efe167..f13714c 100644 --- a/libjrpc/Cargo.toml +++ b/libjrpc/Cargo.toml @@ -14,7 +14,3 @@ log = "0.4.22" regex = "1.10.6" reqwest = { version = "0.12.7", optional = true, features = ["blocking"] } url = { version = "2.5.2", optional = true } - -[dev-dependencies] -env_logger = "0.11.5" -ctor = "*" diff --git a/libjrpc/src/ir.rs b/libjrpc/src/ir.rs index b35f2f3..dc5ebab 100644 --- a/libjrpc/src/ir.rs +++ b/libjrpc/src/ir.rs @@ -273,7 +273,9 @@ fn build_type(stmt: &TypeStatement) -> Result { for field in &stmt.fields { let typ = BaseType::from(&field.fieldtype); - typedef.depends.insert(typ.clone()); + if stmt.name != field.fieldtype { + typedef.depends.insert(typ.clone()); + } if let Some(maptype) = &field.map { if maptype != "string" && maptype != "int" { diff --git a/libjrpc/src/process.rs b/libjrpc/src/process.rs index 4f0ec49..45644d1 100644 --- a/libjrpc/src/process.rs +++ b/libjrpc/src/process.rs @@ -35,38 +35,44 @@ impl FileProcessor { false } - fn resolve_path(input: &str, context: Option<&str>) -> String { + fn resolve_path(input: &str, context: Option<&str>) -> Result { trace!("FileProcessor::resolve_path({}, {:?})", input, context); let mut input = input.to_string(); #[cfg(feature = "http")] if cfg!(feature = "http") && (Self::is_url(Some(&input)) || Self::is_url(context)) { if Self::is_url(Some(&input)) { - input.to_string() + Ok(input.to_string()) } else { let url = Url::parse(context.unwrap()).unwrap(); if !input.ends_with(".jrpc") { input = format!("{}.jrpc", input); } - url.join(&input).unwrap().to_string() + Ok(url.join(&input).unwrap().to_string()) } } else { if !input.ends_with(".jrpc") { input = format!("{}.jrpc", input); } if let Some(context) = context { - let mut path = PathBuf::from(context); + let mut path = PathBuf::from(context).canonicalize()?; path.pop(); - path = path.join(input); - path.to_str().unwrap().to_string() + path = path.join(input).canonicalize()?; + Ok(path.to_str().unwrap().to_string()) } else { - input + // This will resolve the path! + let path = PathBuf::from(input).canonicalize()?; + Ok(path.to_str().unwrap().to_string()) } } } fn get_file_url(&mut self, url: &str) -> Result { trace!("FileProcessor::get_file_url({})", url); - let resp = reqwest::blocking::get(url)?; + let resp = reqwest::blocking::ClientBuilder::new() + .danger_accept_invalid_certs(std::env::var("ACCPT_INVALID_CERTS").is_ok()) + .build()? + .get(url) + .send()?; let body = resp.text()?; self.file_cache.insert(url.to_string(), body.clone()); Ok(body) @@ -101,7 +107,7 @@ impl FileProcessor { } fn process_file(&mut self, file: &str, root: bool) -> Result> { - let file = Self::resolve_path(file, None); + let file = Self::resolve_path(file, None)?; trace!("FileProcessor::process_file({}, {})", file, root); if self.processed_files.contains(&file) { return Ok(vec![]); @@ -115,7 +121,7 @@ impl FileProcessor { let mut result = Vec::new(); for stmt in &parsed { if let crate::parser::RootNode::Import(stmt) = stmt { - let file = Self::resolve_path(&stmt.path, Some(&file)); + let file = Self::resolve_path(&stmt.path, Some(&file))?; let s = self.process_file(&file, false)?; result.extend(s); } else { diff --git a/libjrpc/src/targets/rust.rs b/libjrpc/src/targets/rust.rs index 4b13963..ed580c2 100644 --- a/libjrpc/src/targets/rust.rs +++ b/libjrpc/src/targets/rust.rs @@ -472,7 +472,7 @@ impl Compile for RustCompiler { } f.a1(format!( - "pub {}: {}", + "pub {}: {},", Self::fix_keyword_name(&field.name), Self::type_to_rust_ext(&field.typ) )); diff --git a/libjrpc/src/targets/typescript.rs b/libjrpc/src/targets/typescript.rs index 8f2e209..205ea48 100644 --- a/libjrpc/src/targets/typescript.rs +++ b/libjrpc/src/targets/typescript.rs @@ -138,7 +138,7 @@ impl TypeScriptCompiler { ) -> Result<()> { let esm = F::ext(); file.a0(format!( - "import {{ VerificationError, apply_int, apply_float, apply_string, apply_boolean, apply_void, apply_array, apply_required, apply_optional, apply_map }} from \"./ts_base{esm}\"")); + "import {{ VerificationError, apply_int, apply_float, apply_string, apply_bool, apply_void, apply_array, apply_required, apply_optional, apply_map }} from \"./ts_base{esm}\"")); for dep in depends { match dep { BaseType::Custom(name) => { @@ -222,6 +222,13 @@ impl TypeScriptCompiler { }; } + f.a0(format!("export * as Client from \"./index_client{}\"", esm)); + f.a0(format!("export * as Server from \"./index_server{}\"", esm)); + f.a0(format!( + "export {{ Logging }} from \"./ts_service_base{}\"", + esm + )); + ctx.write_file("index.ts", &f.into_content())?; ctx.write_file("index_client.ts", &fc.into_content())?; ctx.write_file("index_server.ts", &fs.into_content())?; diff --git a/libjrpc/templates/TypeScript/ts_base.ts b/libjrpc/templates/TypeScript/ts_base.ts index cfaf70e..4e301a1 100644 --- a/libjrpc/templates/TypeScript/ts_base.ts +++ b/libjrpc/templates/TypeScript/ts_base.ts @@ -36,7 +36,7 @@ export function apply_string(data: any) { return String(data); } -export function apply_boolean(data: any) { +export function apply_bool(data: any) { return Boolean(data); } diff --git a/src/main.rs b/src/main.rs index dbf4f50..0c5b1b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,6 +32,9 @@ enum Commands { } pub fn main() -> Result<()> { + use simple_logger::SimpleLogger; + SimpleLogger::new().init()?; + let cli = Cli::parse(); if cli.verbose {