mpl_registry_api/
state.rs

1//! Registry API state
2
3use std::path::PathBuf;
4use std::sync::Arc;
5
6use crate::cache::SchemaCache;
7
8/// Shared state for the registry API
9#[derive(Clone)]
10pub struct RegistryState {
11    /// Path to the registry directory
12    pub registry_path: PathBuf,
13    /// Schema cache
14    pub cache: Arc<SchemaCache>,
15}
16
17impl RegistryState {
18    /// Create new registry state
19    pub fn new(registry_path: PathBuf) -> Self {
20        Self {
21            registry_path,
22            cache: Arc::new(SchemaCache::new()),
23        }
24    }
25
26    /// Get the path for an SType
27    pub fn stype_path(&self, namespace: &str, domain: &str, name: &str, version: u32) -> PathBuf {
28        self.registry_path
29            .join("stypes")
30            .join(namespace)
31            .join(domain)
32            .join(name)
33            .join(format!("v{}", version))
34    }
35
36    /// Get the schema path for an SType
37    pub fn schema_path(&self, namespace: &str, domain: &str, name: &str, version: u32) -> PathBuf {
38        self.stype_path(namespace, domain, name, version)
39            .join("schema.json")
40    }
41
42    /// Get the examples directory for an SType
43    pub fn examples_path(&self, namespace: &str, domain: &str, name: &str, version: u32) -> PathBuf {
44        self.stype_path(namespace, domain, name, version)
45            .join("examples")
46    }
47}