global: fixes

This commit is contained in:
nym21
2026-04-27 11:19:05 +02:00
parent e543e4a5db
commit b24bfdc15c
15 changed files with 116 additions and 111 deletions

View File

@@ -110,8 +110,9 @@ fn topological_sort_schemas(schemas: &TypeSchemas) -> Vec<String> {
for (name, schema) in schemas {
let mut type_deps = BTreeSet::new();
collect_schema_refs(schema, &mut type_deps);
// Only keep deps that are in our schemas
type_deps.retain(|d| schemas.contains_key(d));
// Only keep deps that are in our schemas, and drop self-references
// (handled at emit time by quoting via current_type)
type_deps.retain(|d| schemas.contains_key(d) && d != name);
deps.insert(name.clone(), type_deps);
}

View File

@@ -1,5 +1,5 @@
use std::{
fs,
fs, io,
path::{Path, PathBuf},
};
@@ -10,52 +10,53 @@ use brk_server::{
};
use brk_types::Port;
use owo_colors::OwoColorize;
use serde::{Deserialize, Deserializer, Serialize};
use serde::{Deserialize, Serialize};
use crate::{default_brk_path, dot_brk_path, fix_user_path};
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
#[serde(default, deserialize_with = "default_on_error")]
#[serde(default)]
brkdir: Option<String>,
#[serde(default, deserialize_with = "default_on_error")]
#[serde(default)]
brkport: Option<Port>,
#[serde(default, deserialize_with = "default_on_error")]
#[serde(default)]
website: Option<Website>,
#[serde(default, deserialize_with = "default_on_error")]
#[serde(default)]
cdn: Option<bool>,
#[serde(default, deserialize_with = "default_on_error")]
#[serde(default)]
maxweight: Option<usize>,
#[serde(default, deserialize_with = "default_on_error")]
#[serde(default)]
maxweightlocal: Option<usize>,
#[serde(default, deserialize_with = "default_on_error")]
#[serde(default)]
cachesize: Option<usize>,
#[serde(default, deserialize_with = "default_on_error")]
#[serde(default)]
bitcoindir: Option<String>,
#[serde(default, deserialize_with = "default_on_error")]
#[serde(default)]
blocksdir: Option<String>,
#[serde(default, deserialize_with = "default_on_error")]
#[serde(default)]
rpcconnect: Option<String>,
#[serde(default, deserialize_with = "default_on_error")]
#[serde(default)]
rpcport: Option<u16>,
#[serde(default, deserialize_with = "default_on_error")]
#[serde(default)]
rpccookiefile: Option<String>,
#[serde(default, deserialize_with = "default_on_error")]
#[serde(default)]
rpcuser: Option<String>,
#[serde(default, deserialize_with = "default_on_error")]
#[serde(default)]
rpcpassword: Option<String>,
}
@@ -319,10 +320,18 @@ Finally, you can run the program with '-h' for help."
}
fn read(path: &Path) -> Self {
fs::read_to_string(path).map_or_else(
|_| Config::default(),
|contents| toml::from_str(&contents).unwrap_or_default(),
)
let contents = match fs::read_to_string(path) {
Ok(contents) => contents,
Err(e) if e.kind() == io::ErrorKind::NotFound => return Config::default(),
Err(e) => {
eprintln!("Cannot read {}: {e}", path.display());
std::process::exit(1);
}
};
toml::from_str(&contents).unwrap_or_else(|e| {
eprintln!("Invalid {}:\n{e}", path.display());
std::process::exit(1);
})
}
pub fn rpc(&self) -> Result<Client> {
@@ -413,14 +422,3 @@ Finally, you can run the program with '-h' for help."
self.brkport
}
}
fn default_on_error<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
D: Deserializer<'de>,
T: Deserialize<'de> + Default,
{
match T::deserialize(deserializer) {
Ok(v) => Ok(v),
Err(_) => Ok(T::default()),
}
}

View File

@@ -8897,7 +8897,7 @@ pub struct BrkClient {
impl BrkClient {
/// Client version.
pub const VERSION: &'static str = "v0.3.0-beta.5";
pub const VERSION: &'static str = "v0.3.0-beta.6";
/// Create a new client with the given base URL.
pub fn new(base_url: impl Into<String>) -> Self {

View File

@@ -70,6 +70,7 @@ struct CostBasisCohortParam {
}
#[derive(Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
struct CostBasisQuery {
#[serde(default)]
bucket: UrpdAggregation,

View File

@@ -4,6 +4,7 @@ use serde::Deserialize;
use brk_types::Txid;
#[derive(Debug, Default, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct AddrTxidsParam {
/// Txid to paginate from (return transactions before this one)
pub after_txid: Option<Txid>,

View File

@@ -11,6 +11,7 @@ pub struct TimestampParam {
/// Optional UNIX timestamp query parameter
#[derive(Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct OptionalTimestampParam {
pub timestamp: Option<Timestamp>,
}

View File

@@ -19,6 +19,7 @@ pub struct UrpdCohortParam {
/// Query parameters for URPD endpoints.
#[derive(Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct UrpdQuery {
/// Aggregation strategy. Default: raw (no aggregation). Accepts `bucket` as alias.
#[serde(default, rename = "agg", alias = "bucket")]

View File

@@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
/// Pagination parameters for paginated API endpoints
#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct Pagination {
/// Pagination index
#[serde(default, alias = "p")]

View File

@@ -4,6 +4,7 @@ use serde::Deserialize;
use crate::{Limit, SeriesName};
#[derive(Debug, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct SearchQuery {
/// Search query string
pub q: SeriesName,