use crate::path::StorePath;
use std::fmt::Write;
pub fn event_channel(path: &StorePath) -> String {
let mut name = String::from("amethystate://");
for (at, level) in path.segments().enumerate() {
if at > 0 {
name.push(':');
}
for byte in level.as_str().bytes() {
match byte {
b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' => name.push(byte as char),
other => {
let _ = write!(name, "_{other:02x}");
}
}
}
}
name
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FieldKind {
Plain,
Nested {
struct_name: &'static str,
},
Volatile,
ReactiveMap {
key_type: &'static str,
value_type: &'static str,
key_rust_type: &'static str,
value_rust_type: &'static str,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FieldExportMeta {
pub name: &'static str,
pub stored: &'static str,
pub ts_type: &'static str,
pub full_ts_type: &'static str,
pub rust_type: &'static str,
pub kind: FieldKind,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SchemaExportEntry {
pub prefix: Option<&'static str>,
pub struct_name: &'static str,
pub fields: &'static [FieldExportMeta],
}
inventory::collect!(SchemaExportEntry);
pub fn exports() -> &'static [&'static SchemaExportEntry] {
static COMPILED: std::sync::OnceLock<Vec<&'static SchemaExportEntry>> =
std::sync::OnceLock::new();
COMPILED.get_or_init(|| inventory::iter::<SchemaExportEntry>.into_iter().collect())
}