Skip to main content

aster_forge_config/
lib.rs

1//! Shared runtime configuration primitives for Aster services.
2//!
3//! This crate owns product-neutral configuration mechanics: typed configuration
4//! definitions, registry construction, storage value conversion, in-process
5//! runtime snapshots, reload diffing, and cross-process reload notifications.
6//! Product crates still own their concrete database entities, repositories,
7//! localized labels, config keys, domain-specific normalizers, and any derived
8//! runtime state that is built from configuration values.
9#![deny(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
10#![cfg_attr(
11    not(test),
12    deny(
13        clippy::unwrap_used,
14        clippy::unreachable,
15        clippy::expect_used,
16        clippy::panic,
17        clippy::unimplemented,
18        clippy::todo
19    )
20)]
21
22pub mod avatar;
23mod error;
24mod notification;
25mod registry;
26mod runtime;
27mod value;
28
29pub use error::{ConfigCoreError, Result};
30#[cfg(feature = "redis-pubsub")]
31pub use notification::RedisConfigChangeNotifier;
32pub use notification::{
33    CONFIG_SYNC_BACKEND_DISABLED, CONFIG_SYNC_BACKEND_REDIS, ConfigChangeEvent,
34    ConfigChangeNotifier, ConfigNotification, ConfigNotificationSource, ConfigReloadDecision,
35    ConfigReloadMessage, ConfigReloadObservation, ConfigReloadObserver, ConfigReloadWorkerConfig,
36    ConfigSyncConfig, ConfigSyncConnectionObservation, ConfigSyncConnectionObserver,
37    ConfigSyncConnectionState, ConfigSyncRuntime, InMemoryConfigNotifier,
38    SharedConfigChangeNotifier, build_config_sync_runtime,
39    build_config_sync_runtime_with_runtime_id, decode_config_reload_transport_payload,
40    default_config_sync_topic, handle_config_reload_notification, run_config_reload_supervisor,
41    run_config_reload_supervisor_with_observers, run_config_reload_worker,
42    run_config_reload_worker_with_observer,
43};
44pub use registry::{
45    ConfigDefinition, ConfigDependencyValidator, ConfigNormalizer, ConfigRegistry,
46    ConfigSeedRecord, ConfigValueLookup,
47};
48pub use runtime::{
49    AsyncConfigSnapshot, AsyncConfigStore, AsyncRuntimeConfig, RuntimeConfigChange,
50    RuntimeConfigRecord, StoredConfig, SyncConfigSnapshot, SyncRuntimeConfig,
51    normalize_bool_config_value, normalize_bounded_u8_config_value,
52    normalize_bounded_u64_config_value, normalize_finite_f32_config_value,
53    normalize_non_negative_u64_config_value, normalize_positive_u32_config_value,
54    normalize_positive_u64_config_value, normalize_strict_bool_config_value, parse_bool_like_value,
55    parse_bounded_u8, parse_bounded_u64, parse_finite_f32, parse_non_negative_u64,
56    parse_positive_i32, parse_positive_u32, parse_positive_u64, parse_strict_bool_value, read_bool,
57    read_bounded_u8, read_bounded_u64, read_finite_f32, read_non_negative_u64, read_positive_i32,
58    read_positive_u32, read_positive_u64, read_positive_usize,
59};
60pub use value::{
61    ConfigSource, ConfigValue, ConfigValueType, ConfigVisibility, config_value_audit_string,
62    normalize_string_enum_set_selection, parse_single_string_enum_selection,
63    parse_string_array_config_value, parse_string_enum_set_selection, present_config_value,
64    validate_storage_value,
65};
66
67/// Builds a static [`ConfigRegistry`] from a list of [`ConfigDefinition`] items.
68///
69/// Product crates normally wrap this macro in their own module that names
70/// product-specific keys and default functions. Keeping registration declarative
71/// makes it easier for services to hand the same registry to default
72/// initialization, validation, OpenAPI presentation, and admin UI metadata.
73#[macro_export]
74macro_rules! define_config_registry {
75    ($vis:vis static $name:ident = [$($definition:expr),* $(,)?];) => {
76        $vis static $name: $crate::ConfigRegistry = $crate::ConfigRegistry::new(&[
77            $($definition),*
78        ]);
79    };
80}