1use std::collections::HashMap;
4
5use crate::MAIN_REPOSITORY_ID;
6
7#[derive(Debug, Clone, Default)]
9pub struct RepositoryState {
10 pub namespaces: HashMap<String, String>,
12}
13
14impl RepositoryState {
15 pub fn with_default_namespaces() -> Self {
17 let mut namespaces = HashMap::new();
18 namespaces.insert(
19 "rdf".to_owned(),
20 "http://www.w3.org/1999/02/22-rdf-syntax-ns#".to_owned(),
21 );
22 namespaces.insert(
23 "rdfs".to_owned(),
24 "http://www.w3.org/2000/01/rdf-schema#".to_owned(),
25 );
26 namespaces.insert(
27 "xsd".to_owned(),
28 "http://www.w3.org/2001/XMLSchema#".to_owned(),
29 );
30 Self { namespaces }
31 }
32}
33
34#[derive(Debug, Clone)]
36pub struct RepositoryCatalog {
37 repos: HashMap<String, RepositoryState>,
38}
39
40impl RepositoryCatalog {
41 pub fn main_only() -> Self {
43 let mut repos = HashMap::new();
44 repos.insert(
45 MAIN_REPOSITORY_ID.to_owned(),
46 RepositoryState::with_default_namespaces(),
47 );
48 Self { repos }
49 }
50
51 pub fn get(&self, id: &str) -> Option<&RepositoryState> {
53 self.repos.get(id)
54 }
55
56 pub fn ids(&self) -> Vec<String> {
58 let mut ids: Vec<String> = self.repos.keys().cloned().collect();
59 ids.sort();
60 ids
61 }
62
63 pub fn contains(&self, id: &str) -> bool {
65 self.repos.contains_key(id)
66 }
67}
68
69impl Default for RepositoryCatalog {
70 fn default() -> Self {
71 Self::main_only()
72 }
73}