use std::sync::Arc;
use super::entry_pages::EntryPages;
use super::header::RegistryHeader;
pub use super::index::{RegistryIndex, RegistryStorageStats};
use crate::registry_core::declaration::FrameworkId;
use crate::registry_core::declaration::{
Admission, OwnedAdmission, OwnedRegistrationRule, RegistrationRule,
};
use crate::registry_core::identity::{NodeId, ROOT_NODE_ID, root_node_id};
#[derive(Clone, Debug)]
pub struct Registry {
pub(super) header: Arc<RegistryHeader>,
pub(super) entries: Arc<EntryPages>,
}
impl Default for Registry {
fn default() -> Self {
Self::root()
}
}
impl Registry {
pub fn root() -> Self {
Self::new(
FrameworkId::new("nichlink.default"),
"nichlink.default".to_owned(),
"root",
ROOT_NODE_ID,
RegistrationRule::ANY.into_owned(),
"<registry-root>",
Admission::ANY.into_owned(),
)
}
pub fn root_for(framework: FrameworkId) -> Self {
Self::root_for_namespace(framework, framework.0)
}
pub fn root_for_namespace(framework: FrameworkId, namespace: impl Into<String>) -> Self {
let namespace = namespace.into();
let id = root_node_id(&namespace);
Self::new(
framework,
namespace,
"root",
id,
RegistrationRule::ANY.into_owned(),
"<registry-root>",
Admission::ANY.into_owned(),
)
}
#[allow(clippy::too_many_arguments)]
pub(super) fn new(
framework: FrameworkId,
namespace: String,
path: &str,
id: NodeId,
registration_rule: OwnedRegistrationRule,
registration_rule_path: impl Into<String>,
admission: OwnedAdmission,
) -> Self {
Self {
header: Arc::new(RegistryHeader {
namespace,
framework,
path: path.to_owned(),
id,
registration_rule,
registration_rule_path: registration_rule_path.into(),
admission,
}),
entries: Arc::new(EntryPages::default()),
}
}
pub fn framework(&self) -> FrameworkId {
self.header.framework
}
}