Fix some small bugs

This commit is contained in:
Fabian Stamm
2025-05-27 20:31:16 +02:00
parent ffacba2e96
commit c168df8365
9 changed files with 193 additions and 67 deletions

View File

@ -273,7 +273,9 @@ fn build_type(stmt: &TypeStatement) -> Result<TypeDefinition> {
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" {

View File

@ -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<String> {
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<String> {
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<Vec<RootNode>> {
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 {

View File

@ -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)
));

View File

@ -138,7 +138,7 @@ impl<F: Flavour> TypeScriptCompiler<F> {
) -> 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<F: Flavour> TypeScriptCompiler<F> {
};
}
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())?;