knowledge_base_crud/
lib.rs1mod entity;
2mod entity_context;
3mod entity_type;
4mod error;
5mod mutation;
6mod property;
7mod reference;
8mod resource;
9
10pub use entity::{
11 ApplyMode, ApplyStatementsOutcome, Entities, EntitiesPage, EntityFilter, EntityRelationship, EntityRelationshipsPage, RelatedEntity, RelationshipDirection, StatementBatch,
12 StatementInput, StatementResult, StatementResultStatus,
13};
14pub use entity_context::EntityContexts;
15pub use entity_type::EntityTypes;
16pub use error::Error;
17pub use property::Properties;
18pub use reference::{ReferenceDraft, ReferenceRegistrationOutcome, ReferenceRegistrationStatus, References};
19
20use knowledge_base_validation::{AdditionalValidator, Diagnostic, validate_repository_with};
21use std::fmt;
22use std::path::{Path, PathBuf};
23use std::sync::Arc;
24
25#[derive(Clone)]
26pub struct KnowledgeBase {
27 root: PathBuf,
28 additional_validators: Vec<Arc<dyn AdditionalValidator>>,
29}
30
31impl fmt::Debug for KnowledgeBase {
32 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
33 formatter
34 .debug_struct("KnowledgeBase")
35 .field("root", &self.root)
36 .field("additional_validator_count", &self.additional_validators.len())
37 .finish()
38 }
39}
40
41impl KnowledgeBase {
42 pub fn new(root: impl Into<PathBuf>) -> Self {
43 Self::with_additional_validators(root, [])
44 }
45
46 pub fn with_additional_validators(root: impl Into<PathBuf>, validators: impl IntoIterator<Item = Arc<dyn AdditionalValidator>>) -> Self {
47 Self {
48 root: root.into(),
49 additional_validators: validators.into_iter().collect(),
50 }
51 }
52
53 pub fn root(&self) -> &Path {
54 &self.root
55 }
56
57 pub fn validate(&self) -> Vec<Diagnostic> {
59 validate_repository_with(&self.root, self.additional_validators.iter().map(AsRef::as_ref))
60 }
61
62 pub(crate) fn additional_validators(&self) -> &[Arc<dyn AdditionalValidator>] {
63 &self.additional_validators
64 }
65
66 pub fn entities(&self) -> Entities<'_> {
67 Entities::new(self)
68 }
69
70 pub fn entity_types(&self) -> EntityTypes<'_> {
71 EntityTypes::new(self)
72 }
73
74 pub fn properties(&self) -> Properties<'_> {
75 Properties::new(self)
76 }
77
78 pub fn references(&self) -> References<'_> {
79 References::new(self)
80 }
81
82 pub fn entity_contexts(&self) -> EntityContexts<'_> {
83 EntityContexts::new(self)
84 }
85}