binder: snapshot

This commit is contained in:
nym21
2025-12-29 20:01:43 +01:00
parent e89a67b9a7
commit 5b06098368
3 changed files with 217 additions and 186 deletions
+29 -1
View File
@@ -1,5 +1,7 @@
use std::{collections::HashSet, fmt::Write as FmtWrite, fs, io, path::Path};
use serde_json::json;
use brk_grouper::{
AGE_RANGE_NAMES, AMOUNT_RANGE_NAMES, EPOCH_NAMES, GE_AMOUNT_NAMES, LT_AMOUNT_NAMES,
MAX_AGE_NAMES, MIN_AGE_NAMES, SPENDABLE_TYPE_NAMES, TERM_NAMES, YEAR_NAMES,
@@ -37,6 +39,32 @@ pub fn generate_javascript_client(
fs::write(output_path, output)?;
// Update package.json version if it exists in the same directory
if let Some(parent) = output_path.parent() {
let package_json_path = parent.join("package.json");
if package_json_path.exists() {
update_package_json_version(&package_json_path)?;
}
}
Ok(())
}
/// Update the version field in package.json to match the current VERSION.
fn update_package_json_version(package_json_path: &Path) -> io::Result<()> {
let content = fs::read_to_string(package_json_path)?;
let mut package: serde_json::Value = serde_json::from_str(&content)
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
if let Some(obj) = package.as_object_mut() {
obj.insert("version".to_string(), json!(VERSION));
}
let updated = serde_json::to_string_pretty(&package)
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
fs::write(package_json_path, updated + "\n")?;
Ok(())
}
@@ -269,7 +297,7 @@ fn generate_base_client(output: &mut String) {
*/
const _isBrowser = typeof window !== 'undefined' && 'caches' in window;
const _runIdle = (fn) => (globalThis.requestIdleCallback ?? setTimeout)(fn);
const _runIdle = (/** @type {{VoidFunction}} */ fn) => (globalThis.requestIdleCallback ?? setTimeout)(fn);
/** @type {{Promise<Cache | null>}} */
const _cachePromise = _isBrowser
+11 -8
View File
@@ -30,7 +30,7 @@ pub fn generate_python_client(
writeln!(output, "from __future__ import annotations").unwrap();
writeln!(
output,
"from typing import TypeVar, Generic, Any, Optional, List, Literal, TypedDict, Final"
"from typing import TypeVar, Generic, Any, Optional, List, Literal, TypedDict, Final, Union"
)
.unwrap();
writeln!(output, "import httpx\n").unwrap();
@@ -296,7 +296,7 @@ fn schema_to_python_type_ctx(schema: &Value, current_type: Option<&str>) -> Stri
base_type.clone()
};
} else if !types.is_empty() {
let union = types.join(" | ");
let union = format!("Union[{}]", types.join(", "));
return if has_null {
format!("Optional[{}]", union)
} else {
@@ -321,13 +321,16 @@ fn schema_to_python_type_ctx(schema: &Value, current_type: Option<&str>) -> Stri
.collect();
let filtered: Vec<_> = types.iter().filter(|t| *t != "Any").collect();
if !filtered.is_empty() {
return filtered
.iter()
.map(|s| s.as_str())
.collect::<Vec<_>>()
.join(" | ");
return format!(
"Union[{}]",
filtered
.iter()
.map(|s| s.as_str())
.collect::<Vec<_>>()
.join(", ")
);
}
return types.join(" | ");
return format!("Union[{}]", types.join(", "));
}
// Check for format hint without type (common in OpenAPI)