v0.1.0-pre.070
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
<!-- file: kb-config/CHANGELOG.md -->
|
||||
<!-- version: 3 -->
|
||||
<!-- version: 4 -->
|
||||
|
||||
# CHANGELOG — kb-config
|
||||
|
||||
## 0.1.0-pre.070
|
||||
|
||||
- enrichissement de `USAGE.md` avec plusieurs exemples couvrant les familles d’API publiques significatives.
|
||||
|
||||
## 0.1.0-pre.069
|
||||
|
||||
### Documentation
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<!-- file: kb-config/USAGE.md -->
|
||||
<!-- version: 2 -->
|
||||
<!-- version: 3 -->
|
||||
|
||||
# Utilisation de kb-config
|
||||
|
||||
@@ -29,10 +29,25 @@ let report = match kb_config::load_workspace_environment(std::path::Path::new(".
|
||||
Ok(value) => value,
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
|
||||
for path in report.loaded_files {
|
||||
println!("environment file: {}", path.display());
|
||||
}
|
||||
```
|
||||
|
||||
`EnvironmentLoadReport` indique les fichiers chargés. Les placeholders non résolus sans fallback restent visibles afin que la validation ou le consommateur puisse les signaler explicitement.
|
||||
|
||||
## Résolution explicite des placeholders
|
||||
|
||||
```rust
|
||||
let raw = r#"{"databaseUrl":"${KB_DATABASE_URL:-postgres://localhost/kb}"}"#;
|
||||
let resolved = kb_config::resolve_environment_placeholders(raw);
|
||||
|
||||
assert!(resolved.contains("databaseUrl"));
|
||||
```
|
||||
|
||||
Cette API est utile pour un outil de diagnostic qui veut afficher le JSON résolu avant parsing.
|
||||
|
||||
## Validation et parsing
|
||||
|
||||
```rust
|
||||
@@ -61,6 +76,14 @@ let pretty = match kb_config::serialize_config_json_pretty(&config) {
|
||||
Ok(value) => value,
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
|
||||
let write_result = std::fs::write("config/generated.config.json", pretty);
|
||||
if let Err(error) = write_result {
|
||||
return Err(kb_core::Error::new(
|
||||
"config_write_failed",
|
||||
format!("cannot write generated configuration: {error}"),
|
||||
));
|
||||
}
|
||||
```
|
||||
|
||||
La configuration est validée avant sérialisation.
|
||||
@@ -73,10 +96,30 @@ let schema_value = match kb_config::config_json_schema_value() {
|
||||
Ok(value) => value,
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
|
||||
let property_count = schema_value
|
||||
.get("properties")
|
||||
.and_then(serde_json::Value::as_object)
|
||||
.map_or(0, serde_json::Map::len);
|
||||
|
||||
println!("embedded schema bytes={}, properties={property_count}", schema_text.len());
|
||||
```
|
||||
|
||||
Le schéma actif est aussi disponible sous [`../config/schema.config.json`](../config/schema.config.json). Le fichier [`../config/example.config.json`](../config/example.config.json) fournit un exemple utilisateur complet.
|
||||
|
||||
## Sélection du profil actif
|
||||
|
||||
```rust
|
||||
let profile = match kb_config::active_profile(&config) {
|
||||
Ok(value) => value,
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
|
||||
println!("active profile: {}", profile.name);
|
||||
println!("http endpoints: {}", profile.solana.http_endpoints.len());
|
||||
println!("websocket endpoints: {}", profile.solana.ws_endpoints.len());
|
||||
```
|
||||
|
||||
## Types publics importants
|
||||
|
||||
- `AppConfig`, `ProfileConfig`, `AppSectionConfig` ;
|
||||
|
||||
Reference in New Issue
Block a user