Skip to main content

oxirs_core/assembler/
config.rs

1//! Configuration types produced by the Jena Assembler parser.
2//!
3//! These types are the output of parsing a Jena `.ttl` assembler file. They
4//! are intentionally simple (no Rc, no Arc, no RDF terms) so they can be
5//! cheaply cloned and serialised for logging or diffing.
6
7use std::path::PathBuf;
8
9// ---------------------------------------------------------------------------
10// StoreBackend
11// ---------------------------------------------------------------------------
12
13/// The storage backend for a dataset or graph resource.
14#[derive(Debug, Clone, PartialEq, Eq)]
15pub enum StoreBackend {
16    /// In-memory storage (`ja:MemoryModel` or `ja:MemoryDataset`).
17    InMemory,
18
19    /// TDB2 disk-based storage (`tdb2:DatasetTDB2`).
20    ///
21    /// The `location` is the path supplied by the `tdb2:location` literal.
22    Tdb2 { location: PathBuf },
23
24    /// An unrecognised backend type — the full class IRI is preserved so that
25    /// callers can handle proprietary or future extensions without losing
26    /// information.
27    Unknown(String),
28}
29
30// ---------------------------------------------------------------------------
31// GraphConfig
32// ---------------------------------------------------------------------------
33
34/// Configuration for one named graph (or the default graph) within a dataset.
35#[derive(Debug, Clone)]
36pub struct GraphConfig {
37    /// The IRI of the named graph, or `None` for the default graph.
38    pub graph_name: Option<String>,
39
40    /// The storage backend for this graph.
41    pub backend: StoreBackend,
42
43    /// URLs from which to load initial RDF content at startup.
44    ///
45    /// Populated from `ja:contentURL` triples on any model resource referenced
46    /// by `ja:graph` or `ja:defaultGraph`.
47    pub content_urls: Vec<String>,
48}
49
50// ---------------------------------------------------------------------------
51// DatasetConfig
52// ---------------------------------------------------------------------------
53
54/// Top-level dataset configuration parsed from one assembler resource.
55#[derive(Debug, Clone)]
56pub struct DatasetConfig {
57    /// The IRI of the assembled dataset resource (the subject of `rdf:type …Dataset`).
58    pub resource_iri: String,
59
60    /// The primary storage backend for the dataset itself.
61    pub backend: StoreBackend,
62
63    /// Ordered list of named-graph configurations.
64    pub named_graphs: Vec<GraphConfig>,
65
66    /// Configuration for the default graph, if explicitly described.
67    pub default_graph: Option<GraphConfig>,
68}
69
70// ---------------------------------------------------------------------------
71// AssemblerConfig
72// ---------------------------------------------------------------------------
73
74/// The complete result of parsing one Jena Assembler document.
75///
76/// A single assembler file may define multiple datasets; each one becomes a
77/// separate [`DatasetConfig`] entry.
78///
79/// # Example
80/// ```rust
81/// use oxirs_core::assembler::{AssemblerBuilder, AssemblerConfig};
82///
83/// let config = AssemblerBuilder::from_triples(&[]).unwrap();
84/// assert!(config.is_empty());
85/// ```
86#[derive(Debug, Clone)]
87pub struct AssemblerConfig {
88    /// All dataset resources found in the assembler document.
89    pub datasets: Vec<DatasetConfig>,
90}
91
92impl AssemblerConfig {
93    /// Returns `true` when no datasets were found.
94    pub fn is_empty(&self) -> bool {
95        self.datasets.is_empty()
96    }
97
98    /// Returns the number of datasets.
99    pub fn len(&self) -> usize {
100        self.datasets.len()
101    }
102
103    /// Returns the first dataset whose `resource_iri` matches `iri`, or `None`.
104    pub fn find_dataset(&self, iri: &str) -> Option<&DatasetConfig> {
105        self.datasets.iter().find(|d| d.resource_iri == iri)
106    }
107}